Another infinite loop grammar detection. Fix #133

This commit is contained in:
yhirose 2021-01-09 15:10:42 -05:00
parent 8c68f4cff8
commit 9ad70096c8
4 changed files with 16 additions and 1 deletions

Binary file not shown.

View File

@ -2872,7 +2872,9 @@ private:
};
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]);
} else {
std::vector<std::shared_ptr<Ope>> opes;

View File

@ -159,6 +159,14 @@ TEST_CASE("Infinite loop 7", "[infinite loop]") {
REQUIRE(!pg);
}
TEST_CASE("Infinite loop 8", "[infinite loop]") {
parser pg(R"(
ROOT <- ('A' /)*
)");
REQUIRE(!pg);
}
TEST_CASE("Not infinite 1", "[infinite loop]") {
parser pg(R"(
Numbers <- Number* EOF

View File

@ -42,6 +42,11 @@ TEST_CASE("PEG Expression", "[peg]")
REQUIRE(exact(g, "Expression", "") == true);
REQUIRE(exact(g, "Expression", " ") == 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]")