summaryrefslogtreecommitdiff
path: root/glcpp-lex.l
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2010-05-12 13:11:50 -0700
committerCarl Worth <cworth@cworth.org>2010-05-12 13:11:50 -0700
commitcd27e6413a683d3ba1763ec68edfb1ff13193fc3 (patch)
tree0d331b3446bc56f18f4003e90e8657fcc8b73dbe /glcpp-lex.l
parent7bdd1f36d9f238e6af4846d46b9dd30fffc772a5 (diff)
Add support for the #undef macro.
This isn't ideal for two reasons: 1. There's a bunch of stateful redundancy in the lexer that should be cleaned up. 2. The hash table does not provide a mechanism to delete an entry, so we waste memory to add a new NULL entry in front of the existing entry with the same key. But this does at least work, (it passes the recently added undef test case).
Diffstat (limited to 'glcpp-lex.l')
-rw-r--r--glcpp-lex.l19
1 files changed, 18 insertions, 1 deletions
diff --git a/glcpp-lex.l b/glcpp-lex.l
index ec91538a73..9ec4deb718 100644
--- a/glcpp-lex.l
+++ b/glcpp-lex.l
@@ -33,7 +33,7 @@
%option extra-type="glcpp_parser_t *"
%x ST_DEFINE
-%x ST_DEFVAL
+%x ST_UNDEF
SPACE [[:space:]]
NONSPACE [^[:space:]]
@@ -67,6 +67,23 @@ TOKEN {NONSPACE}+
<ST_DEFINE>{SPACE}+
+{HASH}undef{HSPACE}* {
+ BEGIN ST_UNDEF;
+ return UNDEF;
+}
+
+<ST_UNDEF>{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}+ {
yylval.str = xtalloc_strdup (yyextra, yytext);