3 * Copyright © 2010 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
29 #include "glcpp-parse.h"
31 #define YY_USER_ACTION \
34 yylloc->first_column = yycolumn + 1; \
35 yylloc->first_line = yylineno; \
40 %option bison-bridge bison-locations reentrant noyywrap
41 %option extra-type="glcpp_parser_t *"
42 %option prefix="glcpp_"
51 HASH ^{HSPACE}*#{HSPACE}*
52 IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
53 PUNCTUATION [][(){}.&*~!/%<>^|;,=+-]
54 OTHER [^][(){}.&*~!/%<>^|;,=#[:space:]+-]+
56 DECIMAL_INTEGER [1-9][0-9]*[uU]?
57 OCTAL_INTEGER 0[0-7]*[uU]?
58 HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
62 /* Single-line comments */
69 /* Multi-line comments */
70 "/*" { yy_push_state(COMMENT, yyscanner); }
72 <COMMENT>[^*\n]*\n { yylineno++; yycolumn = 0; }
74 <COMMENT>"*"+[^*/\n]*\n { yylineno++; yycolumn = 0; }
76 yy_pop_state(yyscanner);
77 if (yyextra->space_tokens)
81 /* glcpp doesn't handle #extension, #version, or #pragma directives.
82 * Simply pass them through to the main compiler's lexer/parser. */
83 {HASH}(extension|version|pragma)[^\n]+ {
84 yylval->str = xtalloc_strdup (yyextra, yytext);
91 yyextra->space_tokens = 0;
96 yyextra->space_tokens = 0;
100 {HASH}if{HSPACE}/.*\n {
101 yyextra->lexing_if = 1;
102 yyextra->space_tokens = 0;
107 yyextra->lexing_if = 1;
108 yyextra->space_tokens = 0;
113 yyextra->space_tokens = 0;
118 yyextra->space_tokens = 0;
122 /* When skipping (due to an #if 0 or similar) consume anything
123 * up to a newline. We do this less priroty than any
124 * #if-related directive (#if, #elif, #else, #endif), but with
125 * more priority than any other directive or token to avoid
126 * any side-effects from skipped content.
128 * We use the lexing_if flag to avoid skipping any part of an
129 * if conditional expression. */
131 /* Since this rule always matches, YY_USER_ACTION gets called for it,
132 * wrongly incrementing yycolumn. We undo that effect here. */
134 if (yyextra->lexing_if ||
135 yyextra->skip_stack == NULL ||
136 yyextra->skip_stack->type == SKIP_NO_SKIP)
142 {HASH}define{HSPACE}+/{IDENTIFIER}"(" {
143 yyextra->space_tokens = 0;
144 return HASH_DEFINE_FUNC;
148 yyextra->space_tokens = 0;
149 return HASH_DEFINE_OBJ;
153 yyextra->space_tokens = 0;
158 yyextra->space_tokens = 0;
163 yylval->str = xtalloc_strdup (yyextra, yytext);
164 return INTEGER_STRING;
168 yylval->str = xtalloc_strdup (yyextra, yytext);
169 return INTEGER_STRING;
172 {HEXADECIMAL_INTEGER} {
173 yylval->str = xtalloc_strdup (yyextra, yytext);
174 return INTEGER_STRING;
186 return LESS_OR_EQUAL;
190 return GREATER_OR_EQUAL;
218 yylval->str = xtalloc_strdup (yyextra, yytext);
227 yylval->str = xtalloc_strdup (yyextra, yytext);
232 if (yyextra->space_tokens) {
238 yyextra->lexing_if = 0;
244 /* Handle missing newline at EOF. */
246 BEGIN DONE; /* Don't keep matching this rule forever. */
247 yyextra->lexing_if = 0;
254 glcpp_lex_set_source_string(glcpp_parser_t *parser, const char *shader)
256 yy_scan_string(shader, parser->scanner);