pull/73/head v0.1.2
yhirose 5 years ago
parent e4095076e3
commit be470f9332
  1. 23
      peglib.h
  2. 12
      test/test.cc

@ -2486,18 +2486,23 @@ inline void ReferenceChecker::visit(Reference& ope) {
}
inline void LinkReferences::visit(Reference& ope) {
if (grammar_.count(ope.name_)) {
// 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;
} else {
for (size_t i = 0; i < params_.size(); i++) {
const auto& param = params_[i];
if (param == ope.name_) {
ope.iarg_ = i;
break;
}
}
}
for (auto arg: ope.args_) {
arg->accept(*this);
}

@ -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…
Cancel
Save