static RegExp *spec, *specNone = NULL;
static RuleOpList specStar;
static Scanner *in = NULL;
-static StringMap ruleSetupMap;
+static Scanner::ParseMode parseMode;
+static SetupMap ruleSetupMap;
/* Bison version 1.875 emits a definition that is not working
* with several g++ version. Hence we disable it here.
assert(clist);
assert(code);
context_check(clist);
- if (bFirstPass) {
+ if (bFirstPass)
+ {
for(CondList::const_iterator it = clist->begin(); it != clist->end(); ++it)
{
if (ruleSetupMap.find(*it) != ruleSetupMap.end())
{
- in->fatalf("code to setup rule '%s' is already defined", it->c_str());
+ in->fatalf_at(code->line, "code to setup rule '%s' is already defined", it->c_str());
}
- ruleSetupMap[*it] = code->text.to_string();
+ ruleSetupMap[*it] = std::make_pair(code->line, code->text.to_string());
}
}
delete clist;
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
-#line 128 "parser.y"
+#line 130 "parser.y"
{
re2c::Symbol *symbol;
re2c::RegExp *regexp;
re2c::CondList *clist;
}
/* Line 187 of yacc.c. */
-#line 262 "parser.cc"
+#line 264 "parser.cc"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
/* Line 216 of yacc.c. */
-#line 275 "parser.cc"
+#line 277 "parser.cc"
#ifdef short
# undef short
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
- 0, 157, 157, 161, 162, 166, 174, 182, 186, 190,
- 194, 200, 208, 217, 221, 226, 231, 237, 245, 253,
- 258, 264, 276, 288, 294, 302, 305, 312, 317, 326,
- 329, 337, 340, 347, 351, 358, 362, 373, 377, 384,
- 388, 403, 410, 414, 418, 422, 429, 437, 441, 445
+ 0, 159, 159, 163, 170, 174, 182, 190, 194, 198,
+ 202, 208, 216, 225, 229, 234, 239, 245, 253, 261,
+ 266, 272, 284, 296, 302, 310, 313, 320, 325, 334,
+ 337, 345, 348, 355, 359, 366, 370, 381, 385, 392,
+ 396, 411, 418, 422, 426, 430, 437, 445, 449, 453
};
#endif
switch (yyn)
{
case 2:
-#line 157 "parser.y"
+#line 159 "parser.y"
{
accept = 0;
spec = NULL;
}
break;
+ case 3:
+#line 164 "parser.y"
+ {
+ if (parseMode == Scanner::Reuse)
+ {
+ in->fatal("Rules not allowed in 'repeat:re2c' block");
+ }
+ }
+ break;
+
case 5:
-#line 167 "parser.y"
+#line 175 "parser.y"
{
if ((yyvsp[(1) - (4)].symbol)->re)
{
break;
case 6:
-#line 175 "parser.y"
+#line 183 "parser.y"
{
if ((yyvsp[(1) - (2)].symbol)->re)
{
break;
case 7:
-#line 183 "parser.y"
+#line 191 "parser.y"
{
in->fatal("trailing contexts are not allowed in named definitions");
}
break;
case 8:
-#line 187 "parser.y"
+#line 195 "parser.y"
{
in->fatal("trailing contexts are not allowed in named definitions");
}
break;
case 9:
-#line 191 "parser.y"
+#line 199 "parser.y"
{
in->fatal("trailing contexts are not allowed in named definitions");
}
break;
case 10:
-#line 195 "parser.y"
+#line 203 "parser.y"
{
in->config(*(yyvsp[(1) - (4)].str), *(yyvsp[(3) - (4)].str));
delete (yyvsp[(1) - (4)].str);
break;
case 11:
-#line 201 "parser.y"
+#line 209 "parser.y"
{
in->config(*(yyvsp[(1) - (4)].str), (yyvsp[(3) - (4)].number));
delete (yyvsp[(1) - (4)].str);
break;
case 12:
-#line 209 "parser.y"
+#line 217 "parser.y"
{
if (cFlag)
{
break;
case 13:
-#line 218 "parser.y"
+#line 226 "parser.y"
{
context_rule((yyvsp[(2) - (7)].clist), (yyvsp[(4) - (7)].regexp), (yyvsp[(5) - (7)].regexp), (yyvsp[(6) - (7)].str), (yyvsp[(7) - (7)].token));
}
break;
case 14:
-#line 222 "parser.y"
+#line 230 "parser.y"
{
assert((yyvsp[(7) - (7)].str));
context_rule((yyvsp[(2) - (7)].clist), (yyvsp[(4) - (7)].regexp), (yyvsp[(5) - (7)].regexp), (yyvsp[(7) - (7)].str), NULL);
break;
case 15:
-#line 227 "parser.y"
+#line 235 "parser.y"
{
context_none((yyvsp[(2) - (6)].clist));
delete (yyvsp[(5) - (6)].str);
break;
case 16:
-#line 232 "parser.y"
+#line 240 "parser.y"
{
assert((yyvsp[(6) - (6)].str));
context_none((yyvsp[(2) - (6)].clist));
break;
case 17:
-#line 238 "parser.y"
+#line 246 "parser.y"
{
context_check(NULL);
Token *token = new Token((yyvsp[(7) - (7)].token), (yyvsp[(7) - (7)].token)->line, (yyvsp[(6) - (7)].str));
break;
case 18:
-#line 246 "parser.y"
+#line 254 "parser.y"
{
assert((yyvsp[(7) - (7)].str));
context_check(NULL);
break;
case 19:
-#line 254 "parser.y"
+#line 262 "parser.y"
{
context_none(NULL);
delete (yyvsp[(5) - (6)].str);
break;
case 20:
-#line 259 "parser.y"
+#line 267 "parser.y"
{
assert((yyvsp[(6) - (6)].str));
context_none(NULL);
break;
case 21:
-#line 265 "parser.y"
+#line 273 "parser.y"
{
context_check(NULL);
if (specNone)
break;
case 22:
-#line 277 "parser.y"
+#line 285 "parser.y"
{
assert((yyvsp[(3) - (3)].str));
context_check(NULL);
break;
case 23:
-#line 289 "parser.y"
+#line 297 "parser.y"
{
CondList *clist = new CondList();
clist->insert("*");
break;
case 24:
-#line 295 "parser.y"
+#line 303 "parser.y"
{
setup_rule((yyvsp[(2) - (4)].clist), (yyvsp[(4) - (4)].token));
}
break;
case 25:
-#line 302 "parser.y"
+#line 310 "parser.y"
{
in->fatal("unnamed condition not supported");
}
break;
case 26:
-#line 306 "parser.y"
+#line 314 "parser.y"
{
(yyval.clist) = (yyvsp[(1) - (1)].clist);
}
break;
case 27:
-#line 313 "parser.y"
+#line 321 "parser.y"
{
(yyval.clist) = new CondList();
(yyval.clist)->insert((yyvsp[(1) - (1)].symbol)->GetName().to_string());
break;
case 28:
-#line 318 "parser.y"
+#line 326 "parser.y"
{
(yyvsp[(1) - (3)].clist)->insert((yyvsp[(3) - (3)].symbol)->GetName().to_string());
(yyval.clist) = (yyvsp[(1) - (3)].clist);
break;
case 29:
-#line 326 "parser.y"
+#line 334 "parser.y"
{
(yyval.str) = NULL;
}
break;
case 30:
-#line 330 "parser.y"
+#line 338 "parser.y"
{
(yyval.str) = new Str((yyvsp[(3) - (3)].symbol)->GetName().to_string().c_str());
}
break;
case 31:
-#line 337 "parser.y"
+#line 345 "parser.y"
{
(yyval.regexp) = new NullOp;
}
break;
case 32:
-#line 341 "parser.y"
+#line 349 "parser.y"
{
(yyval.regexp) = (yyvsp[(2) - (2)].regexp);
}
break;
case 33:
-#line 348 "parser.y"
+#line 356 "parser.y"
{
(yyval.regexp) = (yyvsp[(1) - (1)].regexp);
}
break;
case 34:
-#line 352 "parser.y"
+#line 360 "parser.y"
{
(yyval.regexp) = mkAlt((yyvsp[(1) - (3)].regexp), (yyvsp[(3) - (3)].regexp));
}
break;
case 35:
-#line 359 "parser.y"
+#line 367 "parser.y"
{
(yyval.regexp) = (yyvsp[(1) - (1)].regexp);
}
break;
case 36:
-#line 363 "parser.y"
+#line 371 "parser.y"
{
(yyval.regexp) = mkDiff((yyvsp[(1) - (3)].regexp), (yyvsp[(3) - (3)].regexp));
if(!(yyval.regexp))
break;
case 37:
-#line 374 "parser.y"
+#line 382 "parser.y"
{
(yyval.regexp) = (yyvsp[(1) - (1)].regexp);
}
break;
case 38:
-#line 378 "parser.y"
+#line 386 "parser.y"
{
(yyval.regexp) = new CatOp((yyvsp[(1) - (2)].regexp), (yyvsp[(2) - (2)].regexp));
}
break;
case 39:
-#line 385 "parser.y"
+#line 393 "parser.y"
{
(yyval.regexp) = (yyvsp[(1) - (1)].regexp);
}
break;
case 40:
-#line 389 "parser.y"
+#line 397 "parser.y"
{
switch((yyvsp[(2) - (2)].op))
{
break;
case 41:
-#line 404 "parser.y"
+#line 412 "parser.y"
{
(yyval.regexp) = new CloseVOp((yyvsp[(1) - (2)].regexp), (yyvsp[(2) - (2)].extop).minsize, (yyvsp[(2) - (2)].extop).maxsize);
}
break;
case 42:
-#line 411 "parser.y"
+#line 419 "parser.y"
{
(yyval.op) = (yyvsp[(1) - (1)].op);
}
break;
case 43:
-#line 415 "parser.y"
+#line 423 "parser.y"
{
(yyval.op) = (yyvsp[(1) - (1)].op);
}
break;
case 44:
-#line 419 "parser.y"
+#line 427 "parser.y"
{
(yyval.op) = ((yyvsp[(1) - (2)].op) == (yyvsp[(2) - (2)].op)) ? (yyvsp[(1) - (2)].op) : '*';
}
break;
case 45:
-#line 423 "parser.y"
+#line 431 "parser.y"
{
(yyval.op) = ((yyvsp[(1) - (2)].op) == (yyvsp[(2) - (2)].op)) ? (yyvsp[(1) - (2)].op) : '*';
}
break;
case 46:
-#line 430 "parser.y"
+#line 438 "parser.y"
{
if(!(yyvsp[(1) - (1)].symbol)->re)
{
break;
case 47:
-#line 438 "parser.y"
+#line 446 "parser.y"
{
(yyval.regexp) = (yyvsp[(1) - (1)].regexp);
}
break;
case 48:
-#line 442 "parser.y"
+#line 450 "parser.y"
{
(yyval.regexp) = (yyvsp[(1) - (1)].regexp);
}
break;
case 49:
-#line 446 "parser.y"
+#line 454 "parser.y"
{
(yyval.regexp) = (yyvsp[(2) - (3)].regexp);
}
/* Line 1267 of yacc.c. */
-#line 1935 "parser.cc"
+#line 1947 "parser.cc"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
}
-#line 451 "parser.y"
+#line 459 "parser.y"
extern "C" {
{
DFA *dfa = NULL;
std::map<std::string, DFA*> dfa_map;
- Scanner::EchoState echo;
in = &i;
o << " */\n";
o << sourceFileInfo;
- while ((echo = i.echo()) != Scanner::Stop)
+ while ((parseMode = i.echo()) != Scanner::Stop)
{
bool bPrologBrace = false;
+ if (rFlag && parseMode == Scanner::Parse && (dfa || dfa_map.size()))
+ {
+ in->fatal("Cannot have another 're2c' block after a block containing rules");
+ }
+ in->set_in_parse(true);
yyparse();
- if (echo == Scanner::Reuse)
+ in->set_in_parse(false);
+ if (parseMode == Scanner::Reuse)
{
if (!dfa && dfa_map.empty())
{
- in->fatal("Got 'repeaet:re2c' without 're2c'");
+ in->fatal("Got 'repeat:re2c' without 're2c'");
}
}
else
if (cFlag)
{
RegExpMap::iterator it;
- StringMap::const_iterator itRuleSetup;
+ SetupMap::const_iterator itRuleSetup;
- if (echo != Scanner::Reuse)
+ if (parseMode != Scanner::Reuse)
+ {
+ if (!specStar.empty())
+ {
+ for (it = specMap.begin(); it != specMap.end(); ++it)
{
- if (!specStar.empty())
- {
- for (it = specMap.begin(); it != specMap.end(); ++it)
- {
- assert(it->second.second);
- for (RuleOpList::const_iterator itOp = specStar.begin(); itOp != specStar.end(); ++itOp)
- {
- it->second.second = mkAlt((*itOp)->copy(accept++), it->second.second);
- }
- }
- }
-
- if (specNone)
- {
- // After merging star rules merge none code to specmap
- // this simplifies some stuff.
- // Note that "0" inserts first, which is important.
- specMap["0"] = std::make_pair(0, specNone);
- }
- else
+ assert(it->second.second);
+ for (RuleOpList::const_iterator itOp = specStar.begin(); itOp != specStar.end(); ++itOp)
{
- // We reserved 0 for specNone but it is not present,
- // so we can decrease all specs.
- for (it = specMap.begin(); it != specMap.end(); ++it)
- {
- it->second.first--;
- }
+ it->second.second = mkAlt((*itOp)->copy(accept++), it->second.second);
}
+ }
+ }
+
+ if (specNone)
+ {
+ // After merging star rules merge none code to specmap
+ // this simplifies some stuff.
+ // Note that "0" inserts first, which is important.
+ specMap["0"] = std::make_pair(0, specNone);
+ }
+ else
+ {
+ // We reserved 0 for specNone but it is not present,
+ // so we can decrease all specs.
+ for (it = specMap.begin(); it != specMap.end(); ++it)
+ {
+ it->second.first--;
+ }
+ }
}
size_t nCount = specMap.size();
{
assert(it->second.second);
- if (echo == Scanner::Reuse)
+ if (parseMode == Scanner::Reuse)
{
dfa_map[it->first]->emit(o, topIndent, &specMap, it->first, !--nCount, bPrologBrace);
}
else
{
- itRuleSetup = ruleSetupMap.find(it->first);
- if (itRuleSetup != ruleSetupMap.end())
- {
- yySetupRule = itRuleSetup->second;
- }
- else
- {
- itRuleSetup = ruleSetupMap.find("*");
+ itRuleSetup = ruleSetupMap.find(it->first);
if (itRuleSetup != ruleSetupMap.end())
{
- yySetupRule = itRuleSetup->second;
+ yySetupRule = itRuleSetup->second.second;
}
else
{
- yySetupRule = "";
+ itRuleSetup = ruleSetupMap.find("*");
+ if (itRuleSetup != ruleSetupMap.end())
+ {
+ yySetupRule = itRuleSetup->second.second;
+ }
+ else
+ {
+ yySetupRule = "";
+ }
}
- }
dfa_map[it->first] = genCode(o, topIndent, it->second.second, &specMap, it->first, !--nCount, bPrologBrace);
}
}
}
else if (spec)
{
- if (echo == Scanner::Reuse)
+ if (parseMode == Scanner::Reuse)
{
dfa->emit(o, topIndent, NULL, "", 0, bPrologBrace);
}
if (cFlag)
{
- StringMap::const_iterator itRuleSetup;
+ SetupMap::const_iterator itRuleSetup;
for (itRuleSetup = ruleSetupMap.begin(); itRuleSetup != ruleSetupMap.end(); ++itRuleSetup)
{
if (itRuleSetup->first != "*" && specMap.find(itRuleSetup->first) == specMap.end())
{
- in->fatalf("Setup for non existing rule '%s' found", itRuleSetup->first.c_str());
+ in->fatalf_at(itRuleSetup->second.first, "Setup for non existing rule '%s' found", itRuleSetup->first.c_str());
}
}
- if (specMap.size() < (ruleSetupMap.find("*") == ruleSetupMap.end() ? ruleSetupMap.size() : ruleSetupMap.size()))
+ if (specMap.size() < ruleSetupMap.size())
{
- in->fatalf("Setup for all rules with '*' not possible when all rules are setup explicitly");
+ uint line = in->get_cline();
+ itRuleSetup = ruleSetupMap.find("*");
+ if (itRuleSetup != ruleSetupMap.end())
+ {
+ line = itRuleSetup->second.first;
+ }
+ in->fatalf_at(line, "Setup for all rules with '*' not possible when all rules are setup explicitly");
}
}