From c172f266b4b611cb69bde3b46e4be350819cde73 Mon Sep 17 00:00:00 2001 From: Oleksii Taran Date: Fri, 27 Nov 2015 20:08:09 -0800 Subject: [PATCH] Fix "CODE" symbol collision on OS X (see #122) On OS X bison generates token enums as CPP macro constants (y.tab.h): #define CODE 260 while on my box it's enum yytokentype { ... CODE = 260, ... }; That #define causes symbol collision as: ../src/parse/lex.re:169:38: error: expected unqualified-id else if (opts->target == opt_t::CODE) ^ src/parse/y.tab.h:58:14: note: expanded from macro 'CODE' #define CODE 260 Renamed enum entry to TOKEN_CODE. --- re2c/bootstrap/src/parse/lex.cc | 6 +++--- re2c/bootstrap/src/parse/parser.cc | 12 ++++++------ re2c/bootstrap/src/parse/y.tab.h | 2 +- re2c/src/parse/lex.re | 4 ++-- re2c/src/parse/parser.ypp | 26 +++++++++++++------------- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/re2c/bootstrap/src/parse/lex.cc b/re2c/bootstrap/src/parse/lex.cc index f62533f2..634a68ba 100644 --- a/re2c/bootstrap/src/parse/lex.cc +++ b/re2c/bootstrap/src/parse/lex.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.15.2 on Fri Nov 27 14:24:13 2015*/ +/* Generated by re2c 0.15.2 on Sat Nov 28 10:47:09 2015*/ #line 1 "../src/parse/lex.re" #include #include @@ -1448,7 +1448,7 @@ yy236: --cur; } yylval.code = new Code (tok, tok_len (), get_fname (), tline); - return CODE; + return TOKEN_CODE; } else if (cur == eof) { @@ -1495,7 +1495,7 @@ yy241: else if (--depth == 0) { yylval.code = new Code (tok, tok_len (), get_fname (), tline); - return CODE; + return TOKEN_CODE; } goto code; } diff --git a/re2c/bootstrap/src/parse/parser.cc b/re2c/bootstrap/src/parse/parser.cc index 914f7951..6318628b 100644 --- a/re2c/bootstrap/src/parse/parser.cc +++ b/re2c/bootstrap/src/parse/parser.cc @@ -242,7 +242,7 @@ void default_rule(CondList *clist, const Code * code) enum yytokentype { CLOSE = 258, CLOSESIZE = 259, - CODE = 260, + TOKEN_CODE = 260, CONF = 261, ID = 262, FID = 263, @@ -596,11 +596,11 @@ static const yytype_uint16 yyrline[] = First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { - "$end", "error", "$undefined", "CLOSE", "CLOSESIZE", "CODE", "CONF", - "ID", "FID", "FID_END", "NOCOND", "REGEXP", "SETUP", "STAR", "'='", - "';'", "'/'", "'<'", "'>'", "':'", "','", "'|'", "'\\\\'", "'('", "')'", - "$accept", "spec", "decl", "rule", "cond", "clist", "newcond", "look", - "expr", "diff", "term", "factor", "close", "primary", 0 + "$end", "error", "$undefined", "CLOSE", "CLOSESIZE", "TOKEN_CODE", + "CONF", "ID", "FID", "FID_END", "NOCOND", "REGEXP", "SETUP", "STAR", + "'='", "';'", "'/'", "'<'", "'>'", "':'", "','", "'|'", "'\\\\'", "'('", + "')'", "$accept", "spec", "decl", "rule", "cond", "clist", "newcond", + "look", "expr", "diff", "term", "factor", "close", "primary", 0 }; #endif diff --git a/re2c/bootstrap/src/parse/y.tab.h b/re2c/bootstrap/src/parse/y.tab.h index afb75933..d484c429 100644 --- a/re2c/bootstrap/src/parse/y.tab.h +++ b/re2c/bootstrap/src/parse/y.tab.h @@ -40,7 +40,7 @@ enum yytokentype { CLOSE = 258, CLOSESIZE = 259, - CODE = 260, + TOKEN_CODE = 260, CONF = 261, ID = 262, FID = 263, diff --git a/re2c/src/parse/lex.re b/re2c/src/parse/lex.re index cdb7a404..ccc24e98 100644 --- a/re2c/src/parse/lex.re +++ b/re2c/src/parse/lex.re @@ -407,7 +407,7 @@ code: else if (--depth == 0) { yylval.code = new Code (tok, tok_len (), get_fname (), tline); - return CODE; + return TOKEN_CODE; } goto code; } @@ -448,7 +448,7 @@ code: --cur; } yylval.code = new Code (tok, tok_len (), get_fname (), tline); - return CODE; + return TOKEN_CODE; } else if (cur == eof) { diff --git a/re2c/src/parse/parser.ypp b/re2c/src/parse/parser.ypp index b2b01087..590d9343 100644 --- a/re2c/src/parse/parser.ypp +++ b/re2c/src/parse/parser.ypp @@ -159,7 +159,7 @@ void default_rule(CondList *clist, const Code * code) %token CLOSE %token CLOSESIZE -%token CODE +%token TOKEN_CODE %token CONF %token ID %token FID @@ -171,7 +171,7 @@ void default_rule(CondList *clist, const Code * code) %type CLOSE STAR SETUP close %type CLOSESIZE -%type CODE +%type TOKEN_CODE %type REGEXP rule look expr diff term factor primary %type ID FID newcond %type cond clist @@ -220,7 +220,7 @@ decl: ; rule: - expr look CODE + expr look TOKEN_CODE { if (opts->cFlag) { @@ -237,7 +237,7 @@ rule: ); spec.add (rule); } - | STAR CODE /* default rule */ + | STAR TOKEN_CODE /* default rule */ { if (opts->cFlag) in->fatal("condition or '<*>' required when using -c switch"); @@ -255,7 +255,7 @@ rule: in->fatal("code to default rule is already defined"); } } - | '<' cond '>' expr look newcond CODE + | '<' cond '>' expr look newcond TOKEN_CODE { context_rule ($2, $7->loc, $4, $5, $7, $6); } @@ -265,7 +265,7 @@ rule: Loc loc (in->get_fname (), in->get_cline ()); context_rule ($2, loc, $4, $5, NULL, $7); } - | '<' cond '>' look newcond CODE + | '<' cond '>' look newcond TOKEN_CODE { context_none($2); delete $5; @@ -276,11 +276,11 @@ rule: context_none($2); delete $6; } - | '<' cond '>' STAR CODE /* default rule for conditions */ + | '<' cond '>' STAR TOKEN_CODE /* default rule for conditions */ { default_rule($2, $5); } - | '<' STAR '>' expr look newcond CODE + | '<' STAR '>' expr look newcond TOKEN_CODE { context_check(NULL); RuleOp * rule = new RuleOp @@ -312,7 +312,7 @@ rule: specStar.push_back (rule); delete $7; } - | '<' STAR '>' look newcond CODE + | '<' STAR '>' look newcond TOKEN_CODE { context_none(NULL); delete $5; @@ -323,7 +323,7 @@ rule: context_none(NULL); delete $6; } - | '<' STAR '>' STAR CODE /* default rule for all conditions */ + | '<' STAR '>' STAR TOKEN_CODE /* default rule for all conditions */ { if (star_default) { @@ -339,7 +339,7 @@ rule: , NULL ); } - | NOCOND newcond CODE + | NOCOND newcond TOKEN_CODE { context_check(NULL); if (specNone) @@ -377,13 +377,13 @@ rule: ); delete $3; } - | SETUP STAR '>' CODE + | SETUP STAR '>' TOKEN_CODE { CondList *clist = new CondList(); clist->insert("*"); setup_rule(clist, $4); } - | SETUP cond '>' CODE + | SETUP cond '>' TOKEN_CODE { setup_rule($2, $4); } -- 2.49.0