summaryrefslogtreecommitdiff
path: root/glcpp-lex.l
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2010-05-10 16:16:06 -0700
committerCarl Worth <cworth@cworth.org>2010-05-10 16:16:06 -0700
commit0b27b5f05191f07ed31e65ff07e5233672f3c33a (patch)
tree84c63c12942e748378d73ef734021f788f4cd569 /glcpp-lex.l
parent725c17a9266c1141508da623c8781412853b70e4 (diff)
Implment #define
By using the recently-imported hash_table implementation.
Diffstat (limited to 'glcpp-lex.l')
-rw-r--r--glcpp-lex.l23
1 files changed, 19 insertions, 4 deletions
diff --git a/glcpp-lex.l b/glcpp-lex.l
index 747e24056f..a220fef76b 100644
--- a/glcpp-lex.l
+++ b/glcpp-lex.l
@@ -31,12 +31,27 @@
%option reentrant noyywrap
+%x ST_DEFINE
+%x ST_DEFVAL
+
+SPACE [[:space:]]
+NONSPACE [^[:space:]]
+NOTNEWLINE [^\n]
+HSPACE [ \t]
+HASH ^{HSPACE}*#
+IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
+DEFVAL {NONSPACE}{NOTNEWLINE}*
%%
- /* Silently eat all whitespace. */
-[[:space:]]+
+{HASH}define { BEGIN ST_DEFINE; return DEFINE; }
+
+<ST_DEFINE>{HSPACE}+
+<ST_DEFINE>{IDENTIFIER} { BEGIN ST_DEFVAL; yylval = strdup (yytext); return IDENTIFIER; }
+
+<ST_DEFVAL>{SPACE}+
+<ST_DEFVAL>{DEFVAL} { BEGIN INITIAL; yylval = strdup (yytext); return DEFVAL; }
- /* Any non-whitespace is a token. */
-[^[:space:]]+ { return TOKEN; }
+ /* Anything we don't specifically recognize is a stream of tokens */
+{NONSPACE}+ { yylval = strdup (yytext); return TOKEN; }
%%