From: John Millaway Date: Sun, 28 Jul 2002 05:38:21 +0000 (+0000) Subject: Don't wrap ()s around {NAMEDEFS} at the end of a rule. X-Git-Tag: flex-2-5-11~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b0f5a7a07afd4978100476ed9c2d265d87c0f6fd;p=flex Don't wrap ()s around {NAMEDEFS} at the end of a rule. --- diff --git a/scan.l b/scan.l index 00d4d81..b390050 100644 --- 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('(');