Another infinite loop grammar detection. Fix #133

pull/139/head
yhirose 3 years ago
parent 8c68f4cff8
commit 9ad70096c8
  1. BIN
      docs/native.wasm
  2. 4
      peglib.h
  3. 8
      test/test2.cc
  4. 5
      test/test3.cc

Binary file not shown.

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

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

@ -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]")

Loading…
Cancel
Save