Skip to content

Commit d8ec599

Browse files
committed
Fix #266
1 parent 6685012 commit d8ec599

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

peglib.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2753,7 +2753,14 @@ inline size_t Holder::parse_core(const char *s, size_t n, SemanticValues &vs,
27532753
chvs.sv_ = std::string_view(s, len);
27542754
chvs.name_ = outer_->name;
27552755

2756-
if (!dynamic_cast<const peg::PrioritizedChoice *>(ope_.get())) {
2756+
auto ope_ptr = ope_.get();
2757+
{
2758+
auto tok_ptr = dynamic_cast<const peg::TokenBoundary *>(ope_ptr);
2759+
if (tok_ptr) {
2760+
ope_ptr = tok_ptr->ope_.get();
2761+
}
2762+
}
2763+
if (!dynamic_cast<const peg::PrioritizedChoice *>(ope_ptr)) {
27572764
chvs.choice_count_ = 0;
27582765
chvs.choice_ = 0;
27592766
}

test/test1.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,3 +1233,18 @@ LINE_END <- '\r\n' / '\r' / '\n' / !.
12331233
}
12341234
}
12351235

1236+
TEST(GeneralTest, ChoiceWithWhitespace) {
1237+
auto parser = peg::parser(R"(
1238+
type <- 'string' / 'int' / 'double'
1239+
%whitespace <- ' '*
1240+
)");
1241+
1242+
parser["type"] = [](const SemanticValues& vs) {
1243+
auto n = vs.choice();
1244+
EXPECT_EQ(1, n);
1245+
};
1246+
1247+
auto ret = parser.parse("int");
1248+
EXPECT_TRUE(ret);
1249+
}
1250+

0 commit comments

Comments
 (0)