mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-30 23:00:11 +01:00
Simplify lexer significantly (remove all stateful lexing).
We are able to remove all state by simply passing NEWLINE through as a token unconditionally (as opposed to only passing newline when on a driective line as we did previously).
This commit is contained in:
parent
a68e668b17
commit
012295f94c
2 changed files with 15 additions and 32 deletions
41
glcpp-lex.l
41
glcpp-lex.l
|
|
@ -32,9 +32,6 @@
|
|||
%option reentrant noyywrap
|
||||
%option extra-type="glcpp_parser_t *"
|
||||
|
||||
%x ST_DEFINE
|
||||
%x ST_UNDEF
|
||||
|
||||
SPACE [[:space:]]
|
||||
NONSPACE [^[:space:]]
|
||||
NEWLINE [\n]
|
||||
|
|
@ -46,48 +43,28 @@ TOKEN {NONSPACE}+
|
|||
%%
|
||||
|
||||
{HASH}define{HSPACE}* {
|
||||
BEGIN ST_DEFINE;
|
||||
return DEFINE;
|
||||
}
|
||||
|
||||
<ST_DEFINE>{IDENTIFIER} {
|
||||
yylval.str = xtalloc_strdup (yyextra, yytext);
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
<ST_DEFINE>{TOKEN} {
|
||||
yylval.str = xtalloc_strdup (yyextra, yytext);
|
||||
return TOKEN;
|
||||
}
|
||||
|
||||
<ST_DEFINE>\n {
|
||||
BEGIN INITIAL;
|
||||
return NEWLINE;
|
||||
}
|
||||
|
||||
<ST_DEFINE>{SPACE}+
|
||||
|
||||
{HASH}undef{HSPACE}* {
|
||||
BEGIN ST_UNDEF;
|
||||
return UNDEF;
|
||||
}
|
||||
|
||||
<ST_UNDEF>{IDENTIFIER} {
|
||||
|
||||
{IDENTIFIER} {
|
||||
yylval.str = xtalloc_strdup (yyextra, yytext);
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
<ST_UNDEF>\n {
|
||||
BEGIN INITIAL;
|
||||
return NEWLINE;
|
||||
}
|
||||
|
||||
<ST_UNDEF>{SPACE}+
|
||||
|
||||
/* Anything we don't specifically recognize is a stream of tokens */
|
||||
{NONSPACE}+ {
|
||||
{TOKEN} {
|
||||
yylval.str = xtalloc_strdup (yyextra, yytext);
|
||||
return TOKEN;
|
||||
}
|
||||
|
||||
\n {
|
||||
return NEWLINE;
|
||||
}
|
||||
|
||||
{SPACE}+
|
||||
|
||||
%%
|
||||
|
|
|
|||
|
|
@ -74,11 +74,17 @@ content:
|
|||
talloc_free ($1);
|
||||
}
|
||||
| directive_with_newline
|
||||
| NEWLINE {
|
||||
printf ("\n");
|
||||
}
|
||||
| content token {
|
||||
_print_resolved_token (parser, $2);
|
||||
talloc_free ($2);
|
||||
}
|
||||
| content directive_with_newline
|
||||
| content NEWLINE {
|
||||
printf ("\n");
|
||||
}
|
||||
;
|
||||
|
||||
directive_with_newline:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue