Skip to content

Commit

Permalink
Fix #202
Browse files Browse the repository at this point in the history
  • Loading branch information
yhirose committed May 27, 2022
1 parent adfd2d6 commit 7ee4fcc
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 53 deletions.
9 changes: 5 additions & 4 deletions peglib.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// peglib.h
//
// Copyright (c) 2020 Yuji Hirose. All rights reserved.
// Copyright (c) 2022 Yuji Hirose. All rights reserved.
// MIT License
//

Expand Down Expand Up @@ -719,11 +719,10 @@ struct ErrorInfo {
auto first_item = true;
size_t i = 0;
while (i < expected_tokens.size()) {
auto [token, is_literal] =
expected_tokens[expected_tokens.size() - i - 1];
auto [token, is_literal] = expected_tokens[i];

// Skip rules start with '_'
if (!is_literal && token[0] != '_') {
if (!is_literal || token[0] != '_') {
msg += (first_item ? ", expecting " : ", ");
if (is_literal) {
msg += "'";
Expand Down Expand Up @@ -1123,6 +1122,7 @@ class Repetition : public Ope {
auto se = scope_exit([&]() { c.pop_capture_scope(); });
auto save_sv_size = vs.size();
auto save_tok_size = vs.tokens.size();
auto save_error_info = c.error_info;
const auto &rule = *ope_;
auto len = rule.parse(s + i, n - i, vs, c, dt);
if (success(len)) {
Expand All @@ -1137,6 +1137,7 @@ class Repetition : public Ope {
vs.tokens.erase(vs.tokens.begin() +
static_cast<std::ptrdiff_t>(save_tok_size));
}
c.error_info = save_error_info;
break;
}
i += len;
Expand Down
Loading

0 comments on commit 7ee4fcc

Please sign in to comment.