This commit is contained in:
yhirose 2023-02-07 16:45:59 -05:00
parent 6685012847
commit d8ec5992f6
2 changed files with 23 additions and 1 deletions

View File

@ -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;
}

View File

@ -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);
}