This commit is contained in:
yhirose 2018-10-06 22:29:51 -04:00
parent 304029a8d3
commit 5b3ad705c4

View File

@ -1178,8 +1178,8 @@ public:
void accept(Visitor& v) override; void accept(Visitor& v) override;
std::string lit_; std::string lit_;
mutable bool init_is_word_; mutable bool init_is_word_;
mutable bool is_word_; mutable bool is_word_;
}; };
class CharacterClass : public Ope class CharacterClass : public Ope
@ -2043,27 +2043,27 @@ inline size_t parse_literal(const char* s, size_t n, SemanticValues& sv, Context
} }
} }
// Word check // Word check
static Context dummy_c(nullptr, lit.data(), lit.size(), 0, nullptr, nullptr, false, nullptr); static Context dummy_c(nullptr, lit.data(), lit.size(), 0, nullptr, nullptr, false, nullptr);
static SemanticValues dummy_sv; static SemanticValues dummy_sv;
static any dummy_dt; static any dummy_dt;
if (!init_is_word) { // TODO: Protect with mutex if (!init_is_word) { // TODO: Protect with mutex
if (c.wordOpe) { if (c.wordOpe) {
auto len = c.wordOpe->parse(lit.data(), lit.size(), dummy_sv, dummy_c, dummy_dt); auto len = c.wordOpe->parse(lit.data(), lit.size(), dummy_sv, dummy_c, dummy_dt);
is_word = success(len); is_word = success(len);
} }
init_is_word = true; init_is_word = true;
} }
if (is_word) { if (is_word) {
auto ope = std::make_shared<NotPredicate>(c.wordOpe); auto ope = std::make_shared<NotPredicate>(c.wordOpe);
auto len = ope->parse(s + i, n - i, dummy_sv, dummy_c, dummy_dt); auto len = ope->parse(s + i, n - i, dummy_sv, dummy_c, dummy_dt);
if (fail(len)) { if (fail(len)) {
return static_cast<size_t>(-1); return static_cast<size_t>(-1);
} }
i += len; i += len;
} }
// Skip whiltespace // Skip whiltespace
if (!c.in_token) { if (!c.in_token) {
@ -2085,7 +2085,7 @@ inline size_t LiteralString::parse(const char* s, size_t n, SemanticValues& sv,
} }
inline size_t TokenBoundary::parse(const char* s, size_t n, SemanticValues& sv, Context& c, any& dt) const { inline size_t TokenBoundary::parse(const char* s, size_t n, SemanticValues& sv, Context& c, any& dt) const {
c.in_token = true; c.in_token = true;
auto se = make_scope_exit([&]() { c.in_token = false; }); auto se = make_scope_exit([&]() { c.in_token = false; });
const auto& rule = *ope_; const auto& rule = *ope_;
auto len = rule.parse(s, n, sv, c, dt); auto len = rule.parse(s, n, sv, c, dt);
@ -2189,33 +2189,33 @@ inline any Holder::reduce(const SemanticValues& sv, any& dt) const {
inline size_t Reference::parse( inline size_t Reference::parse(
const char* s, size_t n, SemanticValues& sv, Context& c, any& dt) const { const char* s, size_t n, SemanticValues& sv, Context& c, any& dt) const {
if (rule_) { if (rule_) {
// Reference rule // Reference rule
if (rule_->is_macro) { if (rule_->is_macro) {
// Macro // Macro
FindReference vis(c.top_args(), rule_->params); FindReference vis(c.top_args(), rule_->params);
// Collect arguments // Collect arguments
std::vector<std::shared_ptr<Ope>> args; std::vector<std::shared_ptr<Ope>> args;
for (auto arg: args_) { for (auto arg: args_) {
arg->accept(vis); arg->accept(vis);
args.push_back(vis.found_ope); args.push_back(vis.found_ope);
} }
c.push_args(args); c.push_args(args);
auto se = make_scope_exit([&]() { c.pop_args(); }); auto se = make_scope_exit([&]() { c.pop_args(); });
auto ope = get_core_operator(); auto ope = get_core_operator();
return ope->parse(s, n, sv, c, dt); return ope->parse(s, n, sv, c, dt);
} else { } else {
// Definition // Definition
auto ope = get_core_operator(); auto ope = get_core_operator();
return ope->parse(s, n, sv, c, dt); return ope->parse(s, n, sv, c, dt);
} }
} else { } else {
// Reference parameter in macro // Reference parameter in macro
const auto& args = c.top_args(); const auto& args = c.top_args();
return args[iarg_]->parse(s, n, sv, c, dt); return args[iarg_]->parse(s, n, sv, c, dt);
} }
} }
inline std::shared_ptr<Ope> Reference::get_core_operator() const { inline std::shared_ptr<Ope> Reference::get_core_operator() const {