mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Fix #71
This commit is contained in:
parent
e4095076e3
commit
be470f9332
13
peglib.h
13
peglib.h
@ -2486,18 +2486,23 @@ inline void ReferenceChecker::visit(Reference& ope) {
|
||||
}
|
||||
|
||||
inline void LinkReferences::visit(Reference& ope) {
|
||||
if (grammar_.count(ope.name_)) {
|
||||
auto& rule = grammar_.at(ope.name_);
|
||||
ope.rule_ = &rule;
|
||||
} else {
|
||||
// Check if the reference is a macro parameter
|
||||
auto found_param = false;
|
||||
for (size_t i = 0; i < params_.size(); i++) {
|
||||
const auto& param = params_[i];
|
||||
if (param == ope.name_) {
|
||||
ope.iarg_ = i;
|
||||
found_param = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the reference is a definition rule
|
||||
if (!found_param && grammar_.count(ope.name_)) {
|
||||
auto& rule = grammar_.at(ope.name_);
|
||||
ope.rule_ = &rule;
|
||||
}
|
||||
|
||||
for (auto arg: ope.args_) {
|
||||
arg->accept(*this);
|
||||
}
|
||||
|
12
test/test.cc
12
test/test.cc
@ -1453,6 +1453,18 @@ TEST_CASE("Macro token check test", "[macro]")
|
||||
REQUIRE(parser["T"].is_token() == true);
|
||||
}
|
||||
|
||||
TEST_CASE("Macro rule-parameter collision", "[macro]")
|
||||
{
|
||||
parser parser(R"(
|
||||
A <- B(C)
|
||||
B(D) <- D
|
||||
C <- 'c'
|
||||
D <- 'd'
|
||||
)");
|
||||
|
||||
REQUIRE(parser.parse("c"));
|
||||
}
|
||||
|
||||
TEST_CASE("Line information test", "[line information]")
|
||||
{
|
||||
parser parser(R"(
|
||||
|
Loading…
Reference in New Issue
Block a user