This commit is contained in:
yhirose 2020-06-08 22:54:35 -04:00
parent 94578c5274
commit ff9e5d6ea3
2 changed files with 24 additions and 0 deletions

View File

@ -1762,6 +1762,7 @@ struct AssignIDToDefinition : public Ope::Visitor {
void visit(Holder &ope) override; void visit(Holder &ope) override;
void visit(Reference &ope) override; void visit(Reference &ope) override;
void visit(Whitespace &ope) override { ope.ope_->accept(*this); } void visit(Whitespace &ope) override { ope.ope_->accept(*this); }
void visit(PrecedenceClimbing &ope) override;
std::unordered_map<void *, size_t> ids; std::unordered_map<void *, size_t> ids;
}; };
@ -2733,6 +2734,11 @@ inline void AssignIDToDefinition::visit(Reference &ope) {
} }
} }
inline void AssignIDToDefinition::visit(PrecedenceClimbing &ope) {
ope.atom_->accept(*this);
ope.binop_->accept(*this);
}
inline void TokenChecker::visit(WeakHolder & /*ope*/) { has_rule_ = true; } inline void TokenChecker::visit(WeakHolder & /*ope*/) { has_rule_ = true; }
inline void TokenChecker::visit(Reference &ope) { inline void TokenChecker::visit(Reference &ope) {

View File

@ -325,6 +325,24 @@ TEST_CASE("Packrat parser test with macro", "[packrat]")
REQUIRE(ret == true); REQUIRE(ret == true);
} }
TEST_CASE("Packrat parser test with precedence expression parser", "[packrat]") {
peg::parser parser(R"(
Expression <- Atom (Operator Atom)* { precedence L + - L * / }
Atom <- _? Number _?
Number <- [0-9]+
Operator <- '+' / '-' / '*' / '/'
_ <- ' '+
)");
bool ret = parser;
REQUIRE(ret == true);
parser.enable_packrat_parsing();
ret = parser.parse(" 1 + 2 * 3 ");
REQUIRE(ret == true);
}
TEST_CASE("Backreference test", "[backreference]") TEST_CASE("Backreference test", "[backreference]")
{ {
parser parser(R"( parser parser(R"(