From a3a9ad672c73f252f32630fe58395a8ef6adaa78 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Fri, 23 Dec 2016 16:10:50 +0000 Subject: [PATCH] Keep '*' rules separately from other rules. --- re2c/bootstrap/src/parse/lex.cc | 2 +- re2c/bootstrap/src/parse/parser.cc | 12 +++--------- re2c/src/parse/parser.h | 3 +++ re2c/src/parse/parser.ypp | 12 +++--------- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/re2c/bootstrap/src/parse/lex.cc b/re2c/bootstrap/src/parse/lex.cc index 614eaf48..56b6d20c 100644 --- a/re2c/bootstrap/src/parse/lex.cc +++ b/re2c/bootstrap/src/parse/lex.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.16 on Fri Dec 23 15:51:34 2016 */ +/* Generated by re2c 0.16 on Fri Dec 23 16:09:39 2016 */ #line 1 "../src/parse/lex.re" #include "src/util/c99_stdint.h" #include diff --git a/re2c/bootstrap/src/parse/parser.cc b/re2c/bootstrap/src/parse/parser.cc index b2c88683..a2c6d55c 100644 --- a/re2c/bootstrap/src/parse/parser.cc +++ b/re2c/bootstrap/src/parse/parser.cc @@ -179,7 +179,7 @@ static void make_star(Scanner &in, context_t &context, RegExpRule *rule, Code *c check_cflag(in); rule->code = code; - context.specMap["*"].push_back(rule); + context.spec_all.push_back(rule); } static void make_zero(Scanner &in, context_t &context, Code *code) @@ -2135,18 +2135,12 @@ void parse(Scanner &in, Output & o) for (it = context.specMap.begin(); it != context.specMap.end(); ++it) { check_default(it->second, it->first); } + check_default(context.spec_all, "*"); // merge <*> rules to all conditions except "0" with lowest priority - Spec star; - if ((it = context.specMap.find("*")) != context.specMap.end()) { - star = it->second; - context.specMap.erase(it); - } for (it = context.specMap.begin(); it != context.specMap.end(); ++it) { if (it->first == "0") continue; - for (size_t j = 0; j < star.size(); ++j) { - it->second.push_back(star[j]); - } + it->second.insert(it->second.end(), context.spec_all.begin(), context.spec_all.end()); } for (it = context.specMap.begin(); it != context.specMap.end(); ++it) { diff --git a/re2c/src/parse/parser.h b/re2c/src/parse/parser.h index cf17d626..23d45c0c 100644 --- a/re2c/src/parse/parser.h +++ b/re2c/src/parse/parser.h @@ -27,12 +27,14 @@ struct context_t { std::vector condnames; SpecMap specMap; + Spec spec_all; SetupMap ruleSetupMap; symbol_table_t symbol_table; context_t() : condnames() , specMap() + , spec_all() , ruleSetupMap() , symbol_table() {} @@ -40,6 +42,7 @@ struct context_t { condnames.clear(); specMap.clear(); + spec_all.clear(); ruleSetupMap.clear(); symbol_table.clear(); } diff --git a/re2c/src/parse/parser.ypp b/re2c/src/parse/parser.ypp index 3014e737..0f39ce73 100644 --- a/re2c/src/parse/parser.ypp +++ b/re2c/src/parse/parser.ypp @@ -111,7 +111,7 @@ static void make_star(Scanner &in, context_t &context, RegExpRule *rule, Code *c check_cflag(in); rule->code = code; - context.specMap["*"].push_back(rule); + context.spec_all.push_back(rule); } static void make_zero(Scanner &in, context_t &context, Code *code) @@ -494,18 +494,12 @@ void parse(Scanner &in, Output & o) for (it = context.specMap.begin(); it != context.specMap.end(); ++it) { check_default(it->second, it->first); } + check_default(context.spec_all, "*"); // merge <*> rules to all conditions except "0" with lowest priority - Spec star; - if ((it = context.specMap.find("*")) != context.specMap.end()) { - star = it->second; - context.specMap.erase(it); - } for (it = context.specMap.begin(); it != context.specMap.end(); ++it) { if (it->first == "0") continue; - for (size_t j = 0; j < star.size(); ++j) { - it->second.push_back(star[j]); - } + it->second.insert(it->second.end(), context.spec_all.begin(), context.spec_all.end()); } for (it = context.specMap.begin(); it != context.specMap.end(); ++it) { -- 2.40.0