diff options
author | Carl Worth <cworth@cworth.org> | 2010-05-12 12:17:10 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2010-05-12 12:25:34 -0700 |
commit | 33cc400714f379ef13e876b4aedd0de8cb5d033d (patch) | |
tree | eb0fcb9c900079aebdab63af41d001af56e9736d /glcpp-lex.l | |
parent | df2ab5b99237ab0b6760226554b133a5ccd11579 (diff) |
Fix defines involving both literals and other defined macros.
We now store a list of tokens in our hash-table rather than a single
string. This lets us replace each macro in the value as necessary.
This code adds a link dependency on talloc which does exactly what we
want in terms of memory management for a parser.
The 3 tests added in the previous commit now pass.
Diffstat (limited to 'glcpp-lex.l')
-rw-r--r-- | glcpp-lex.l | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/glcpp-lex.l b/glcpp-lex.l index a220fef76b..f1a3560779 100644 --- a/glcpp-lex.l +++ b/glcpp-lex.l @@ -36,22 +36,40 @@ SPACE [[:space:]] NONSPACE [^[:space:]] -NOTNEWLINE [^\n] +NEWLINE [\n] HSPACE [ \t] HASH ^{HSPACE}*# IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]* -DEFVAL {NONSPACE}{NOTNEWLINE}* +TOKEN {NONSPACE}+ + %% -{HASH}define { BEGIN ST_DEFINE; return DEFINE; } +{HASH}define{HSPACE}* { + BEGIN ST_DEFINE; + return DEFINE; +} + +<ST_DEFINE>{IDENTIFIER} { + yylval.str = strdup (yytext); + return IDENTIFIER; +} + +<ST_DEFINE>{TOKEN} { + yylval.str = strdup (yytext); + return TOKEN; +} -<ST_DEFINE>{HSPACE}+ -<ST_DEFINE>{IDENTIFIER} { BEGIN ST_DEFVAL; yylval = strdup (yytext); return IDENTIFIER; } +<ST_DEFINE>\n { + BEGIN INITIAL; + return NEWLINE; +} -<ST_DEFVAL>{SPACE}+ -<ST_DEFVAL>{DEFVAL} { BEGIN INITIAL; yylval = strdup (yytext); return DEFVAL; } +<ST_DEFINE>{SPACE}+ /* Anything we don't specifically recognize is a stream of tokens */ -{NONSPACE}+ { yylval = strdup (yytext); return TOKEN; } +{NONSPACE}+ { + yylval.str = strdup (yytext); + return TOKEN; +} %% |