]> granicus.if.org Git - flex/commitdiff
Don't wrap ()s around {NAMEDEFS} at the end of a rule.
authorJohn Millaway <john43@users.sourceforge.net>
Sun, 28 Jul 2002 05:38:21 +0000 (05:38 +0000)
committerJohn Millaway <john43@users.sourceforge.net>
Sun, 28 Jul 2002 05:38:21 +0000 (05:38 +0000)
scan.l

diff --git a/scan.l b/scan.l
index 00d4d81f79bc3143f77c0d3a9fe94cb20502c5a7..b390050bdda369bff50f2edb03f84be544977ca7 100644 (file)
--- a/scan.l
+++ b/scan.l
@@ -480,11 +480,19 @@ LEXOPT            [aceknopr]
                                }
                        }
 
-       "{"{NAME}"}"    {
+    /* Check for :space: at the end of the rule so we don't
+     * wrap the expanded regex in '(' ')' -- breaking trailing
+     * context.
+     */
+       "{"{NAME}"}"[[:space:]]?         {
                        register Char *nmdefptr;
+            int end_is_ws, end_ch;
+            
+            end_ch = yytext[yyleng-1];
+            end_is_ws = end_ch != '}' ? 1 : 0;
 
                        strcpy( nmstr, yytext + 1 );
-                       nmstr[yyleng - 2] = '\0';  /* chop trailing brace */
+                       nmstr[yyleng - 2 - end_is_ws] = '\0';  /* chop trailing brace */
 
                        if ( (nmdefptr = ndlookup( nmstr )) == 0 )
                                format_synerr(
@@ -496,7 +504,8 @@ LEXOPT              [aceknopr]
                                int len = strlen( (char *) nmdefptr );
 
                                if ( lex_compat || nmdefptr[0] == '^' ||
-                                    (len > 0 && nmdefptr[len - 1] == '$') )
+                                    (len > 0 && nmdefptr[len - 1] == '$')
+                     || end_is_ws)
                                        { /* don't use ()'s after all */
                                        PUT_BACK_STRING((char *) nmdefptr, 0);
 
@@ -506,6 +515,8 @@ LEXOPT              [aceknopr]
 
                                else
                                        {
+                                       if (end_is_ws)
+                        unput(end_ch);
                                        unput(')');
                                        PUT_BACK_STRING((char *) nmdefptr, 0);
                                        unput('(');