mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-11-24 10:35:29 +00:00
Fix #266
This commit is contained in:
parent
6685012847
commit
d8ec5992f6
9
peglib.h
9
peglib.h
@ -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…
Reference in New Issue
Block a user