diff options
Diffstat (limited to 'mesalib/src/glsl/glcpp/glcpp-lex.l')
-rw-r--r-- | mesalib/src/glsl/glcpp/glcpp-lex.l | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/mesalib/src/glsl/glcpp/glcpp-lex.l b/mesalib/src/glsl/glcpp/glcpp-lex.l index 188e45466..a1a8e76af 100644 --- a/mesalib/src/glsl/glcpp/glcpp-lex.l +++ b/mesalib/src/glsl/glcpp/glcpp-lex.l @@ -76,6 +76,7 @@ NEWLINE [\n] HSPACE [ \t] HASH ^{HSPACE}*#{HSPACE}* IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]* +PP_NUMBER [.]?[0-9]([._a-zA-Z0-9]|[eEpP][-+])* PUNCTUATION [][(){}.&*~!/%<>^|;,=+-] /* The OTHER class is simply a catch-all for things that the CPP @@ -137,14 +138,15 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? * 2. The skip_stack is NULL meaning that we've reached * the last #endif. * - * 3. The lexing_if bit is set. This indicates that we - * are lexing the expression following an "#if" of - * "#elif". Even inside an "#if 0" we need to lex this - * expression so the parser can correctly update the - * skip_stack state. + * 3. The lexing_directive bit is set. This indicates that we are + * lexing a pre-processor directive, (such as #if, #elif, or + * #else). For the #if and #elif directives we always need to + * parse the conditions, (even if otherwise within an #if + * 0). And for #else, we want to be able to generate an error + * if any garbage follows #else. */ if (YY_START == INITIAL || YY_START == SKIP) { - if (parser->lexing_if || + if (parser->lexing_directive || parser->skip_stack == NULL || parser->skip_stack->type == SKIP_NO_SKIP) { @@ -178,7 +180,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? /* glcpp doesn't handle #extension, #version, or #pragma directives. * Simply pass them through to the main compiler's lexer/parser. */ -{HASH}(extension|pragma)[^\n]+ { +{HASH}(extension|pragma)[^\n]* { if (parser->commented_newlines) BEGIN NEWLINE_CATCHUP; yylval->str = ralloc_strdup (yyextra, yytext); @@ -193,25 +195,25 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? <SKIP,INITIAL>{ {HASH}ifdef { - yyextra->lexing_if = 1; + yyextra->lexing_directive = 1; yyextra->space_tokens = 0; return HASH_IFDEF; } {HASH}ifndef { - yyextra->lexing_if = 1; + yyextra->lexing_directive = 1; yyextra->space_tokens = 0; return HASH_IFNDEF; } {HASH}if/[^_a-zA-Z0-9] { - yyextra->lexing_if = 1; + yyextra->lexing_directive = 1; yyextra->space_tokens = 0; return HASH_IF; } {HASH}elif/[^_a-zA-Z0-9] { - yyextra->lexing_if = 1; + yyextra->lexing_directive = 1; yyextra->space_tokens = 0; return HASH_ELIF; } @@ -329,6 +331,11 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? return IDENTIFIER; } +{PP_NUMBER} { + yylval->str = ralloc_strdup (yyextra, yytext); + return OTHER; +} + {PUNCTUATION} { return yytext[0]; } @@ -348,7 +355,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? if (parser->commented_newlines) { BEGIN NEWLINE_CATCHUP; } - yyextra->lexing_if = 0; + yyextra->lexing_directive = 0; yylineno++; yycolumn = 0; return NEWLINE; @@ -357,7 +364,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? /* Handle missing newline at EOF. */ <INITIAL><<EOF>> { BEGIN DONE; /* Don't keep matching this rule forever. */ - yyextra->lexing_if = 0; + yyextra->lexing_directive = 0; return NEWLINE; } |