From 8c68f4cff85bc10b103063314f41e2cb02687fb4 Mon Sep 17 00:00:00 2001 From: yhirose Date: Fri, 8 Jan 2021 15:07:30 -0500 Subject: [PATCH] Fixed error report problems --- docs/native.wasm | Bin 349328 -> 349329 bytes peglib.h | 17 ++++++----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/docs/native.wasm b/docs/native.wasm index 2f0b1c3b7c8809df757fd394f5c455b7907a4a4e..f6d0f321b1839152719e1cc10a6854eb038c54c9 100644 GIT binary patch delta 618 zcmXw#O=uHQ6ouct^P0bzw9_+_2#7 z&NFMh2v2uT)Hc4sR`{a;_b26(AskjW7GMS(wYvawEPEE=s54A4|Ep-b8P<2Kqpan& zn+>lnLIrXuk|aGW`$4P73vT3Cai4G~~vODt|R8dI;^jQ=>bZ`9Xdi zJeA8QWR;vvN~>Z6=Cb`=ly`i&-ruIlQR@x34Joz12}L_gQ4bwG_S$zNG^$!nC_qMa zns7R&X@86MbP|Y<9$wbtn*9qcP#+p_Al!EbmH788Cj!`$E@`Jy5OfiFrpZh@&!6*18l4k4&hZvj6T z)>}sNJ=gu*lSiiDd-&y?{A9q#aH}O(3)N*o(!S)fseKUxUy$%n`}aARqQ@}i2fA&B zm`#c?4Ol|Q4@?);y^hQoX!`1BM;=%83o;S@>By5Yb|`h_6_k%9MAeH`dA)9MNd13% zmTO`^GCUl2<61m7p+&f+7U^35IihWf^(xVY#2AM2TV$%0hjQ0QP+V2l0LY~x|)w>z`@pV|MTb+5nfy;@DehmB{+ zCo}MTl!8ukR+L1UGC}7AmN`2*D{_HUBS~-!^!rOt+UwDebiGBR+l%eW~WO6XH7coE~=KGZ9?^X?y)?tFFt 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; }