pull/278/head
yhirose 1 year ago
parent 6685012847
commit d8ec5992f6
  1. 9
      peglib.h
  2. 15
      test/test1.cc

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

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

Loading…
Cancel
Save