diff --git a/docs/native.wasm b/docs/native.wasm index 2f0b1c3..f6d0f32 100644 Binary files a/docs/native.wasm and b/docs/native.wasm differ diff --git a/peglib.h b/peglib.h index e2e85ec..38d6276 100644 --- a/peglib.h +++ b/peglib.h @@ -901,7 +901,6 @@ public: count++; } - auto save_error_pos = c.error_pos; while (n - i > 0 && count < max_) { c.push_capture_scope(); auto se = scope_exit([&]() { c.pop_capture_scope(); }); @@ -921,7 +920,6 @@ public: vs.tokens.erase(vs.tokens.begin() + static_cast(save_tok_size)); } - c.error_pos = save_error_pos; break; } i += len; @@ -987,7 +985,6 @@ public: size_t parse_core(const char *s, size_t n, SemanticValues & /*vs*/, Context &c, std::any &dt) const override { - auto save_error_pos = c.error_pos; auto &chldsv = c.push(); c.push_capture_scope(); auto se = scope_exit([&]() { @@ -999,7 +996,6 @@ public: c.set_error_pos(s); return static_cast(-1); } else { - c.error_pos = save_error_pos; return 0; } } @@ -2104,6 +2100,11 @@ private: enablePackratParsing, tracer_enter, tracer_leave); auto len = ope->parse(s, n, vs, cxt, dt); + if (success(len)) { + cxt.error_pos = nullptr; + cxt.message_pos = nullptr; + cxt.message.clear(); + } return Result{success(len), len, cxt.error_pos, cxt.message_pos, cxt.message}; } @@ -2417,8 +2418,6 @@ inline size_t PrecedenceClimbing::parse_expression(const char *s, size_t n, }; auto action_se = scope_exit([&]() { rule.action = std::move(action); }); - auto save_error_pos = c.error_pos; - auto i = len; while (i < n) { std::vector save_values(vs.begin(), vs.end()); @@ -2428,10 +2427,7 @@ inline size_t PrecedenceClimbing::parse_expression(const char *s, size_t n, auto chl = binop_->parse(s + i, n - i, chv, c, dt); c.pop(); - if (fail(chl)) { - c.error_pos = save_error_pos; - break; - } + if (fail(chl)) { break; } auto it = info_.find(tok); if (it == info_.end()) { break; } @@ -2454,7 +2450,6 @@ inline size_t PrecedenceClimbing::parse_expression(const char *s, size_t n, if (fail(chl)) { vs.assign(save_values.begin(), save_values.end()); vs.tokens = save_tokens; - c.error_pos = save_error_pos; break; }