This commit is contained in:
yhirose 2019-11-29 00:57:45 -05:00
parent e4095076e3
commit be470f9332
2 changed files with 27 additions and 10 deletions

View File

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

View File

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