From 21f555639ecc63210cd7cf78cd6611c26dfe51c2 Mon Sep 17 00:00:00 2001 From: yhirose Date: Sun, 6 Dec 2015 23:01:27 -0500 Subject: [PATCH] Code cleanup. --- peglib.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/peglib.h b/peglib.h index 53576f7..c503975 100644 --- a/peglib.h +++ b/peglib.h @@ -207,15 +207,14 @@ auto make_scope_exit(EF&& exit_function) noexcept { struct SemanticValue { any val; - const char* name; const char* s; size_t n; SemanticValue() : s(nullptr), n(0) {} - SemanticValue(const any& val, const char* name, const char* s, size_t n) - : val(val), name(name), s(s), n(n) {} + SemanticValue(const any& val, const char* s, size_t n) + : val(val), s(s), n(n) {} template T& get() { @@ -487,12 +486,12 @@ public: const char* message_pos; std::string message; // TODO: should be `int`. - size_t nest_level; - std::vector definition_stack; - std::vector> value_stack; size_t value_stack_size; + size_t nest_level; + std::vector definition_stack; + std::shared_ptr whitespaceOpe; bool in_whiltespace; bool in_token; @@ -519,11 +518,11 @@ public: , l(l) , error_pos(nullptr) , message_pos(nullptr) + , value_stack_size(0) + , nest_level(0) , whitespaceOpe(whitespaceOpe) , in_whiltespace(false) , in_token(false) - , nest_level(0) - , value_stack_size(0) , def_count(def_count) , enablePackratParsing(enablePackratParsing) , cache_register(enablePackratParsing ? def_count * (l + 1) : 0) @@ -681,7 +680,7 @@ public: auto& chldsv = c.push(); const auto& rule = *ope; auto len = rule.parse(s, n, chldsv, c, dt); - if (len != -1) { + if (success(len)) { if (!chldsv.empty()) { sv.insert(sv.end(), chldsv.begin(), chldsv.end()); } @@ -841,7 +840,6 @@ public: c.set_error_pos(s); return -1; } else { - sv.rewind(s); c.error_pos = save_error_pos; return 0; } @@ -1474,7 +1472,7 @@ inline size_t Holder::parse(const char* s, size_t n, SemanticValues& sv, Context if (success(len)) { if (!outer_->ignoreSemanticValue) { - sv.emplace_back(val, outer_->name.c_str(), token_boundary_s, token_boundary_n); + sv.emplace_back(val, token_boundary_s, token_boundary_n); } } else { if (outer_->error_message) {