Skip to content

Commit

Permalink
Fix #266
Browse files Browse the repository at this point in the history
  • Loading branch information
yhirose committed Feb 7, 2023
1 parent 6685012 commit d8ec599
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion peglib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2753,7 +2753,14 @@ inline size_t Holder::parse_core(const char *s, size_t n, SemanticValues &vs,
chvs.sv_ = std::string_view(s, len);
chvs.name_ = outer_->name;

if (!dynamic_cast<const peg::PrioritizedChoice *>(ope_.get())) {
auto ope_ptr = ope_.get();
{
auto tok_ptr = dynamic_cast<const peg::TokenBoundary *>(ope_ptr);
if (tok_ptr) {
ope_ptr = tok_ptr->ope_.get();
}
}
if (!dynamic_cast<const peg::PrioritizedChoice *>(ope_ptr)) {
chvs.choice_count_ = 0;
chvs.choice_ = 0;
}
Expand Down
15 changes: 15 additions & 0 deletions test/test1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1233,3 +1233,18 @@ LINE_END <- '\r\n' / '\r' / '\n' / !.
}
}

TEST(GeneralTest, ChoiceWithWhitespace) {
auto parser = peg::parser(R"(
type <- 'string' / 'int' / 'double'
%whitespace <- ' '*
)");

parser["type"] = [](const SemanticValues& vs) {
auto n = vs.choice();
EXPECT_EQ(1, n);
};

auto ret = parser.parse("int");
EXPECT_TRUE(ret);
}

0 comments on commit d8ec599

Please sign in to comment.