]> git.draconx.ca Git - cdecl99.git/blobdiff - src/scan.l
libcdecl: Simplify Bison error message reporting.
[cdecl99.git] / src / scan.l
index 7e3e365af90f99102b3fc11adf198ed09e9f423d..767ba2263aca0eea2fe0888ff0c2e4dd4207e767 100644 (file)
@@ -132,29 +132,23 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+
 %}
 
 "..."|[][;*(),] {
+       unsigned char *match;
        static const unsigned char tab[2][8] = {
                "*[](),.;",
                {
-                       T_ASTERISK  & 0xff,
-                       T_LBRACKET  & 0xff,
-                       T_RBRACKET  & 0xff,
-                       T_LPAREN    & 0xff,
-                       T_RPAREN    & 0xff,
-                       T_COMMA     & 0xff,
-                       T_ELLIPSIS  & 0xff,
-                       T_SEMICOLON & 0xff
+                       PACK_TOKEN(T_ASTERISK),
+                       PACK_TOKEN(T_LBRACKET),
+                       PACK_TOKEN(T_RBRACKET),
+                       PACK_TOKEN(T_LPAREN),
+                       PACK_TOKEN(T_RPAREN),
+                       PACK_TOKEN(T_COMMA),
+                       PACK_TOKEN(T_ELLIPSIS),
+                       PACK_TOKEN(T_SEMICOLON)
                }
        };
 
-       unsigned char *match;
-       int x;
-
        match = memchr(&tab, yytext[0], sizeof tab[0]);
-       x = match[sizeof tab[0]];
-
-       if (T_VOID >= 256)
-               x += 256;
-       return x;
+       return UNPACK_TOKEN(match[sizeof tab[0]]);
 }
 
 {INTEGER} {
@@ -175,8 +169,11 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+
 }
 
 {IDENT} {
-       int ret = cdecl__to_keyword(yytext, yyleng, yyextra);
-       if (ret == T_IDENT) {
+       unsigned x = cdecl__to_keyword(yytext, yyleng, yyextra);
+       int tok;
+
+       yylval->spectype = UNPACK_SPEC(x & 0xff);
+       if ((tok = (x >> 8)) == PACK_TOKEN(T_IDENT)) {
                /*
                 * Our IDENT pattern includes hyphens so we can match
                 * "variable-length" as a keyword.  In all other cases a
@@ -195,7 +192,7 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+
 #endif
                dup_token();
        }
-       return ret;
+       return UNPACK_TOKEN(tok);
 }
 
 [[:space:]]+