mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Fix #112
This commit is contained in:
parent
94578c5274
commit
ff9e5d6ea3
6
peglib.h
6
peglib.h
@ -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) {
|
||||||
|
@ -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"(
|
||||||
|
Loading…
Reference in New Issue
Block a user