Re: PATCH: simplify regular expressions

Andreas Schwab <[email protected]>
Newsgroups gmane.comp.sysutils.dejagnu.general
Message-ID <[email protected]>
On Dez 10 2018, Ben Elliston <[email protected]> wrote:

> diff --git a/config/gdb-comm.exp b/config/gdb-comm.exp
> index c9ef574..1e57eac 100644
> --- a/config/gdb-comm.exp
> +++ b/config/gdb-comm.exp
> @@ -86,7 +86,7 @@ proc gdb_comm_file_cmd { arg } {
>  	    verbose "\t\tKilling previous program being debugged"
>  	    exp_continue
>  	}
> -	-re "Load new symbol table from \".*\".*y or n.*$" {
> +	-re {Load new symbol table from ".*".*y or n.*$" {

Missing close brace.

> @@ -493,7 +493,7 @@ proc gdb_comm_load { dest prog args } {
>  	    remote_reboot $dest
>  	    return [list "fail" $output]
>  	}
> -	-re "(.*)Program exited with code \[0-9\]+.*$gdb_prompt $" {
> +	-re "(.*)Program exited with code [0-9]+.*$gdb_prompt $" {

You cannot remove the backslash here.

> diff --git a/lib/framework.exp b/lib/framework.exp
> index 5879ea6..a5ae572 100644
> --- a/lib/framework.exp
> +++ b/lib/framework.exp
> @@ -292,7 +292,7 @@ proc clone_output { message } {
>  	puts $sum_file $message
>      }
>  
> -    regsub "^\[ \t\]*(\[^ \t\]+).*$" $message "\\1" firstword
> +    regsub "^\[ \t\]*(\[^ \t\]+).*$" $message {\1} firstword

The re can be simplified too.

> diff --git a/lib/target.exp b/lib/target.exp
> index 2620e30..3a40995 100644
> --- a/lib/target.exp
> +++ b/lib/target.exp
> @@ -124,15 +124,15 @@ proc prune_warnings { text } {
>      regsub -all -- "\r" $text "" text
>  
>      # This is from sun4's.  Do it for all machines for now.
> -    # The "\\1" is to try to preserve a "\n" but only if necessary.
> +    # The {\1} is to try to preserve a "\n" but only if necessary.
>      if {[ishost "sparc-*-sunos*"]} {
> -	regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
> +	regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text {\1} text

Likewise.

>      }
>  
>      # See Brendan for the raison d'etre of this one.
>      # http://en.wikipedia.org/wiki/Brendan_Kehoe
>      if {[ishost "alpha*-*-*"]} {
> -	regsub -all "(^|\n)(/usr/(ucb|bin)/ld.*without exceptions was\[^\n\]+\n?)" $text "\\1" text
> +	regsub -all "(^|\n)(/usr/(ucb|bin)/ld.*without exceptions was\[^\n\]+\n?)" $text {\1} text

Likewise.

> @@ -197,72 +197,72 @@ proc prune_warnings { text } {
>      regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
>  
>      # This is from sun4's.  Do it for all machines for now.
> -    # The "\\1" is to try to preserve a "\n" but only if necessary.
> -    regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
> +    # The {\1} is to try to preserve a "\n" but only if necessary.
> +    regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text {\1} text

Likewise.

>  
>      # This happens when compiling on Alpha OSF/1 with cc -g -O.
> -    regsub -all "(^|\n)(\n*uopt: Warning: file not optimized; use -g3 if both optimization and debug wanted\n?)+" $text "\\1" text
> +    regsub -all "(^|\n)(\n*uopt: Warning: file not optimized; use -g3 if both optimization and debug wanted\n?)+" $text {\1} text

Likewise.

Many more occurences following.

Andreas.

-- 
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.