[Mesa-dev] [PATCH 2/2] glcpp: Fix so that trailing punctuation does not prevent macro expansion

Kenneth Graunke kenneth at whitecape.org
Sun Jan 22 23:21:05 PST 2012


On 01/21/2012 09:34 AM, Carl Worth wrote:
> The trick here is that flex always chooses the rule that matches the most
> text. So with a input text of "two:" which we want to be lexed as an
> IDENTIFIER token "two" followed by an OTHER token ":" the previous OTHER
> rule would match longer as a single token of "two:" which we don't want.
>
> We prevent this by forcing the OTHER pattern to never match a string which
> has a first character that could be an identifier (that is _, a-z, or A-Z).
> This way the ambiguity is eliminated and this case is lexed correctly.
> ---
>   src/glsl/glcpp/glcpp-lex.l |    2 +-
>   1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l
> index 8661887..20d7fc1 100644
> --- a/src/glsl/glcpp/glcpp-lex.l
> +++ b/src/glsl/glcpp/glcpp-lex.l
> @@ -70,7 +70,7 @@ HSPACE		[ \t]
>   HASH		^{HSPACE}*#{HSPACE}*
>   IDENTIFIER	[_a-zA-Z][_a-zA-Z0-9]*
>   PUNCTUATION	[][(){}.&*~!/%<>^|;,=+-]
> -OTHER		[^][(){}.&*~!/%<>^|;,=#[:space:]+-]+
> +OTHER		[^][_a-zA-Z(){}.&*~!/%<>^|;,=#[:space:]+-][^][(){}.&*~!/%<>^|;,=#[:space:]+-]*
>
>   DIGITS			[0-9][0-9]*
>   DECIMAL_INTEGER		[1-9][0-9]*[uU]?

Looks correct to me.  For both patches:
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>


More information about the mesa-dev mailing list