File tree Expand file tree Collapse file tree 2 files changed +26
-9
lines changed Expand file tree Collapse file tree 2 files changed +26
-9
lines changed Original file line number Diff line number Diff line change @@ -2486,18 +2486,23 @@ inline void ReferenceChecker::visit(Reference& ope) {
2486
2486
}
2487
2487
2488
2488
inline void LinkReferences::visit (Reference& ope) {
2489
- if (grammar_.count (ope.name_ )) {
2489
+ // Check if the reference is a macro parameter
2490
+ auto found_param = false ;
2491
+ for (size_t i = 0 ; i < params_.size (); i++) {
2492
+ const auto & param = params_[i];
2493
+ if (param == ope.name_ ) {
2494
+ ope.iarg_ = i;
2495
+ found_param = true ;
2496
+ break ;
2497
+ }
2498
+ }
2499
+
2500
+ // Check if the reference is a definition rule
2501
+ if (!found_param && grammar_.count (ope.name_ )) {
2490
2502
auto & rule = grammar_.at (ope.name_ );
2491
2503
ope.rule_ = &rule;
2492
- } else {
2493
- for (size_t i = 0 ; i < params_.size (); i++) {
2494
- const auto & param = params_[i];
2495
- if (param == ope.name_ ) {
2496
- ope.iarg_ = i;
2497
- break ;
2498
- }
2499
- }
2500
2504
}
2505
+
2501
2506
for (auto arg: ope.args_ ) {
2502
2507
arg->accept (*this );
2503
2508
}
Original file line number Diff line number Diff line change @@ -1453,6 +1453,18 @@ TEST_CASE("Macro token check test", "[macro]")
1453
1453
REQUIRE (parser[" T" ].is_token () == true );
1454
1454
}
1455
1455
1456
+ TEST_CASE (" Macro rule-parameter collision" , " [macro]" )
1457
+ {
1458
+ parser parser (R"(
1459
+ A <- B(C)
1460
+ B(D) <- D
1461
+ C <- 'c'
1462
+ D <- 'd'
1463
+ )" );
1464
+
1465
+ REQUIRE (parser.parse (" c" ));
1466
+ }
1467
+
1456
1468
TEST_CASE (" Line information test" , " [line information]" )
1457
1469
{
1458
1470
parser parser (R"(
You can’t perform that action at this time.
0 commit comments