|
243 | 243 | { |
244 | 244 | rule = Grammar::ParameterizingRule::Rule.new(val[2].s_value, [], val[4], is_inline: true) |
245 | 245 | @grammar.add_parameterizing_rule(rule) |
| 246 | + @grammar.initialize_if_count |
246 | 247 | } |
247 | 248 | | "%rule" "%inline" IDENTIFIER "(" rule_args ")" ":" rule_rhs_list |
248 | 249 | { |
|
288 | 289 | builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]]) |
289 | 290 | result = builder |
290 | 291 | } |
291 | | - | rule_rhs IDENTIFIER "(" parameterizing_args ")" TAG? |
| 292 | + | rule_rhs IDENTIFIER "(" parameterizing_rule_args ")" TAG? |
292 | 293 | { |
293 | 294 | builder = val[0] |
294 | 295 | builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[5]) |
@@ -322,6 +323,21 @@ rule |
322 | 323 | builder.precedence_sym = sym |
323 | 324 | result = builder |
324 | 325 | } |
| 326 | + | rule_rhs "%if" "(" IDENTIFIER ")" |
| 327 | + { |
| 328 | + builder = val[0] |
| 329 | + builder.symbols << Lrama::Lexer::Token::ControlSyntax.new(s_value: val[1], location: @lexer.location, condition: val[3]) |
| 330 | + @grammar.if_count += 1 |
| 331 | + result = builder |
| 332 | + } |
| 333 | + | rule_rhs "%endif" |
| 334 | + { |
| 335 | + on_action_error("no %if before %endif", val[0]) if @grammar.if_count == 0 |
| 336 | + builder = val[0] |
| 337 | + builder.symbols << Lrama::Lexer::Token::ControlSyntax.new(s_value: val[1], location: @lexer.location) |
| 338 | + @grammar.if_count -= 1 |
| 339 | + result = builder |
| 340 | + } |
325 | 341 |
|
326 | 342 | alias: # empty |
327 | 343 | | string_as_id { result = val[0].s_value } |
@@ -494,11 +510,22 @@ rule |
494 | 510 | | "+" { result = "nonempty_list" } |
495 | 511 | | "*" { result = "list" } |
496 | 512 |
|
497 | | - parameterizing_args: symbol { result = [val[0]] } |
498 | | - | parameterizing_args ',' symbol { result = val[0].append(val[2]) } |
| 513 | + parameterizing_rule_args: symbol { result = [val[0]] } |
| 514 | + | parameterizing_args ',' symbol { result = val[0].append(val[2]) } |
| 515 | + | symbol parameterizing_suffix { result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] } |
| 516 | + | IDENTIFIER "(" parameterizing_args ")" { result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] } |
| 517 | + |
| 518 | + parameterizing_args: symbol_or_bool { result = [val[0]] } |
| 519 | + | parameterizing_args ',' symbol_or_bool { result = val[0].append(val[2]) } |
499 | 520 | | symbol parameterizing_suffix { result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] } |
500 | 521 | | IDENTIFIER "(" parameterizing_args ")" { result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] } |
501 | 522 |
|
| 523 | + symbol_or_bool: symbol |
| 524 | + | bool |
| 525 | + |
| 526 | + bool: "%true" { result = Lrama::Lexer::Token::Ident.new(s_value: true) } |
| 527 | + | "%false" { result = Lrama::Lexer::Token::Ident.new(s_value: false) } |
| 528 | + |
502 | 529 | named_ref_opt: # empty |
503 | 530 | | '[' IDENTIFIER ']' { result = val[1].s_value } |
504 | 531 |
|
|
0 commit comments