diff options
Diffstat (limited to 'mesalib/src/glsl/glcpp/glcpp-lex.l')
-rw-r--r-- | mesalib/src/glsl/glcpp/glcpp-lex.l | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/mesalib/src/glsl/glcpp/glcpp-lex.l b/mesalib/src/glsl/glcpp/glcpp-lex.l index 11b73aea8..68e44eb79 100644 --- a/mesalib/src/glsl/glcpp/glcpp-lex.l +++ b/mesalib/src/glsl/glcpp/glcpp-lex.l @@ -57,7 +57,7 @@ void glcpp_set_column (int column_no , yyscan_t yyscanner); %option stack %option never-interactive -%x DONE COMMENT UNREACHABLE +%x DONE COMMENT UNREACHABLE SKIP SPACE [[:space:]] NONSPACE [^[:space:]] @@ -74,6 +74,17 @@ OCTAL_INTEGER 0[0-7]*[uU]? HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? %% + /* Implicitly switch between SKIP and INITIAL (non-skipping); + * don't switch if some other state was explicitly set. + */ + glcpp_parser_t *parser = yyextra; + if (YY_START == 0 || YY_START == SKIP) { + if (parser->lexing_if || parser->skip_stack == NULL || parser->skip_stack->type == SKIP_NO_SKIP) { + BEGIN 0; + } else { + BEGIN SKIP; + } + } /* Single-line comments */ "//"[^\n]* { @@ -137,60 +148,44 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? yylineno = strtol(ptr, &ptr, 0) - 1; } -{HASH}ifdef/.*\n { +<SKIP,INITIAL>{ +{HASH}ifdef { yyextra->lexing_if = 1; yyextra->space_tokens = 0; return HASH_IFDEF; } -{HASH}ifndef/.*\n { +{HASH}ifndef { yyextra->lexing_if = 1; yyextra->space_tokens = 0; return HASH_IFNDEF; } -{HASH}if/[^_a-zA-Z0-9].*\n { +{HASH}if/[^_a-zA-Z0-9] { yyextra->lexing_if = 1; yyextra->space_tokens = 0; return HASH_IF; } -{HASH}elif/.*\n { +{HASH}elif { yyextra->lexing_if = 1; yyextra->space_tokens = 0; return HASH_ELIF; } -{HASH}else/.*\n { +{HASH}else { yyextra->space_tokens = 0; return HASH_ELSE; } -{HASH}endif/.*\n { +{HASH}endif { yyextra->space_tokens = 0; return HASH_ENDIF; } - - /* When skipping (due to an #if 0 or similar) consume anything - * up to a newline. We do this with less priority than any - * #if-related directive (#if, #elif, #else, #endif), but with - * more priority than any other directive or token to avoid - * any side-effects from skipped content. - * - * We use the lexing_if flag to avoid skipping any part of an - * if conditional expression. */ -[^\n]+/\n { - /* Since this rule always matches, YY_USER_ACTION gets called for it, - * wrongly incrementing yycolumn. We undo that effect here. */ - yycolumn -= yyleng; - if (yyextra->lexing_if || - yyextra->skip_stack == NULL || - yyextra->skip_stack->type == SKIP_NO_SKIP) - { - REJECT; - } } +<SKIP>[^\n] ; + {HASH}error.* { char *p; for (p = yytext; !isalpha(p[0]); p++); /* skip " # " */ @@ -293,7 +288,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? } } -\n { +<SKIP,INITIAL>\n { yyextra->lexing_if = 0; yylineno++; yycolumn = 0; |