]> granicus.if.org Git - re2c/commitdiff
libre2c: added prefix 'TOKEN_' to all parser tokens to avoid name collisions.
authorUlya Trofimovich <skvadrik@gmail.com>
Thu, 29 Aug 2019 21:27:01 +0000 (22:27 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Thu, 29 Aug 2019 21:27:01 +0000 (22:27 +0100)
Apparently some versions of bison generate token definitions as macros, not
as enum members. If a bison-generated header is included into another file
that contains identifiers identical to the names of parser tokens, all such
identifiers are macro-substituted to a numeric constant. Adding a prefix to
token names reduces the chances of name collision.

This fixes bug #261: "lib/parse.h:49:15: 错误:expected unqualified-id before
numeric constant" reported by qidizi.

bootstrap/lib/lex.cc
bootstrap/lib/parse.cc
bootstrap/lib/parse.h
lib/lex.re
lib/parse.ypp

index f6778930e6ba5c8487eaf1ee5fa2282a27c32f11..f8a7e995841dfa75b27d6fd1e0538fb7435a9e20 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 1.1.1 on Sat Jul 13 19:06:36 2019 */
+/* Generated by re2c 1.2.1 on Thu Aug 29 22:25:45 2019 */
 #line 1 "../lib/lex.re"
 #include <stdio.h>
 
@@ -109,7 +109,7 @@ yy5:
         std::vector<ASTChar> *str = new std::vector<ASTChar>;
         str->push_back(c);
         yylval.regexp = ast_str(NOWHERE, str, false);
-        return REGEXP;
+        return TOKEN_REGEXP;
     }
 #line 115 "lib/lex.cc"
 yy6:
@@ -117,7 +117,7 @@ yy6:
 #line 46 "../lib/lex.re"
        {
         error("anchors are not supported");
-        return ERROR;
+        return TOKEN_ERROR;
     }
 #line 123 "lib/lex.cc"
 yy8:
@@ -130,7 +130,7 @@ yy10:
 #line 72 "../lib/lex.re"
        {
         yylval.regexp = ast_dot(NOWHERE);
-        return REGEXP;
+        return TOKEN_REGEXP;
     }
 #line 136 "lib/lex.cc"
 yy12:
@@ -178,7 +178,7 @@ yy21:
        {
         if (!s_to_u32_unsafe(x, cur - 1, yylval.bounds.min)) goto err_cnt;
         yylval.bounds.max = yylval.bounds.min;
-        return COUNT;
+        return TOKEN_COUNT;
     }
 #line 184 "lib/lex.cc"
 yy23:
@@ -194,7 +194,7 @@ yy25:
        {
         if (!s_to_u32_unsafe(x, cur - 2, yylval.bounds.min)) goto err_cnt;
         yylval.bounds.max = AST::MANY;
-        return COUNT;
+        return TOKEN_COUNT;
     }
 #line 200 "lib/lex.cc"
 yy27:
@@ -205,7 +205,7 @@ yy27:
        {
         if (!s_to_u32_unsafe(x, y - 1, yylval.bounds.min)
             || !s_to_u32_unsafe(y, cur - 1, yylval.bounds.max)) goto err_cnt;
-        return COUNT;
+        return TOKEN_COUNT;
     }
 #line 211 "lib/lex.cc"
 }
@@ -257,7 +257,7 @@ yy39:
         std::vector<ASTRange> *p = new std::vector<ASTRange>;
         p->swap(cls);
         yylval.regexp = ast_cls(NOWHERE, p, neg);
-        return REGEXP;
+        return TOKEN_REGEXP;
     }
 #line 263 "lib/lex.cc"
 }
@@ -266,11 +266,11 @@ yy39:
 
 err:
     error("syntax error: %s\n", cur);
-    return ERROR;
+    return TOKEN_ERROR;
 
 err_cnt:
     error("repetition count overflow");
-    return ERROR;
+    return TOKEN_ERROR;
 }
 
 int32_t lex_cls_chr(const char *&cur, uint32_t &c)
index 413de35d0c37d63a91c0435037d84e23f5917a99..e8738534c3db0019068dcebb973daa88b97847f2 100644 (file)
@@ -128,9 +128,9 @@ extern int yydebug;
 # define YYTOKENTYPE
   enum yytokentype
   {
-    COUNT = 258,
-    ERROR = 259,
-    REGEXP = 260
+    TOKEN_COUNT = 258,
+    TOKEN_ERROR = 259,
+    TOKEN_REGEXP = 260
   };
 #endif
 
@@ -469,9 +469,9 @@ static const yytype_uint8 yyrline[] =
    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
 static const char *const yytname[] =
 {
-  "$end", "error", "$undefined", "COUNT", "ERROR", "REGEXP", "'|'", "'*'",
-  "'+'", "'?'", "'('", "')'", "$accept", "regexp", "expr", "term",
-  "factor", "primary", YY_NULLPTR
+  "$end", "error", "$undefined", "TOKEN_COUNT", "TOKEN_ERROR",
+  "TOKEN_REGEXP", "'|'", "'*'", "'+'", "'?'", "'('", "')'", "$accept",
+  "regexp", "expr", "term", "factor", "primary", YY_NULLPTR
 };
 #endif
 
index 9be559c7275b4f26165aaa08648faa82fafe6634..10864f11144073f630f3faf89e1160864d255007 100644 (file)
@@ -45,9 +45,9 @@ extern int yydebug;
 # define YYTOKENTYPE
   enum yytokentype
   {
-    COUNT = 258,
-    ERROR = 259,
-    REGEXP = 260
+    TOKEN_COUNT = 258,
+    TOKEN_ERROR = 259,
+    TOKEN_REGEXP = 260
   };
 #endif
 
index 754d4c90de4adb6d1c090ccbf29a34fa43362283..1dc4c701b5fc1f0a9fcdf610046b0c2784b0ad35 100644 (file)
@@ -45,7 +45,7 @@ int lex(const char *&cur)
 
     [$^] {
         error("anchors are not supported");
-        return ERROR;
+        return TOKEN_ERROR;
     }
 
     "[^" { neg = true; goto cls; }
@@ -54,24 +54,24 @@ int lex(const char *&cur)
     "{" @x num "}" {
         if (!s_to_u32_unsafe(x, cur - 1, yylval.bounds.min)) goto err_cnt;
         yylval.bounds.max = yylval.bounds.min;
-        return COUNT;
+        return TOKEN_COUNT;
     }
 
     "{" @x num "," @y num "}" {
         if (!s_to_u32_unsafe(x, y - 1, yylval.bounds.min)
             || !s_to_u32_unsafe(y, cur - 1, yylval.bounds.max)) goto err_cnt;
-        return COUNT;
+        return TOKEN_COUNT;
     }
 
     "{" @x num ",}" {
         if (!s_to_u32_unsafe(x, cur - 2, yylval.bounds.min)) goto err_cnt;
         yylval.bounds.max = AST::MANY;
-        return COUNT;
+        return TOKEN_COUNT;
     }
 
     "." {
         yylval.regexp = ast_dot(NOWHERE);
-        return REGEXP;
+        return TOKEN_REGEXP;
     }
 
     [^] \ nil {
@@ -79,7 +79,7 @@ int lex(const char *&cur)
         std::vector<ASTChar> *str = new std::vector<ASTChar>;
         str->push_back(c);
         yylval.regexp = ast_str(NOWHERE, str, false);
-        return REGEXP;
+        return TOKEN_REGEXP;
     }
 */
 
@@ -98,17 +98,17 @@ add:
         std::vector<ASTRange> *p = new std::vector<ASTRange>;
         p->swap(cls);
         yylval.regexp = ast_cls(NOWHERE, p, neg);
-        return REGEXP;
+        return TOKEN_REGEXP;
     }
 */
 
 err:
     error("syntax error: %s\n", cur);
-    return ERROR;
+    return TOKEN_ERROR;
 
 err_cnt:
     error("repetition count overflow");
-    return ERROR;
+    return TOKEN_ERROR;
 }
 
 int32_t lex_cls_chr(const char *&cur, uint32_t &c)
index 1288e38f38961470531b61745b3484c2c3e7b382..e10209db31b9dde16c904179b19faf654d6733ed 100644 (file)
@@ -39,12 +39,12 @@ void yyerror(const char *pattern, const char*) RE2C_ATTR((noreturn));
     re2c::ASTBounds bounds;
 };
 
-%token COUNT
-%token ERROR
-%token REGEXP
+%token TOKEN_COUNT
+%token TOKEN_ERROR
+%token TOKEN_REGEXP
 
-%type <regexp> REGEXP regexp expr term factor primary
-%type <bounds> COUNT
+%type <regexp> TOKEN_REGEXP regexp expr term factor primary
+%type <bounds> TOKEN_COUNT
 
 %%
 
@@ -62,14 +62,14 @@ term
 
 factor
 : primary
-| primary '*'   { $$ = ast_iter($1, 0, AST::MANY); }
-| primary '+'   { $$ = ast_iter($1, 1, AST::MANY); }
-| primary '?'   { $$ = ast_iter($1, 0, 1); }
-| primary COUNT { $$ = ast_iter($1, $2.min, $2.max); }
+| primary '*'         { $$ = ast_iter($1, 0, AST::MANY); }
+| primary '+'         { $$ = ast_iter($1, 1, AST::MANY); }
+| primary '?'         { $$ = ast_iter($1, 0, 1); }
+| primary TOKEN_COUNT { $$ = ast_iter($1, $2.min, $2.max); }
 ;
 
 primary
-: REGEXP
+: TOKEN_REGEXP
 | '(' ')'      { $$ = ast_cap(ast_nil(NOWHERE)); }
 | '(' expr ')' { $$ = ast_cap($2); }
 ;