mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Another infinite loop grammar detection. Fix #133
This commit is contained in:
parent
8c68f4cff8
commit
9ad70096c8
BIN
docs/native.wasm
BIN
docs/native.wasm
Binary file not shown.
4
peglib.h
4
peglib.h
@ -2872,7 +2872,9 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
g["Sequence"] = [&](const SemanticValues &vs) {
|
g["Sequence"] = [&](const SemanticValues &vs) {
|
||||||
if (vs.size() == 1) {
|
if (vs.empty()) {
|
||||||
|
return npd(dot());
|
||||||
|
} else if (vs.size() == 1) {
|
||||||
return std::any_cast<std::shared_ptr<Ope>>(vs[0]);
|
return std::any_cast<std::shared_ptr<Ope>>(vs[0]);
|
||||||
} else {
|
} else {
|
||||||
std::vector<std::shared_ptr<Ope>> opes;
|
std::vector<std::shared_ptr<Ope>> opes;
|
||||||
|
@ -159,6 +159,14 @@ TEST_CASE("Infinite loop 7", "[infinite loop]") {
|
|||||||
REQUIRE(!pg);
|
REQUIRE(!pg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Infinite loop 8", "[infinite loop]") {
|
||||||
|
parser pg(R"(
|
||||||
|
ROOT <- ('A' /)*
|
||||||
|
)");
|
||||||
|
|
||||||
|
REQUIRE(!pg);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("Not infinite 1", "[infinite loop]") {
|
TEST_CASE("Not infinite 1", "[infinite loop]") {
|
||||||
parser pg(R"(
|
parser pg(R"(
|
||||||
Numbers <- Number* EOF
|
Numbers <- Number* EOF
|
||||||
|
@ -42,6 +42,11 @@ TEST_CASE("PEG Expression", "[peg]")
|
|||||||
REQUIRE(exact(g, "Expression", "") == true);
|
REQUIRE(exact(g, "Expression", "") == true);
|
||||||
REQUIRE(exact(g, "Expression", " ") == false);
|
REQUIRE(exact(g, "Expression", " ") == false);
|
||||||
REQUIRE(exact(g, "Expression", " a b ") == false);
|
REQUIRE(exact(g, "Expression", " a b ") == false);
|
||||||
|
|
||||||
|
// NOTE: The followings are actually allowed in the original Ford's paper...
|
||||||
|
REQUIRE(exact(g, "Expression", "a//b ") == true);
|
||||||
|
REQUIRE(exact(g, "Expression", "a // b ") == true);
|
||||||
|
REQUIRE(exact(g, "Expression", "a / / b ") == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("PEG Sequence", "[peg]")
|
TEST_CASE("PEG Sequence", "[peg]")
|
||||||
|
Loading…
Reference in New Issue
Block a user