mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Fix #107
This commit is contained in:
parent
072cdb6d23
commit
580721aa46
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>PEG Playground - v0.1.6</title>
|
||||
<title>PEG Playground - v0.1.7</title>
|
||||
<link rel="stylesheet" href="style.css" media="all">
|
||||
</head>
|
||||
<body>
|
||||
|
File diff suppressed because one or more lines are too long
BIN
docs/native.wasm
BIN
docs/native.wasm
Binary file not shown.
10
peglib.h
10
peglib.h
@ -1934,6 +1934,9 @@ struct HasEmptyElement : public Ope::Visitor {
|
||||
}
|
||||
void visit(AndPredicate & /*ope*/) override { set_error(); }
|
||||
void visit(NotPredicate & /*ope*/) override { set_error(); }
|
||||
void visit(LiteralString &ope) override {
|
||||
if (ope.lit_.empty()) { set_error(); }
|
||||
}
|
||||
void visit(CaptureScope &ope) override { ope.ope_->accept(*this); }
|
||||
void visit(Capture &ope) override { ope.ope_->accept(*this); }
|
||||
void visit(TokenBoundary &ope) override { ope.ope_->accept(*this); }
|
||||
@ -3626,15 +3629,14 @@ ast_to_s(const std::shared_ptr<T> &ptr,
|
||||
}
|
||||
|
||||
struct AstOptimizer {
|
||||
AstOptimizer(bool mode,
|
||||
const std::vector<std::string> &rules = {})
|
||||
AstOptimizer(bool mode, const std::vector<std::string> &rules = {})
|
||||
: mode_(mode), rules_(rules) {}
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<T> optimize(std::shared_ptr<T> original,
|
||||
std::shared_ptr<T> parent = nullptr) {
|
||||
auto found = std::find(rules_.begin(), rules_.end(), original->name) !=
|
||||
rules_.end();
|
||||
auto found =
|
||||
std::find(rules_.begin(), rules_.end(), original->name) != rules_.end();
|
||||
bool opt = mode_ ? !found : found;
|
||||
|
||||
if (opt && original->nodes.size() == 1) {
|
||||
|
@ -59,6 +59,25 @@ TEST_CASE("Infinite loop 5", "[infinite loop]")
|
||||
REQUIRE(!pg);
|
||||
}
|
||||
|
||||
TEST_CASE("Infinite loop 6", "[infinite loop]")
|
||||
{
|
||||
parser pg(R"(
|
||||
S <- ''*
|
||||
)");
|
||||
|
||||
REQUIRE(!pg);
|
||||
}
|
||||
|
||||
TEST_CASE("Infinite loop 7", "[infinite loop]")
|
||||
{
|
||||
parser pg(R"(
|
||||
S <- A*
|
||||
A <- ''
|
||||
)");
|
||||
|
||||
REQUIRE(!pg);
|
||||
}
|
||||
|
||||
TEST_CASE("Not infinite 1", "[infinite loop]")
|
||||
{
|
||||
parser pg(R"(
|
||||
|
Loading…
Reference in New Issue
Block a user