From 60d3276dfb43486e0bdeb401a743a5acb2984da4 Mon Sep 17 00:00:00 2001 From: ydah Date: Sun, 9 Jun 2024 13:21:46 +0900 Subject: [PATCH 1/5] [PoC] Intoroduce parameterizing rules with conditonal I would like to propose a new grammar in this PR. I believe that more parameterizing rules can handle more abstract rules if we can switch between rules and actions that are expanded by conditions in order to make rules common. Syntax is as follows: ``` %rule defined_rule(X, condition): /* empty */ | X { $$ = $1; } %if(condition) /* 1 */ | %if(condition) X %endif X { $$ = $1; } /* 2 */ ; %% r_true : defined_rule(number, %true) ; r_false : defined_rule(number, %false) ; ``` 1. It's like a postfix if in Ruby. If condition is false, it is equivalent to missing this line. 2. If statementIf condition is false, it is equivalent to missing RHS between `%if` and`% endif`. I believe it will solve the problem mentioned in the article below with the tight coupling with Lexer "to disable certain generation rules under certain conditions" and I would like to propose this feature to solve this problem. https://yui-knk.hatenablog.com/entry/2023/04/04/190413 We can trace the RHS to [f_args](https://github.com/ruby/ruby/blob/2f916812a9b818b432ee7c299e021ec62d4727fb/parse.y#L5523-L5575) > [args_tail](https://github.com/ruby/ruby/blob/2f916812a9b818b432ee7c299e021ec62d4727fb/parse.y#L5487-L5503) > [args_forward](https://github.com/ruby/ruby/blob/2f916812a9b818b432ee7c299e021ec62d4727fb/parse.y#L5586-L5597), where f_args is the RHS of both the lambda argument (f_larglist) and the method definition argument (f_arglist). So if we can switch between RHS and actions by passing parameters, we can break up the Lexer/Parser coupling here. --- lib/lrama/grammar.rb | 7 +- lib/lrama/grammar/binding.rb | 4 + lib/lrama/grammar/parameterizing_rule/rhs.rb | 25 + lib/lrama/grammar/rule_builder.rb | 6 +- lib/lrama/lexer.rb | 4 + lib/lrama/lexer/token/control_syntax.rb | 34 + lib/lrama/parser.rb | 945 ++++++++++-------- parser.y | 33 +- sig/lrama/grammar/parameterizing_rule/rhs.rbs | 2 + sig/lrama/lexer/token/control_syntax.rbs | 16 + .../parameterizing_rules/user_defined/if.y | 44 + spec/lrama/parser_spec.rb | 103 ++ 12 files changed, 799 insertions(+), 424 deletions(-) create mode 100644 lib/lrama/lexer/token/control_syntax.rb create mode 100644 sig/lrama/lexer/token/control_syntax.rbs create mode 100644 spec/fixtures/parameterizing_rules/user_defined/if.y diff --git a/lib/lrama/grammar.rb b/lib/lrama/grammar.rb index 3724f828..36cb5fb1 100644 --- a/lib/lrama/grammar.rb +++ b/lib/lrama/grammar.rb @@ -28,7 +28,7 @@ class Grammar attr_reader :percent_codes, :eof_symbol, :error_symbol, :undef_symbol, :accept_symbol, :aux, :parameterizing_rule_resolver attr_accessor :union, :expect, :printers, :error_tokens, :lex_param, :parse_param, :initial_action, :after_shift, :before_reduce, :after_reduce, :after_shift_error_token, :after_pop_stack, - :symbols_resolver, :types, :rules, :rule_builders, :sym_to_rules, :no_stdlib, :locations + :symbols_resolver, :types, :rules, :rule_builders, :sym_to_rules, :no_stdlib, :locations, :if_count def_delegators "@symbols_resolver", :symbols, :nterms, :terms, :add_nterm, :add_term, :find_symbol_by_number!, :find_symbol_by_id!, :token_to_symbol, @@ -57,6 +57,7 @@ def initialize(rule_counter) @aux = Auxiliary.new @no_stdlib = false @locations = false + @if_count = 0 append_special_symbols end @@ -171,6 +172,10 @@ def find_rules_by_symbol(sym) @sym_to_rules[sym.number] end + def initialize_if_count + @if_count = 0 + end + private def compute_nullable diff --git a/lib/lrama/grammar/binding.rb b/lib/lrama/grammar/binding.rb index 5e6e7c59..718c3699 100644 --- a/lib/lrama/grammar/binding.rb +++ b/lib/lrama/grammar/binding.rb @@ -17,6 +17,10 @@ def resolve_symbol(symbol) if symbol.is_a?(Lexer::Token::InstantiateRule) resolved_args = symbol.args.map { |arg| resolve_symbol(arg) } Lrama::Lexer::Token::InstantiateRule.new(s_value: symbol.s_value, location: symbol.location, args: resolved_args, lhs_tag: symbol.lhs_tag) + elsif symbol.is_a?(Lexer::Token::ControlSyntax) + resolved = symbol.dup + resolved.condition = @parameter_to_arg[symbol.condition_value] + resolved else parameter_to_arg(symbol) || symbol end diff --git a/lib/lrama/grammar/parameterizing_rule/rhs.rb b/lib/lrama/grammar/parameterizing_rule/rhs.rb index d574841d..c35ceb89 100644 --- a/lib/lrama/grammar/parameterizing_rule/rhs.rb +++ b/lib/lrama/grammar/parameterizing_rule/rhs.rb @@ -12,6 +12,31 @@ def initialize @precedence_sym = nil end + def skip?(bindings) + return false unless @symbols.last + last_sym = bindings.resolve_symbol(@symbols.last) + last_sym.is_a?(Lexer::Token::ControlSyntax) && last_sym.if? && last_sym.false? + end + + def resolve_symbols(bindings) + is_skip = [] + @symbols.map do |sym| + resolved = bindings.resolve_symbol(sym) + if resolved.is_a?(Lexer::Token::ControlSyntax) + if resolved.if? + is_skip.push(resolved.false?) + elsif resolved.endif? + is_skip.pop + else + raise "Unexpected control syntax: #{resolved.condition_value}" + end + nil + else + resolved unless is_skip.last + end + end.compact + end + def resolve_user_code(bindings) return unless user_code diff --git a/lib/lrama/grammar/rule_builder.rb b/lib/lrama/grammar/rule_builder.rb index 65216c57..998fc57e 100644 --- a/lib/lrama/grammar/rule_builder.rb +++ b/lib/lrama/grammar/rule_builder.rb @@ -144,13 +144,17 @@ def process_rhs if (created_lhs = @parameterizing_rule_resolver.created_lhs(lhs_s_value)) @replaced_rhs << created_lhs else + next if parameterizing_rule.rhs_list.all? { |r| r.skip?(bindings) } lhs_token = Lrama::Lexer::Token::Ident.new(s_value: lhs_s_value, location: token.location) @replaced_rhs << lhs_token @parameterizing_rule_resolver.created_lhs_list << lhs_token parameterizing_rule.rhs_list.each do |r| rule_builder = RuleBuilder.new(@rule_counter, @midrule_action_counter, @parameterizing_rule_resolver, lhs_tag: token.lhs_tag || parameterizing_rule.tag) rule_builder.lhs = lhs_token - r.symbols.each { |sym| rule_builder.add_rhs(bindings.resolve_symbol(sym)) } + next if r.skip?(bindings) + r.resolve_symbols(bindings).each do |sym| + rule_builder.add_rhs(sym) + end rule_builder.line = line rule_builder.precedence_sym = r.precedence_sym rule_builder.user_code = r.resolve_user_code(bindings) diff --git a/lib/lrama/lexer.rb b/lib/lrama/lexer.rb index 7231e191..4b0b32dd 100644 --- a/lib/lrama/lexer.rb +++ b/lib/lrama/lexer.rb @@ -41,6 +41,10 @@ class Lexer %no-stdlib %inline %locations + %if + %endif + %true + %false ) def initialize(grammar_file) diff --git a/lib/lrama/lexer/token/control_syntax.rb b/lib/lrama/lexer/token/control_syntax.rb new file mode 100644 index 00000000..9a89368c --- /dev/null +++ b/lib/lrama/lexer/token/control_syntax.rb @@ -0,0 +1,34 @@ +module Lrama + class Lexer + class Token + class ControlSyntax < Token + attr_accessor :condition + + def initialize(s_value:, location:, condition: nil) + @condition = condition + super(s_value: s_value, location: location) + end + + def if? + s_value == '%if' + end + + def endif? + s_value == '%endif' + end + + def true? + !!@condition&.s_value + end + + def false? + !true? + end + + def condition_value + @condition&.s_value + end + end + end + end +end diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index 2d0a8ce7..6fd91ab1 100644 --- a/lib/lrama/parser.rb +++ b/lib/lrama/parser.rb @@ -654,7 +654,7 @@ def token_to_str(t) module Lrama class Parser < Racc::Parser -module_eval(<<'...end parser.y/module_eval...', 'parser.y', 535) +module_eval(<<'...end parser.y/module_eval...', 'parser.y', 562) include Lrama::Report::Duration @@ -728,330 +728,356 @@ def raise_parse_error(error_message, location) ##### State transition tables begin ### racc_action_table = [ - 101, 53, 102, 168, 90, 81, 53, 53, 185, 168, - 81, 81, 53, 3, 185, 53, 81, 52, 170, 161, - 72, 8, 162, 186, 170, 6, 53, 7, 52, 186, - 81, 77, 41, 53, 53, 52, 52, 47, 84, 84, - 53, 188, 52, 91, 162, 84, 171, 48, 53, 103, - 52, 187, 171, 84, 53, 50, 52, 187, 21, 25, - 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 39, 47, 53, 53, 52, 52, 95, - 81, 203, 53, 53, 52, 52, 81, 203, 53, 56, - 52, 225, 81, 203, 226, 21, 25, 26, 27, 28, - 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, - 39, 9, 193, 194, 195, 99, 12, 13, 14, 15, - 16, 17, 47, 125, 18, 19, 20, 21, 25, 26, + 101, 161, 102, 53, 162, 217, 53, 81, 229, 53, + 81, 217, 53, 81, 52, 53, 81, 217, 53, 81, + 52, 190, 81, 53, 162, 168, 53, 81, 185, 53, + 81, 185, 53, 81, 168, 236, 81, 3, 237, 90, + 170, 8, 256, 186, -130, 237, 186, 47, 125, 170, + 195, 196, 197, 103, 222, 223, 41, 222, 223, 47, + 222, 223, 259, 222, 223, 237, 222, 223, 171, 222, + 223, 187, 188, 189, 187, 188, 189, 171, 91, 48, + 21, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 47, 53, 6, 52, + 7, 95, 72, 53, 53, 52, 52, 81, 77, 84, + 53, 53, 52, 52, 50, 84, 84, 21, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, - 37, 38, 39, 53, 53, 52, 52, 81, 203, 53, - 53, 52, 52, 81, 203, 53, 53, 52, 52, 81, - 203, 53, 53, 52, 52, 81, 81, 53, 53, 52, - 52, 81, 81, 53, 53, 52, 52, 81, 81, 53, - 53, 52, 214, 81, 81, 53, 53, 214, 214, 81, - 81, 53, 53, 52, 52, 81, 193, 194, 195, 99, - 230, 238, 56, 226, 226, 53, 53, 52, 52, 53, - 53, 52, 52, 193, 194, 195, 56, 59, 60, 61, - 62, 63, 64, 65, 66, 67, 68, 69, 92, 48, - 97, 99, 104, 104, 104, 106, 112, 115, 117, 120, - 120, 120, 120, 123, 128, 129, 131, 133, 134, 135, - 136, 137, 81, 144, 145, 146, 147, 148, 151, 152, - 153, 155, 165, 144, 167, 173, 175, 176, 177, 178, - 179, 180, 182, 183, 151, 190, 198, 199, 206, 165, - 210, 213, 99, 218, 165, 222, 165, 224, 180, 183, - 183, 99, 235, 180, 237, 180, 99, 99, 180 ] + 37, 38, 39, 9, 53, 53, 52, 52, 12, 13, + 14, 15, 16, 17, 56, 56, 18, 19, 20, 21, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 53, 53, 52, 52, 56, + 84, 195, 196, 197, 59, 53, 99, 52, 60, 81, + 205, 53, 53, 52, 52, 81, 205, 53, 53, 52, + 52, 81, 205, 195, 196, 197, 61, 53, 99, 52, + 62, 81, 205, 53, 53, 52, 52, 81, 205, 53, + 53, 52, 52, 81, 205, 53, 53, 52, 52, 81, + 81, 53, 53, 52, 52, 81, 81, 53, 53, 52, + 52, 81, 81, 53, 53, 52, 52, 81, 53, 53, + 52, 52, 53, 63, 52, 195, 196, 197, 64, 65, + 66, 67, 68, 69, 92, 48, 97, 99, 104, 104, + 104, 106, 112, 115, 117, 120, 120, 120, 120, 123, + 128, 129, 131, 133, 134, 135, 136, 137, 81, 144, + 145, 146, 147, 148, 151, 152, 153, 155, 165, 144, + 167, 173, 175, 176, 177, 178, 179, 180, 182, 183, + 151, 192, 200, 201, 208, 165, 212, 215, 216, 99, + 225, 165, 232, 233, 165, 235, 180, 183, 241, 242, + 244, 246, 183, 99, 251, 180, -128, 255, 180, 99, + -130, 99, 180, -129 ] racc_action_check = [ - 51, 150, 51, 150, 39, 150, 164, 189, 164, 189, - 164, 189, 207, 1, 207, 33, 207, 33, 150, 143, - 33, 3, 143, 164, 189, 2, 34, 2, 34, 207, - 34, 34, 7, 35, 36, 35, 36, 9, 35, 36, - 37, 166, 37, 39, 166, 37, 150, 10, 38, 51, - 38, 164, 189, 38, 13, 12, 13, 207, 9, 9, + 51, 143, 51, 192, 143, 192, 212, 192, 212, 235, + 212, 235, 237, 235, 237, 242, 237, 242, 244, 242, + 244, 166, 244, 150, 166, 150, 164, 150, 164, 209, + 164, 209, 191, 209, 191, 218, 191, 1, 218, 39, + 150, 3, 247, 164, 230, 247, 209, 91, 91, 191, + 230, 230, 230, 51, 192, 192, 7, 212, 212, 9, + 235, 235, 253, 237, 237, 253, 242, 242, 150, 244, + 244, 164, 164, 164, 209, 209, 209, 191, 39, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 42, 71, 177, 71, 177, 42, - 177, 177, 178, 72, 178, 72, 178, 178, 179, 14, - 179, 215, 179, 179, 215, 42, 42, 42, 42, 42, + 9, 9, 9, 9, 9, 9, 42, 33, 2, 33, + 2, 42, 33, 34, 35, 34, 35, 34, 34, 35, + 36, 37, 36, 37, 12, 36, 37, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 4, 169, 169, 169, 169, 4, 4, 4, 4, - 4, 4, 91, 91, 4, 4, 4, 4, 4, 4, + 42, 42, 42, 4, 13, 71, 13, 71, 4, 4, + 4, 4, 4, 4, 14, 15, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 200, 83, 200, 83, 200, 200, 204, - 84, 204, 84, 204, 204, 205, 112, 205, 112, 205, - 205, 76, 77, 76, 77, 76, 77, 117, 119, 117, - 119, 117, 119, 141, 171, 141, 171, 141, 171, 187, - 190, 187, 190, 187, 190, 210, 224, 210, 224, 210, - 224, 226, 114, 226, 114, 226, 184, 184, 184, 184, - 221, 232, 15, 221, 232, 120, 122, 120, 122, 138, - 142, 138, 142, 216, 216, 216, 16, 17, 18, 21, - 25, 26, 27, 28, 29, 30, 31, 32, 40, 44, - 45, 46, 55, 57, 58, 59, 70, 74, 75, 82, - 87, 88, 89, 90, 98, 99, 105, 107, 108, 109, - 110, 111, 116, 123, 124, 125, 126, 127, 128, 129, - 130, 132, 145, 146, 149, 154, 156, 157, 158, 159, - 160, 161, 162, 163, 167, 168, 172, 174, 181, 183, - 185, 188, 192, 196, 206, 211, 213, 214, 217, 220, - 223, 225, 229, 230, 231, 233, 235, 237, 240 ] + 4, 4, 4, 4, 4, 38, 72, 38, 72, 16, + 38, 169, 169, 169, 17, 177, 169, 177, 18, 177, + 177, 178, 83, 178, 83, 178, 178, 179, 84, 179, + 84, 179, 179, 184, 184, 184, 21, 202, 184, 202, + 25, 202, 202, 206, 112, 206, 112, 206, 206, 207, + 114, 207, 114, 207, 207, 76, 77, 76, 77, 76, + 77, 117, 119, 117, 119, 117, 119, 141, 171, 141, + 171, 141, 171, 187, 120, 187, 120, 187, 122, 138, + 122, 138, 142, 26, 142, 220, 220, 220, 27, 28, + 29, 30, 31, 32, 40, 44, 45, 46, 55, 57, + 58, 59, 70, 74, 75, 82, 87, 88, 89, 90, + 98, 99, 105, 107, 108, 109, 110, 111, 116, 123, + 124, 125, 126, 127, 128, 129, 130, 132, 145, 146, + 149, 154, 156, 157, 158, 159, 160, 161, 162, 163, + 167, 168, 172, 174, 181, 183, 185, 188, 190, 194, + 198, 208, 213, 215, 216, 217, 224, 227, 228, 229, + 231, 233, 234, 236, 240, 241, 243, 245, 248, 251, + 254, 255, 258, 259 ] racc_action_pointer = [ - nil, 13, 15, 21, 102, nil, nil, 25, nil, 33, - 34, nil, 49, 51, 69, 182, 196, 212, 198, nil, - nil, 199, nil, nil, nil, 200, 201, 202, 218, 219, - 220, 221, 222, 12, 23, 30, 31, 37, 45, -1, - 226, nil, 70, nil, 216, 217, 179, nil, nil, nil, - nil, -5, nil, nil, nil, 212, nil, 213, 214, 215, + nil, 37, 88, 41, 124, nil, nil, 49, nil, 55, + 66, nil, 108, 131, 124, 125, 149, 169, 158, nil, + nil, 176, nil, nil, nil, 180, 223, 228, 244, 245, + 246, 247, 248, 94, 100, 101, 107, 108, 162, 34, + 252, nil, 92, nil, 242, 243, 201, nil, nil, nil, + nil, -5, nil, nil, nil, 238, nil, 239, 240, 241, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 228, 72, 80, nil, 231, 230, 158, 159, nil, nil, - nil, nil, 231, 141, 147, nil, nil, 232, 233, 234, - 202, 118, nil, nil, nil, nil, nil, nil, 201, 240, - nil, nil, nil, nil, nil, 244, nil, 245, 246, 247, - 248, 249, 153, nil, 189, nil, 245, 164, nil, 165, - 202, nil, 203, 248, 211, 214, 245, 255, 211, 206, - 258, nil, 259, nil, nil, nil, nil, nil, 206, nil, - nil, 170, 207, -23, nil, 215, 258, nil, nil, 218, - -2, nil, nil, nil, 244, nil, 245, 246, 247, 248, - 249, 263, 267, 227, 3, nil, -1, 227, 234, 63, - nil, 171, 255, nil, 256, nil, nil, 73, 79, 85, - nil, 235, nil, 232, 147, 239, nil, 176, 238, 4, - 177, nil, 230, nil, nil, nil, 281, nil, nil, nil, - 140, nil, nil, nil, 146, 152, 237, 9, nil, nil, - 182, 283, nil, 239, 246, 49, 164, 280, nil, nil, - 243, 158, nil, 244, 183, 239, 188, nil, nil, 271, - 285, 273, 159, 287, nil, 244, nil, 245, nil, nil, - 290, nil, nil ] + 254, 132, 163, nil, 257, 256, 212, 213, nil, nil, + nil, nil, 257, 179, 185, nil, nil, 258, 259, 260, + 228, 43, nil, nil, nil, nil, nil, nil, 227, 266, + nil, nil, nil, nil, nil, 270, nil, 271, 272, 273, + 274, 275, 201, nil, 207, nil, 271, 218, nil, 219, + 231, nil, 235, 274, 237, 240, 271, 281, 237, 228, + 284, nil, 285, nil, nil, nil, nil, nil, 236, nil, + nil, 224, 239, -41, nil, 241, 284, nil, nil, 244, + 20, nil, nil, nil, 270, nil, 271, 272, 273, 274, + 275, 289, 293, 253, 23, nil, -21, 253, 260, 120, + nil, 225, 281, nil, 282, nil, nil, 172, 178, 184, + nil, 261, nil, 258, 142, 265, nil, 230, 266, nil, + 265, 29, 0, nil, 253, nil, nil, nil, 308, nil, + nil, nil, 194, nil, nil, nil, 200, 206, 264, 26, + nil, nil, 3, 310, nil, 308, 267, 274, -7, nil, + 194, nil, nil, nil, 308, nil, nil, 271, 276, 278, + -1, 275, nil, 279, 276, 6, 267, 9, nil, nil, + 303, 317, 12, 281, 15, 306, nil, 0, 320, nil, + nil, 273, nil, 20, 285, 275, nil, nil, 324, 288, + nil, nil ] racc_action_default = [ - -2, -140, -10, -140, -140, -3, -4, -140, 243, -140, - -8, -12, -140, -140, -140, -140, -140, -140, -140, -24, - -25, -140, -29, -30, -31, -140, -140, -140, -140, -140, - -140, -140, -140, -140, -140, -140, -140, -140, -140, -140, - -140, -7, -127, -101, -8, -140, -124, -126, -9, -11, - -13, -131, -99, -100, -130, -15, -90, -16, -17, -140, + -2, -150, -10, -150, -150, -3, -4, -150, 262, -150, + -8, -12, -150, -150, -150, -150, -150, -150, -150, -24, + -25, -150, -29, -30, -31, -150, -150, -150, -150, -150, + -150, -150, -150, -150, -150, -150, -150, -150, -150, -150, + -150, -7, -137, -103, -8, -150, -134, -136, -9, -11, + -13, -141, -101, -102, -140, -15, -92, -16, -17, -150, -21, -26, -32, -35, -38, -41, -42, -43, -44, -45, - -46, -52, -140, -55, -57, -47, -80, -140, -83, -85, - -86, -139, -48, -93, -140, -96, -98, -49, -50, -51, - -140, -140, -5, -1, -102, -128, -103, -104, -140, -140, - -14, -132, -133, -134, -87, -140, -18, -140, -140, -140, - -140, -140, -140, -56, -53, -58, -78, -140, -84, -81, - -140, -97, -94, -140, -140, -140, -140, -140, -108, -140, - -140, -91, -140, -22, -27, -33, -36, -39, -54, -59, - -79, -82, -95, -140, -65, -69, -140, -6, -129, -105, - -106, -109, -125, -88, -140, -19, -140, -140, -140, -140, - -140, -60, -140, -63, -67, -70, -140, -108, -99, -124, - -113, -140, -140, -92, -140, -23, -28, -140, -140, -140, - -61, -140, -66, -69, -124, -99, -74, -140, -140, -107, - -140, -110, -124, -117, -118, -119, -140, -116, -89, -20, - -34, -135, -137, -138, -37, -40, -69, -68, -71, -72, - -140, -140, -77, -69, -99, -140, -120, -60, -114, -136, - -62, -140, -75, -64, -140, -124, -140, -122, -111, -140, - -60, -140, -140, -60, -121, -124, -73, -124, -123, -112, - -60, -76, -115 ] + -46, -52, -150, -55, -57, -47, -82, -150, -85, -87, + -88, -149, -48, -95, -150, -98, -100, -49, -50, -51, + -150, -150, -5, -1, -104, -138, -105, -106, -150, -150, + -14, -142, -143, -144, -89, -150, -18, -150, -150, -150, + -150, -150, -150, -56, -53, -58, -80, -150, -86, -83, + -150, -99, -96, -150, -150, -150, -150, -150, -110, -150, + -150, -93, -150, -22, -27, -33, -36, -39, -54, -59, + -81, -84, -97, -150, -65, -69, -150, -6, -139, -107, + -108, -111, -135, -90, -150, -19, -150, -150, -150, -150, + -150, -60, -150, -63, -67, -70, -150, -110, -101, -134, + -115, -150, -150, -94, -150, -23, -28, -150, -150, -150, + -61, -150, -66, -69, -134, -101, -74, -150, -150, -79, + -150, -109, -150, -112, -134, -119, -120, -121, -150, -118, + -91, -20, -34, -145, -147, -148, -37, -40, -69, -68, + -71, -72, -150, -150, -77, -150, -69, -101, -150, -126, + -130, -131, -132, -133, -60, -116, -146, -62, -150, -101, + -122, -150, -75, -150, -64, -150, -134, -150, -128, -113, + -150, -60, -150, -124, -150, -150, -78, -150, -60, -127, + -130, -134, -73, -150, -123, -134, -129, -114, -60, -125, + -76, -117 ] racc_goto_table = [ - 78, 76, 98, 54, 163, 122, 192, 71, 181, 113, - 121, 150, 43, 49, 215, 143, 82, 87, 88, 89, - 1, 209, 2, 74, 4, 86, 86, 86, 86, 42, - 93, 219, 5, 40, 221, 219, 219, 126, 166, 10, - 11, 142, 118, 78, 119, 94, 114, 96, 232, 121, - 189, 51, 113, 227, 55, 57, 58, 200, 204, 205, - 100, 74, 74, 132, 228, 220, 174, 107, 156, 121, - 108, 157, 223, 86, 86, 109, 113, 236, 158, 110, - 239, 159, 111, 78, 141, 118, 138, 242, 160, 70, - 75, 139, 116, 124, 207, 211, 231, 140, 130, 172, - 105, 154, 74, 149, 74, 196, 229, 118, 127, nil, - 86, nil, 86, nil, nil, nil, 169, nil, nil, nil, - nil, nil, nil, nil, nil, 191, nil, nil, 74, nil, - 184, nil, 86, nil, nil, nil, nil, 197, nil, nil, - 208, nil, nil, nil, nil, nil, nil, nil, 217, nil, - nil, nil, nil, 212, nil, 169, 216, nil, nil, nil, + 78, 181, 98, 54, 76, 71, 163, 194, 113, 218, + 150, 121, 122, 43, 143, 1, 226, 249, 2, 49, + 226, 226, 211, 74, 249, 86, 86, 86, 86, 231, + 82, 87, 88, 89, 55, 57, 58, 166, 202, 206, + 207, 4, 118, 78, 114, 42, 94, 119, 142, 191, + 121, 113, 247, 96, 93, 5, 40, 126, 238, 253, + 10, 74, 74, 11, 239, 51, 100, 132, 243, 227, + 121, 174, 107, 86, 86, 113, 156, 234, 108, 157, + 109, 252, 158, 78, 138, 118, 110, 141, 257, 159, + 111, 160, 70, 75, 139, 116, 124, 209, 261, 228, + 213, 245, 74, 140, 74, 130, 172, 118, 105, 154, + 86, 149, 86, 198, 240, 127, 169, nil, nil, nil, + nil, nil, nil, nil, nil, 193, nil, nil, 74, nil, + 184, nil, 86, nil, nil, nil, nil, 199, nil, nil, + 210, nil, nil, nil, nil, nil, nil, nil, nil, nil, + 224, nil, nil, 214, nil, nil, nil, 169, 220, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, 184, nil, nil, 216, nil, nil, nil, - nil, 233, nil, nil, nil, nil, nil, nil, nil, nil, - 216, 240, 234, 241 ] + nil, nil, nil, nil, nil, 184, nil, nil, 230, nil, + nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, 248, nil, nil, nil, nil, nil, nil, nil, + nil, 220, nil, 250, nil, nil, nil, 258, 220, nil, + 254, 260 ] racc_goto_check = [ - 44, 51, 45, 36, 40, 56, 46, 34, 41, 35, - 57, 61, 58, 10, 47, 39, 33, 33, 33, 33, - 1, 46, 2, 36, 3, 36, 36, 36, 36, 4, - 5, 65, 6, 7, 47, 65, 65, 8, 39, 9, - 11, 56, 44, 44, 51, 58, 34, 10, 47, 57, - 61, 12, 35, 46, 14, 14, 14, 22, 22, 22, - 13, 36, 36, 15, 41, 40, 16, 17, 18, 57, - 23, 24, 40, 36, 36, 25, 35, 41, 26, 27, - 41, 28, 29, 44, 51, 44, 34, 41, 30, 31, - 32, 37, 38, 42, 43, 48, 49, 50, 52, 53, - 54, 55, 36, 60, 36, 62, 63, 44, 64, nil, - 36, nil, 36, nil, nil, nil, 44, nil, nil, nil, + 44, 41, 45, 36, 51, 34, 40, 46, 35, 62, + 61, 57, 56, 58, 39, 1, 68, 65, 2, 10, + 68, 68, 46, 36, 65, 36, 36, 36, 36, 62, + 33, 33, 33, 33, 14, 14, 14, 39, 22, 22, + 22, 3, 44, 44, 34, 4, 58, 51, 56, 61, + 57, 35, 62, 10, 5, 6, 7, 8, 46, 62, + 9, 36, 36, 11, 41, 12, 13, 15, 46, 40, + 57, 16, 17, 36, 36, 35, 18, 40, 23, 24, + 25, 41, 26, 44, 34, 44, 27, 51, 41, 28, + 29, 30, 31, 32, 37, 38, 42, 43, 41, 47, + 48, 49, 36, 50, 36, 52, 53, 44, 54, 55, + 36, 60, 36, 63, 64, 67, 44, nil, nil, nil, nil, nil, nil, nil, nil, 45, nil, nil, 36, nil, 44, nil, 36, nil, nil, nil, nil, 44, nil, nil, - 45, nil, nil, nil, nil, nil, nil, nil, 45, nil, - nil, nil, nil, 44, nil, 44, 44, nil, nil, nil, + 45, nil, nil, nil, nil, nil, nil, nil, nil, nil, + 45, nil, nil, 44, nil, nil, nil, 44, 44, nil, + nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, nil, nil, nil, 44, nil, nil, 44, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, 44, nil, nil, 44, nil, nil, nil, - nil, 45, nil, nil, nil, nil, nil, nil, nil, nil, - 44, 45, 44, 45 ] + nil, nil, 45, nil, nil, nil, nil, nil, nil, nil, + nil, 44, nil, 44, nil, nil, nil, 45, 44, nil, + 44, 45 ] racc_goto_pointer = [ - nil, 20, 22, 22, 20, -12, 30, 27, -55, 35, - 3, 36, 38, 9, 40, -43, -89, 7, -65, nil, - nil, nil, -120, 9, -63, 13, -57, 16, -55, 18, - -49, 56, 56, -19, -26, -62, -10, -25, 18, -108, - -141, -153, 2, -89, -34, -44, -163, -176, -91, -126, - -19, -33, -6, -54, 44, -30, -79, -73, 3, nil, - -25, -117, -65, -112, 13, -169 ] + nil, 15, 18, 39, 36, 12, 53, 50, -35, 56, + 9, 59, 52, 15, 20, -39, -84, 12, -57, nil, + nil, nil, -139, 17, -55, 18, -53, 23, -47, 26, + -46, 59, 59, -5, -28, -63, -10, -22, 21, -109, + -139, -160, 5, -86, -34, -44, -162, -113, -86, -131, + -13, -30, 1, -47, 52, -22, -72, -72, 4, nil, + -17, -118, -183, -57, -111, -220, nil, 20, -186 ] racc_goto_default = [ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 45, nil, nil, nil, nil, nil, nil, nil, 22, 23, 24, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 73, 79, nil, nil, nil, - nil, nil, 46, 164, 202, nil, nil, nil, nil, nil, + nil, nil, 46, 164, 204, nil, nil, nil, nil, nil, 80, nil, nil, nil, nil, nil, 83, 85, nil, 44, - nil, nil, nil, nil, nil, 201 ] + nil, nil, nil, nil, nil, 219, 221, nil, 203 ] racc_reduce_table = [ 0, 0, :racc_error, - 5, 56, :_reduce_none, - 0, 57, :_reduce_none, - 2, 57, :_reduce_none, - 0, 62, :_reduce_4, - 0, 63, :_reduce_5, - 5, 61, :_reduce_6, + 5, 60, :_reduce_none, + 0, 61, :_reduce_none, 2, 61, :_reduce_none, - 0, 65, :_reduce_none, - 1, 65, :_reduce_none, - 0, 58, :_reduce_10, - 3, 58, :_reduce_none, - 1, 64, :_reduce_none, - 2, 64, :_reduce_13, - 3, 64, :_reduce_none, - 2, 64, :_reduce_none, - 2, 64, :_reduce_16, - 2, 64, :_reduce_17, - 0, 70, :_reduce_18, - 0, 71, :_reduce_19, - 7, 64, :_reduce_20, - 0, 72, :_reduce_21, - 0, 73, :_reduce_22, - 6, 64, :_reduce_23, - 1, 64, :_reduce_24, - 1, 64, :_reduce_25, - 0, 78, :_reduce_26, - 0, 79, :_reduce_27, - 6, 66, :_reduce_28, - 1, 66, :_reduce_none, - 1, 66, :_reduce_none, - 1, 66, :_reduce_none, - 0, 80, :_reduce_32, - 0, 81, :_reduce_33, - 7, 66, :_reduce_34, - 0, 82, :_reduce_35, - 0, 83, :_reduce_36, - 7, 66, :_reduce_37, - 0, 84, :_reduce_38, - 0, 85, :_reduce_39, - 7, 66, :_reduce_40, - 2, 66, :_reduce_41, - 2, 66, :_reduce_42, - 2, 66, :_reduce_43, - 2, 66, :_reduce_44, - 2, 66, :_reduce_45, - 2, 74, :_reduce_none, - 2, 74, :_reduce_47, - 2, 74, :_reduce_48, - 2, 74, :_reduce_49, - 2, 74, :_reduce_50, - 2, 74, :_reduce_51, - 1, 86, :_reduce_52, - 2, 86, :_reduce_53, - 3, 86, :_reduce_54, - 1, 89, :_reduce_55, - 2, 89, :_reduce_56, - 0, 93, :_reduce_none, - 1, 93, :_reduce_none, - 3, 90, :_reduce_59, - 0, 96, :_reduce_none, - 1, 96, :_reduce_none, - 8, 75, :_reduce_62, - 5, 76, :_reduce_63, - 8, 76, :_reduce_64, - 1, 94, :_reduce_65, - 3, 94, :_reduce_66, - 1, 95, :_reduce_67, - 3, 95, :_reduce_68, - 0, 98, :_reduce_69, - 1, 98, :_reduce_70, - 3, 98, :_reduce_71, - 3, 98, :_reduce_72, - 6, 98, :_reduce_73, - 0, 103, :_reduce_74, - 0, 104, :_reduce_75, - 7, 98, :_reduce_76, - 3, 98, :_reduce_77, - 0, 92, :_reduce_none, - 1, 92, :_reduce_79, - 1, 87, :_reduce_80, - 2, 87, :_reduce_81, - 3, 87, :_reduce_82, - 1, 106, :_reduce_83, - 2, 106, :_reduce_84, - 1, 99, :_reduce_none, - 1, 99, :_reduce_none, - 0, 107, :_reduce_87, - 0, 108, :_reduce_88, - 6, 69, :_reduce_89, - 0, 109, :_reduce_90, - 0, 110, :_reduce_91, - 5, 69, :_reduce_92, - 1, 88, :_reduce_93, - 2, 88, :_reduce_94, - 3, 88, :_reduce_95, - 1, 111, :_reduce_96, - 2, 111, :_reduce_97, - 1, 112, :_reduce_none, - 1, 91, :_reduce_99, - 1, 91, :_reduce_100, - 1, 59, :_reduce_none, - 2, 59, :_reduce_none, - 2, 113, :_reduce_none, - 2, 113, :_reduce_none, - 4, 114, :_reduce_105, - 1, 115, :_reduce_106, - 3, 115, :_reduce_107, - 0, 116, :_reduce_108, - 1, 116, :_reduce_109, - 3, 116, :_reduce_110, - 5, 116, :_reduce_111, - 7, 116, :_reduce_112, - 0, 117, :_reduce_113, - 0, 118, :_reduce_114, - 8, 116, :_reduce_115, - 3, 116, :_reduce_116, - 1, 101, :_reduce_117, - 1, 101, :_reduce_118, - 1, 101, :_reduce_119, - 1, 102, :_reduce_120, - 3, 102, :_reduce_121, - 2, 102, :_reduce_122, - 4, 102, :_reduce_123, - 0, 100, :_reduce_none, - 3, 100, :_reduce_125, - 1, 97, :_reduce_none, - 0, 60, :_reduce_none, - 0, 119, :_reduce_128, - 3, 60, :_reduce_129, - 1, 67, :_reduce_none, - 0, 68, :_reduce_none, - 1, 68, :_reduce_none, + 0, 66, :_reduce_4, + 0, 67, :_reduce_5, + 5, 65, :_reduce_6, + 2, 65, :_reduce_none, + 0, 69, :_reduce_none, + 1, 69, :_reduce_none, + 0, 62, :_reduce_10, + 3, 62, :_reduce_none, 1, 68, :_reduce_none, - 1, 68, :_reduce_none, - 1, 77, :_reduce_135, - 2, 77, :_reduce_136, - 1, 120, :_reduce_none, - 1, 120, :_reduce_none, - 1, 105, :_reduce_139 ] - -racc_reduce_n = 140 - -racc_shift_n = 243 + 2, 68, :_reduce_13, + 3, 68, :_reduce_none, + 2, 68, :_reduce_none, + 2, 68, :_reduce_16, + 2, 68, :_reduce_17, + 0, 74, :_reduce_18, + 0, 75, :_reduce_19, + 7, 68, :_reduce_20, + 0, 76, :_reduce_21, + 0, 77, :_reduce_22, + 6, 68, :_reduce_23, + 1, 68, :_reduce_24, + 1, 68, :_reduce_25, + 0, 82, :_reduce_26, + 0, 83, :_reduce_27, + 6, 70, :_reduce_28, + 1, 70, :_reduce_none, + 1, 70, :_reduce_none, + 1, 70, :_reduce_none, + 0, 84, :_reduce_32, + 0, 85, :_reduce_33, + 7, 70, :_reduce_34, + 0, 86, :_reduce_35, + 0, 87, :_reduce_36, + 7, 70, :_reduce_37, + 0, 88, :_reduce_38, + 0, 89, :_reduce_39, + 7, 70, :_reduce_40, + 2, 70, :_reduce_41, + 2, 70, :_reduce_42, + 2, 70, :_reduce_43, + 2, 70, :_reduce_44, + 2, 70, :_reduce_45, + 2, 78, :_reduce_none, + 2, 78, :_reduce_47, + 2, 78, :_reduce_48, + 2, 78, :_reduce_49, + 2, 78, :_reduce_50, + 2, 78, :_reduce_51, + 1, 90, :_reduce_52, + 2, 90, :_reduce_53, + 3, 90, :_reduce_54, + 1, 93, :_reduce_55, + 2, 93, :_reduce_56, + 0, 97, :_reduce_none, + 1, 97, :_reduce_none, + 3, 94, :_reduce_59, + 0, 100, :_reduce_none, + 1, 100, :_reduce_none, + 8, 79, :_reduce_62, + 5, 80, :_reduce_63, + 8, 80, :_reduce_64, + 1, 98, :_reduce_65, + 3, 98, :_reduce_66, + 1, 99, :_reduce_67, + 3, 99, :_reduce_68, + 0, 102, :_reduce_69, + 1, 102, :_reduce_70, + 3, 102, :_reduce_71, + 3, 102, :_reduce_72, + 6, 102, :_reduce_73, + 0, 107, :_reduce_74, + 0, 108, :_reduce_75, + 7, 102, :_reduce_76, + 3, 102, :_reduce_77, + 5, 102, :_reduce_78, + 2, 102, :_reduce_79, + 0, 96, :_reduce_none, + 1, 96, :_reduce_81, + 1, 91, :_reduce_82, + 2, 91, :_reduce_83, + 3, 91, :_reduce_84, + 1, 110, :_reduce_85, + 2, 110, :_reduce_86, + 1, 103, :_reduce_none, + 1, 103, :_reduce_none, + 0, 111, :_reduce_89, + 0, 112, :_reduce_90, + 6, 73, :_reduce_91, + 0, 113, :_reduce_92, + 0, 114, :_reduce_93, + 5, 73, :_reduce_94, + 1, 92, :_reduce_95, + 2, 92, :_reduce_96, + 3, 92, :_reduce_97, + 1, 115, :_reduce_98, + 2, 115, :_reduce_99, + 1, 116, :_reduce_none, + 1, 95, :_reduce_101, + 1, 95, :_reduce_102, + 1, 63, :_reduce_none, + 2, 63, :_reduce_none, + 2, 117, :_reduce_none, + 2, 117, :_reduce_none, + 4, 118, :_reduce_107, + 1, 119, :_reduce_108, + 3, 119, :_reduce_109, + 0, 120, :_reduce_110, + 1, 120, :_reduce_111, + 3, 120, :_reduce_112, + 5, 120, :_reduce_113, + 7, 120, :_reduce_114, + 0, 122, :_reduce_115, + 0, 123, :_reduce_116, + 8, 120, :_reduce_117, + 3, 120, :_reduce_118, + 1, 105, :_reduce_119, + 1, 105, :_reduce_120, + 1, 105, :_reduce_121, + 1, 106, :_reduce_122, + 3, 106, :_reduce_123, + 2, 106, :_reduce_124, + 4, 106, :_reduce_125, + 1, 121, :_reduce_126, + 3, 121, :_reduce_127, + 2, 121, :_reduce_128, + 4, 121, :_reduce_129, + 1, 124, :_reduce_none, + 1, 124, :_reduce_none, + 1, 125, :_reduce_132, + 1, 125, :_reduce_133, + 0, 104, :_reduce_none, + 3, 104, :_reduce_135, + 1, 101, :_reduce_none, + 0, 64, :_reduce_none, + 0, 126, :_reduce_138, + 3, 64, :_reduce_139, + 1, 71, :_reduce_none, + 0, 72, :_reduce_none, + 1, 72, :_reduce_none, + 1, 72, :_reduce_none, + 1, 72, :_reduce_none, + 1, 81, :_reduce_145, + 2, 81, :_reduce_146, + 1, 127, :_reduce_none, + 1, 127, :_reduce_none, + 1, 109, :_reduce_149 ] + +racc_reduce_n = 150 + +racc_shift_n = 262 racc_token_table = { false => 0, @@ -1103,14 +1129,18 @@ def raise_parse_error(error_message, location) "|" => 46, "%empty" => 47, "%prec" => 48, - "?" => 49, - "+" => 50, - "*" => 51, - "[" => 52, - "]" => 53, - "{...}" => 54 } - -racc_nt_base = 55 + "%if" => 49, + "%endif" => 50, + "?" => 51, + "+" => 52, + "*" => 53, + "%true" => 54, + "%false" => 55, + "[" => 56, + "]" => 57, + "{...}" => 58 } + +racc_nt_base = 59 racc_use_result_var = true @@ -1181,9 +1211,13 @@ def raise_parse_error(error_message, location) "\"|\"", "\"%empty\"", "\"%prec\"", + "\"%if\"", + "\"%endif\"", "\"?\"", "\"+\"", "\"*\"", + "\"%true\"", + "\"%false\"", "\"[\"", "\"]\"", "\"{...}\"", @@ -1234,7 +1268,7 @@ def raise_parse_error(error_message, location) "symbol", "named_ref_opt", "parameterizing_suffix", - "parameterizing_args", + "parameterizing_rule_args", "@15", "@16", "string_as_id", @@ -1249,8 +1283,11 @@ def raise_parse_error(error_message, location) "rules", "rhs_list", "rhs", + "parameterizing_args", "@21", "@22", + "symbol_or_bool", + "bool", "@23", "generic_symlist_item" ] Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor) @@ -1701,12 +1738,13 @@ def _reduce_62(val, _values, result) def _reduce_63(val, _values, result) rule = Grammar::ParameterizingRule::Rule.new(val[2].s_value, [], val[4], is_inline: true) @grammar.add_parameterizing_rule(rule) + @grammar.initialize_if_count result end .,., -module_eval(<<'.,.,', 'parser.y', 248) +module_eval(<<'.,.,', 'parser.y', 249) def _reduce_64(val, _values, result) rule = Grammar::ParameterizingRule::Rule.new(val[2].s_value, val[4], val[7], is_inline: true) @grammar.add_parameterizing_rule(rule) @@ -1715,21 +1753,21 @@ def _reduce_64(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 252) +module_eval(<<'.,.,', 'parser.y', 253) def _reduce_65(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 253) +module_eval(<<'.,.,', 'parser.y', 254) def _reduce_66(val, _values, result) result = val[0].append(val[2]) result end .,., -module_eval(<<'.,.,', 'parser.y', 257) +module_eval(<<'.,.,', 'parser.y', 258) def _reduce_67(val, _values, result) builder = val[0] result = [builder] @@ -1738,7 +1776,7 @@ def _reduce_67(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 262) +module_eval(<<'.,.,', 'parser.y', 263) def _reduce_68(val, _values, result) builder = val[2] result = val[0].append(builder) @@ -1747,7 +1785,7 @@ def _reduce_68(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 268) +module_eval(<<'.,.,', 'parser.y', 269) def _reduce_69(val, _values, result) reset_precs result = Grammar::ParameterizingRule::Rhs.new @@ -1756,7 +1794,7 @@ def _reduce_69(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 273) +module_eval(<<'.,.,', 'parser.y', 274) def _reduce_70(val, _values, result) reset_precs result = Grammar::ParameterizingRule::Rhs.new @@ -1765,7 +1803,7 @@ def _reduce_70(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 278) +module_eval(<<'.,.,', 'parser.y', 279) def _reduce_71(val, _values, result) token = val[1] token.alias_name = val[2] @@ -1777,7 +1815,7 @@ def _reduce_71(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 286) +module_eval(<<'.,.,', 'parser.y', 287) def _reduce_72(val, _values, result) builder = val[0] builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]]) @@ -1787,7 +1825,7 @@ def _reduce_72(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 292) +module_eval(<<'.,.,', 'parser.y', 293) def _reduce_73(val, _values, result) builder = val[0] builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[5]) @@ -1797,7 +1835,7 @@ def _reduce_73(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 298) +module_eval(<<'.,.,', 'parser.y', 299) def _reduce_74(val, _values, result) if @prec_seen on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec @@ -1809,7 +1847,7 @@ def _reduce_74(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 306) +module_eval(<<'.,.,', 'parser.y', 307) def _reduce_75(val, _values, result) end_c_declaration @@ -1817,7 +1855,7 @@ def _reduce_75(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 310) +module_eval(<<'.,.,', 'parser.y', 311) def _reduce_76(val, _values, result) user_code = val[3] user_code.alias_name = val[6] @@ -1829,7 +1867,7 @@ def _reduce_76(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 318) +module_eval(<<'.,.,', 'parser.y', 319) def _reduce_77(val, _values, result) sym = @grammar.find_symbol_by_id!(val[2]) @prec_seen = true @@ -1841,169 +1879,192 @@ def _reduce_77(val, _values, result) end .,., -# reduce 78 omitted +module_eval(<<'.,.,', 'parser.y', 327) + def _reduce_78(val, _values, result) + builder = val[0] + builder.symbols << Lrama::Lexer::Token::ControlSyntax.new(s_value: val[1], location: @lexer.location, condition: val[3]) + @grammar.if_count += 1 + result = builder + + result + end +.,., -module_eval(<<'.,.,', 'parser.y', 326) +module_eval(<<'.,.,', 'parser.y', 334) def _reduce_79(val, _values, result) + on_action_error("no %if before %endif", val[0]) if @grammar.if_count == 0 + builder = val[0] + builder.symbols << Lrama::Lexer::Token::ControlSyntax.new(s_value: val[1], location: @lexer.location) + @grammar.if_count -= 1 + result = builder + + result + end +.,., + +# reduce 80 omitted + +module_eval(<<'.,.,', 'parser.y', 342) + def _reduce_81(val, _values, result) result = val[0].s_value result end .,., -module_eval(<<'.,.,', 'parser.y', 330) - def _reduce_80(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 346) + def _reduce_82(val, _values, result) result = [{tag: nil, tokens: val[0]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 334) - def _reduce_81(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 350) + def _reduce_83(val, _values, result) result = [{tag: val[0], tokens: val[1]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 338) - def _reduce_82(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 354) + def _reduce_84(val, _values, result) result = val[0].append({tag: val[1], tokens: val[2]}) result end .,., -module_eval(<<'.,.,', 'parser.y', 341) - def _reduce_83(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 357) + def _reduce_85(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 342) - def _reduce_84(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 358) + def _reduce_86(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 85 omitted +# reduce 87 omitted -# reduce 86 omitted +# reduce 88 omitted -module_eval(<<'.,.,', 'parser.y', 349) - def _reduce_87(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 365) + def _reduce_89(val, _values, result) begin_c_declaration("}") result end .,., -module_eval(<<'.,.,', 'parser.y', 353) - def _reduce_88(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 369) + def _reduce_90(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 357) - def _reduce_89(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 373) + def _reduce_91(val, _values, result) result = val[0].append(val[3]) result end .,., -module_eval(<<'.,.,', 'parser.y', 361) - def _reduce_90(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 377) + def _reduce_92(val, _values, result) begin_c_declaration("}") result end .,., -module_eval(<<'.,.,', 'parser.y', 365) - def _reduce_91(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 381) + def _reduce_93(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 369) - def _reduce_92(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 385) + def _reduce_94(val, _values, result) result = [val[2]] result end .,., -module_eval(<<'.,.,', 'parser.y', 374) - def _reduce_93(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 390) + def _reduce_95(val, _values, result) result = [{tag: nil, tokens: val[0]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 378) - def _reduce_94(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 394) + def _reduce_96(val, _values, result) result = [{tag: val[0], tokens: val[1]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 382) - def _reduce_95(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 398) + def _reduce_97(val, _values, result) result = val[0].append({tag: val[1], tokens: val[2]}) result end .,., -module_eval(<<'.,.,', 'parser.y', 385) - def _reduce_96(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 401) + def _reduce_98(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 386) - def _reduce_97(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 402) + def _reduce_99(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 98 omitted +# reduce 100 omitted -module_eval(<<'.,.,', 'parser.y', 390) - def _reduce_99(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 406) + def _reduce_101(val, _values, result) on_action_error("ident after %prec", val[0]) if @prec_seen result end .,., -module_eval(<<'.,.,', 'parser.y', 391) - def _reduce_100(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 407) + def _reduce_102(val, _values, result) on_action_error("char after %prec", val[0]) if @prec_seen result end .,., -# reduce 101 omitted - -# reduce 102 omitted - # reduce 103 omitted # reduce 104 omitted -module_eval(<<'.,.,', 'parser.y', 401) - def _reduce_105(val, _values, result) +# reduce 105 omitted + +# reduce 106 omitted + +module_eval(<<'.,.,', 'parser.y', 417) + def _reduce_107(val, _values, result) lhs = val[0] lhs.alias_name = val[1] val[3].each do |builder| @@ -2016,8 +2077,8 @@ def _reduce_105(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 412) - def _reduce_106(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 428) + def _reduce_108(val, _values, result) builder = val[0] if !builder.line builder.line = @lexer.line - 1 @@ -2028,8 +2089,8 @@ def _reduce_106(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 420) - def _reduce_107(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 436) + def _reduce_109(val, _values, result) builder = val[2] if !builder.line builder.line = @lexer.line - 1 @@ -2040,8 +2101,8 @@ def _reduce_107(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 429) - def _reduce_108(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 445) + def _reduce_110(val, _values, result) reset_precs result = @grammar.create_rule_builder(@rule_counter, @midrule_action_counter) @@ -2049,8 +2110,8 @@ def _reduce_108(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 434) - def _reduce_109(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 450) + def _reduce_111(val, _values, result) reset_precs result = @grammar.create_rule_builder(@rule_counter, @midrule_action_counter) @@ -2058,8 +2119,8 @@ def _reduce_109(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 439) - def _reduce_110(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 455) + def _reduce_112(val, _values, result) token = val[1] token.alias_name = val[2] builder = val[0] @@ -2070,8 +2131,8 @@ def _reduce_110(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 447) - def _reduce_111(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 463) + def _reduce_113(val, _values, result) token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], alias_name: val[3], location: @lexer.location, args: [val[1]], lhs_tag: val[4]) builder = val[0] builder.add_rhs(token) @@ -2082,8 +2143,8 @@ def _reduce_111(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 455) - def _reduce_112(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 471) + def _reduce_114(val, _values, result) token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, alias_name: val[5], location: @lexer.location, args: val[3], lhs_tag: val[6]) builder = val[0] builder.add_rhs(token) @@ -2094,8 +2155,8 @@ def _reduce_112(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 463) - def _reduce_113(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 479) + def _reduce_115(val, _values, result) if @prec_seen on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec @code_after_prec = true @@ -2106,16 +2167,16 @@ def _reduce_113(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 471) - def _reduce_114(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 487) + def _reduce_116(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 475) - def _reduce_115(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 491) + def _reduce_117(val, _values, result) user_code = val[3] user_code.alias_name = val[6] user_code.tag = val[7] @@ -2127,8 +2188,8 @@ def _reduce_115(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 484) - def _reduce_116(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 500) + def _reduce_118(val, _values, result) sym = @grammar.find_symbol_by_id!(val[2]) @prec_seen = true builder = val[0] @@ -2139,70 +2200,116 @@ def _reduce_116(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 491) - def _reduce_117(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 507) + def _reduce_119(val, _values, result) result = "option" result end .,., -module_eval(<<'.,.,', 'parser.y', 492) - def _reduce_118(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 508) + def _reduce_120(val, _values, result) result = "nonempty_list" result end .,., -module_eval(<<'.,.,', 'parser.y', 493) - def _reduce_119(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 509) + def _reduce_121(val, _values, result) result = "list" result end .,., -module_eval(<<'.,.,', 'parser.y', 495) - def _reduce_120(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 511) + def _reduce_122(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 496) - def _reduce_121(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 512) + def _reduce_123(val, _values, result) result = val[0].append(val[2]) result end .,., -module_eval(<<'.,.,', 'parser.y', 497) - def _reduce_122(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 513) + def _reduce_124(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] result end .,., -module_eval(<<'.,.,', 'parser.y', 498) - def _reduce_123(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 514) + def _reduce_125(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] result end .,., -# reduce 124 omitted +module_eval(<<'.,.,', 'parser.y', 516) + def _reduce_126(val, _values, result) + result = [val[0]] + result + end +.,., -module_eval(<<'.,.,', 'parser.y', 501) - def _reduce_125(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 517) + def _reduce_127(val, _values, result) + result = val[0].append(val[2]) + result + end +.,., + +module_eval(<<'.,.,', 'parser.y', 518) + def _reduce_128(val, _values, result) + result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] + result + end +.,., + +module_eval(<<'.,.,', 'parser.y', 519) + def _reduce_129(val, _values, result) + result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] + result + end +.,., + +# reduce 130 omitted + +# reduce 131 omitted + +module_eval(<<'.,.,', 'parser.y', 524) + def _reduce_132(val, _values, result) + result = Lrama::Lexer::Token::Ident.new(s_value: true) + result + end +.,., + +module_eval(<<'.,.,', 'parser.y', 525) + def _reduce_133(val, _values, result) + result = Lrama::Lexer::Token::Ident.new(s_value: false) + result + end +.,., + +# reduce 134 omitted + +module_eval(<<'.,.,', 'parser.y', 528) + def _reduce_135(val, _values, result) result = val[1].s_value result end .,., -# reduce 126 omitted +# reduce 136 omitted -# reduce 127 omitted +# reduce 137 omitted -module_eval(<<'.,.,', 'parser.y', 508) - def _reduce_128(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 535) + def _reduce_138(val, _values, result) begin_c_declaration('\Z') @grammar.epilogue_first_lineno = @lexer.line + 1 @@ -2210,8 +2317,8 @@ def _reduce_128(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 513) - def _reduce_129(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 540) + def _reduce_139(val, _values, result) end_c_declaration @grammar.epilogue = val[2].s_value @@ -2219,36 +2326,36 @@ def _reduce_129(val, _values, result) end .,., -# reduce 130 omitted +# reduce 140 omitted -# reduce 131 omitted +# reduce 141 omitted -# reduce 132 omitted +# reduce 142 omitted -# reduce 133 omitted +# reduce 143 omitted -# reduce 134 omitted +# reduce 144 omitted -module_eval(<<'.,.,', 'parser.y', 524) - def _reduce_135(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 551) + def _reduce_145(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 525) - def _reduce_136(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 552) + def _reduce_146(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 137 omitted +# reduce 147 omitted -# reduce 138 omitted +# reduce 148 omitted -module_eval(<<'.,.,', 'parser.y', 530) - def _reduce_139(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 557) + def _reduce_149(val, _values, result) result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) result end diff --git a/parser.y b/parser.y index a6cf19d2..63abaf1b 100644 --- a/parser.y +++ b/parser.y @@ -243,6 +243,7 @@ rule { rule = Grammar::ParameterizingRule::Rule.new(val[2].s_value, [], val[4], is_inline: true) @grammar.add_parameterizing_rule(rule) + @grammar.initialize_if_count } | "%rule" "%inline" IDENTIFIER "(" rule_args ")" ":" rule_rhs_list { @@ -288,7 +289,7 @@ rule builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]]) result = builder } - | rule_rhs IDENTIFIER "(" parameterizing_args ")" TAG? + | rule_rhs IDENTIFIER "(" parameterizing_rule_args ")" TAG? { builder = val[0] 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 builder.precedence_sym = sym result = builder } + | rule_rhs "%if" "(" IDENTIFIER ")" + { + builder = val[0] + builder.symbols << Lrama::Lexer::Token::ControlSyntax.new(s_value: val[1], location: @lexer.location, condition: val[3]) + @grammar.if_count += 1 + result = builder + } + | rule_rhs "%endif" + { + on_action_error("no %if before %endif", val[0]) if @grammar.if_count == 0 + builder = val[0] + builder.symbols << Lrama::Lexer::Token::ControlSyntax.new(s_value: val[1], location: @lexer.location) + @grammar.if_count -= 1 + result = builder + } alias: # empty | string_as_id { result = val[0].s_value } @@ -493,11 +509,22 @@ rule | "+" { result = "nonempty_list" } | "*" { result = "list" } - parameterizing_args: symbol { result = [val[0]] } - | parameterizing_args ',' symbol { result = val[0].append(val[2]) } + parameterizing_rule_args: symbol { result = [val[0]] } + | parameterizing_args ',' symbol { result = val[0].append(val[2]) } + | symbol parameterizing_suffix { result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] } + | IDENTIFIER "(" parameterizing_args ")" { result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] } + + parameterizing_args: symbol_or_bool { result = [val[0]] } + | parameterizing_args ',' symbol_or_bool { result = val[0].append(val[2]) } | symbol parameterizing_suffix { result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] } | IDENTIFIER "(" parameterizing_args ")" { result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] } + symbol_or_bool: symbol + | bool + + bool: "%true" { result = Lrama::Lexer::Token::Ident.new(s_value: true) } + | "%false" { result = Lrama::Lexer::Token::Ident.new(s_value: false) } + named_ref_opt: # empty | '[' IDENTIFIER ']' { result = val[1].s_value } diff --git a/sig/lrama/grammar/parameterizing_rule/rhs.rbs b/sig/lrama/grammar/parameterizing_rule/rhs.rbs index 844557c9..4d4c1342 100644 --- a/sig/lrama/grammar/parameterizing_rule/rhs.rbs +++ b/sig/lrama/grammar/parameterizing_rule/rhs.rbs @@ -7,6 +7,8 @@ module Lrama attr_reader precedence_sym: Grammar::Symbol? def initialize: () -> void + def skip?: (Grammar::Binding bindings) -> bool + def resolve_symbols: (Grammar::Binding bindings) -> Array[untyped] def resolve_user_code: (Grammar::Binding bindings) -> Lexer::Token::UserCode? end end diff --git a/sig/lrama/lexer/token/control_syntax.rbs b/sig/lrama/lexer/token/control_syntax.rbs new file mode 100644 index 00000000..9701c685 --- /dev/null +++ b/sig/lrama/lexer/token/control_syntax.rbs @@ -0,0 +1,16 @@ +module Lrama + class Lexer + class Token + class ControlSyntax < Token + attr_accessor condition: Lexer::Token::Ident? + + def initialize: (s_value: String, location: Location, ?condition: Lexer::Token::Ident?) -> void + def if?: () -> bool + def endif?: () -> bool + def true?: () -> bool + def false?: () -> bool + def condition_value: () -> String? + end + end + end +end diff --git a/spec/fixtures/parameterizing_rules/user_defined/if.y b/spec/fixtures/parameterizing_rules/user_defined/if.y new file mode 100644 index 00000000..97c6de2a --- /dev/null +++ b/spec/fixtures/parameterizing_rules/user_defined/if.y @@ -0,0 +1,44 @@ +/* + * This is comment for this file. + */ + +%{ +// Prologue +static int yylex(YYSTYPE *val, YYLTYPE *loc); +static int yyerror(YYLTYPE *loc, const char *str); +%} + +%union { + int i; +} + +%token number + +%rule defined_rule(X, condition): /* empty */ + | X { $$ = $1; } %if(condition) + | %if(condition) X %endif X { $$ = $1; } + ; + +%% + +r_true : defined_rule(number, %true) + ; + +r_false : defined_rule(number, %false) + ; + +%% + +static int yylex(YYSTYPE *yylval, YYLTYPE *loc) +{ + return 0; +} + +static int yyerror(YYLTYPE *loc, const char *str) +{ + return 0; +} + +int main(int argc, char *argv[]) +{ +} diff --git a/spec/lrama/parser_spec.rb b/spec/lrama/parser_spec.rb index 8b14ee5f..c6135a6a 100644 --- a/spec/lrama/parser_spec.rb +++ b/spec/lrama/parser_spec.rb @@ -2334,6 +2334,109 @@ ]) end end + + context "when if" do + let(:path) { "parameterizing_rules/user_defined/if.y" } + + it "expands parameterizing rules" do + expect(grammar.nterms.sort_by(&:number)).to match_symbols([ + Sym.new(id: T::Ident.new(s_value: "$accept"), alias_name: nil, number: 4, tag: nil, term: false, token_id: 0, nullable: false), + Sym.new(id: T::Ident.new(s_value: "defined_rule_number_true"), alias_name: nil, number: 5, tag: nil, term: false, token_id: 1, nullable: true), + Sym.new(id: T::Ident.new(s_value: "r_true"), alias_name: nil, number: 6, tag: nil, term: false, token_id: 2, nullable: true), + Sym.new(id: T::Ident.new(s_value: "defined_rule_number_false"), alias_name: nil, number: 7, tag: nil, term: false, token_id: 3, nullable: true), + Sym.new(id: T::Ident.new(s_value: "r_false"), alias_name: nil, number: 8, tag: nil, term: false, token_id: 4, nullable: true), + ]) + + expect(grammar.rules).to eq([ + Rule.new( + id: 0, + lhs: grammar.find_symbol_by_s_value!("$accept"), + rhs: [ + grammar.find_symbol_by_s_value!("r_true"), + grammar.find_symbol_by_s_value!("YYEOF"), + ], + token_code: nil, + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"), + lineno: 24, + ), + Rule.new( + id: 1, + lhs: grammar.find_symbol_by_s_value!("defined_rule_number_true"), + rhs: [], + token_code: nil, + nullable: true, + precedence_sym: nil, + lineno: 24, + ), + Rule.new( + id: 2, + lhs: grammar.find_symbol_by_s_value!("defined_rule_number_true"), + rhs: [ + grammar.find_symbol_by_s_value!("number"), + ], + token_code: T::UserCode.new(s_value: " $$ = $1; "), + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("number"), + lineno: 24, + ), + Rule.new( + id: 3, + lhs: grammar.find_symbol_by_s_value!("defined_rule_number_true"), + rhs: [ + grammar.find_symbol_by_s_value!("number"), + grammar.find_symbol_by_s_value!("number"), + ], + token_code: T::UserCode.new(s_value: " $$ = $1; "), + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("number"), + lineno: 24, + ), + Rule.new( + id: 4, + lhs: grammar.find_symbol_by_s_value!("r_true"), + rhs: [ + grammar.find_symbol_by_s_value!("defined_rule_number_true"), + ], + token_code: nil, + nullable: true, + precedence_sym: nil, + lineno: 24, + ), + Rule.new( + id: 5, + lhs: grammar.find_symbol_by_s_value!("defined_rule_number_false"), + rhs: [], + token_code: nil, + nullable: true, + precedence_sym: nil, + lineno: 27, + ), + Rule.new( + id: 6, + lhs: grammar.find_symbol_by_s_value!("defined_rule_number_false"), + rhs: [ + grammar.find_symbol_by_s_value!("number"), + ], + token_code: T::UserCode.new(s_value: " $$ = $1; "), + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("number"), + lineno: 27, + ), + Rule.new( + id: 7, + lhs: grammar.find_symbol_by_s_value!("r_false"), + rhs: [ + grammar.find_symbol_by_s_value!("defined_rule_number_false"), + ], + token_code: nil, + nullable: true, + precedence_sym: nil, + lineno: 27, + ), + ]) + end + end end context 'when error case' do From ba35a95497024096b496aa514b57c2bb1fab8788 Mon Sep 17 00:00:00 2001 From: ydah Date: Sun, 9 Jun 2024 13:58:18 +0900 Subject: [PATCH 2/5] Change only support for postfix if format ``` %rule defined_rule(X, condition): X { $$ = $1; } %if(condition) ; ``` --- lib/lrama/grammar.rb | 6 +- lib/lrama/grammar/parameterizing_rule/rhs.rb | 19 - lib/lrama/grammar/rule_builder.rb | 6 +- lib/lrama/lexer.rb | 1 - lib/lrama/lexer/token.rb | 1 + lib/lrama/lexer/token/control_syntax.rb | 4 - lib/lrama/parser.rb | 909 +++++++++--------- parser.y | 10 - sig/lrama/grammar/parameterizing_rule/rhs.rbs | 1 - sig/lrama/lexer/token/control_syntax.rbs | 1 - .../parameterizing_rules/user_defined/if.y | 1 - spec/lrama/parser_spec.rb | 41 +- 12 files changed, 460 insertions(+), 540 deletions(-) diff --git a/lib/lrama/grammar.rb b/lib/lrama/grammar.rb index 36cb5fb1..9478977f 100644 --- a/lib/lrama/grammar.rb +++ b/lib/lrama/grammar.rb @@ -28,7 +28,7 @@ class Grammar attr_reader :percent_codes, :eof_symbol, :error_symbol, :undef_symbol, :accept_symbol, :aux, :parameterizing_rule_resolver attr_accessor :union, :expect, :printers, :error_tokens, :lex_param, :parse_param, :initial_action, :after_shift, :before_reduce, :after_reduce, :after_shift_error_token, :after_pop_stack, - :symbols_resolver, :types, :rules, :rule_builders, :sym_to_rules, :no_stdlib, :locations, :if_count + :symbols_resolver, :types, :rules, :rule_builders, :sym_to_rules, :no_stdlib, :locations def_delegators "@symbols_resolver", :symbols, :nterms, :terms, :add_nterm, :add_term, :find_symbol_by_number!, :find_symbol_by_id!, :token_to_symbol, @@ -172,10 +172,6 @@ def find_rules_by_symbol(sym) @sym_to_rules[sym.number] end - def initialize_if_count - @if_count = 0 - end - private def compute_nullable diff --git a/lib/lrama/grammar/parameterizing_rule/rhs.rb b/lib/lrama/grammar/parameterizing_rule/rhs.rb index c35ceb89..b1b4a83d 100644 --- a/lib/lrama/grammar/parameterizing_rule/rhs.rb +++ b/lib/lrama/grammar/parameterizing_rule/rhs.rb @@ -18,25 +18,6 @@ def skip?(bindings) last_sym.is_a?(Lexer::Token::ControlSyntax) && last_sym.if? && last_sym.false? end - def resolve_symbols(bindings) - is_skip = [] - @symbols.map do |sym| - resolved = bindings.resolve_symbol(sym) - if resolved.is_a?(Lexer::Token::ControlSyntax) - if resolved.if? - is_skip.push(resolved.false?) - elsif resolved.endif? - is_skip.pop - else - raise "Unexpected control syntax: #{resolved.condition_value}" - end - nil - else - resolved unless is_skip.last - end - end.compact - end - def resolve_user_code(bindings) return unless user_code diff --git a/lib/lrama/grammar/rule_builder.rb b/lib/lrama/grammar/rule_builder.rb index 998fc57e..347f22fe 100644 --- a/lib/lrama/grammar/rule_builder.rb +++ b/lib/lrama/grammar/rule_builder.rb @@ -152,9 +152,7 @@ def process_rhs rule_builder = RuleBuilder.new(@rule_counter, @midrule_action_counter, @parameterizing_rule_resolver, lhs_tag: token.lhs_tag || parameterizing_rule.tag) rule_builder.lhs = lhs_token next if r.skip?(bindings) - r.resolve_symbols(bindings).each do |sym| - rule_builder.add_rhs(sym) - end + r.symbols.each { |sym| rule_builder.add_rhs(bindings.resolve_symbol(sym)) } rule_builder.line = line rule_builder.precedence_sym = r.precedence_sym rule_builder.user_code = r.resolve_user_code(bindings) @@ -176,6 +174,8 @@ def process_rhs rule_builder.setup_rules @rule_builders_for_derived_rules << rule_builder + when Lrama::Lexer::Token::ControlSyntax + # NOP else raise "Unexpected token. #{token}" end diff --git a/lib/lrama/lexer.rb b/lib/lrama/lexer.rb index 4b0b32dd..42a6e03d 100644 --- a/lib/lrama/lexer.rb +++ b/lib/lrama/lexer.rb @@ -42,7 +42,6 @@ class Lexer %inline %locations %if - %endif %true %false ) diff --git a/lib/lrama/lexer/token.rb b/lib/lrama/lexer/token.rb index 45a097f6..ed78ec62 100644 --- a/lib/lrama/lexer/token.rb +++ b/lib/lrama/lexer/token.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require_relative 'token/char' +require_relative 'token/control_syntax' require_relative 'token/ident' require_relative 'token/instantiate_rule' require_relative 'token/tag' diff --git a/lib/lrama/lexer/token/control_syntax.rb b/lib/lrama/lexer/token/control_syntax.rb index 9a89368c..16ff6c3a 100644 --- a/lib/lrama/lexer/token/control_syntax.rb +++ b/lib/lrama/lexer/token/control_syntax.rb @@ -13,10 +13,6 @@ def if? s_value == '%if' end - def endif? - s_value == '%endif' - end - def true? !!@condition&.s_value end diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index 6fd91ab1..ecfb8e0e 100644 --- a/lib/lrama/parser.rb +++ b/lib/lrama/parser.rb @@ -654,7 +654,7 @@ def token_to_str(t) module Lrama class Parser < Racc::Parser -module_eval(<<'...end parser.y/module_eval...', 'parser.y', 562) +module_eval(<<'...end parser.y/module_eval...', 'parser.y', 552) include Lrama::Report::Duration @@ -728,356 +728,355 @@ def raise_parse_error(error_message, location) ##### State transition tables begin ### racc_action_table = [ - 101, 161, 102, 53, 162, 217, 53, 81, 229, 53, - 81, 217, 53, 81, 52, 53, 81, 217, 53, 81, - 52, 190, 81, 53, 162, 168, 53, 81, 185, 53, - 81, 185, 53, 81, 168, 236, 81, 3, 237, 90, - 170, 8, 256, 186, -130, 237, 186, 47, 125, 170, - 195, 196, 197, 103, 222, 223, 41, 222, 223, 47, - 222, 223, 259, 222, 223, 237, 222, 223, 171, 222, - 223, 187, 188, 189, 187, 188, 189, 171, 91, 48, - 21, 25, 26, 27, 28, 29, 30, 31, 32, 33, - 34, 35, 36, 37, 38, 39, 47, 53, 6, 52, - 7, 95, 72, 53, 53, 52, 52, 81, 77, 84, - 53, 53, 52, 52, 50, 84, 84, 21, 25, 26, - 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, - 37, 38, 39, 9, 53, 53, 52, 52, 12, 13, - 14, 15, 16, 17, 56, 56, 18, 19, 20, 21, + 101, 90, 102, 53, 3, 216, 53, 81, 228, 53, + 81, 216, 53, 81, 52, 53, 81, 216, 53, 81, + 52, 53, 81, 52, 8, 53, 72, 185, 53, 81, + 185, 53, 81, 168, 53, 81, 168, 41, 81, 53, + 91, 52, 186, 81, 77, 186, 161, 189, 170, 162, + 162, 170, 103, 221, 222, 235, 221, 222, 236, 221, + 222, 47, 221, 222, 255, 221, 222, 236, 221, 222, + 187, 188, 48, 187, 188, 53, 171, 52, 258, 171, + 84, 236, 21, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 47, -129, + 6, 50, 7, 95, 194, 195, 196, 53, 53, 52, + 52, 56, 84, 84, 53, 53, 52, 52, 81, 21, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 35, 36, 37, 38, 39, 53, 53, 52, 52, 56, - 84, 195, 196, 197, 59, 53, 99, 52, 60, 81, - 205, 53, 53, 52, 52, 81, 205, 53, 53, 52, - 52, 81, 205, 195, 196, 197, 61, 53, 99, 52, - 62, 81, 205, 53, 53, 52, 52, 81, 205, 53, - 53, 52, 52, 81, 205, 53, 53, 52, 52, 81, - 81, 53, 53, 52, 52, 81, 81, 53, 53, 52, - 52, 81, 81, 53, 53, 52, 52, 81, 53, 53, - 52, 52, 53, 63, 52, 195, 196, 197, 64, 65, - 66, 67, 68, 69, 92, 48, 97, 99, 104, 104, - 104, 106, 112, 115, 117, 120, 120, 120, 120, 123, - 128, 129, 131, 133, 134, 135, 136, 137, 81, 144, - 145, 146, 147, 148, 151, 152, 153, 155, 165, 144, - 167, 173, 175, 176, 177, 178, 179, 180, 182, 183, - 151, 192, 200, 201, 208, 165, 212, 215, 216, 99, - 225, 165, 232, 233, 165, 235, 180, 183, 241, 242, - 244, 246, 183, 99, 251, 180, -128, 255, 180, 99, - -130, 99, 180, -129 ] + 35, 36, 37, 38, 39, 9, 53, 53, 52, 52, + 12, 13, 14, 15, 16, 17, 47, 125, 18, 19, + 20, 21, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 53, 53, 52, + 52, 56, 84, 194, 195, 196, 56, 53, 99, 52, + 59, 81, 204, 53, 53, 52, 52, 81, 204, 53, + 53, 52, 52, 81, 204, 194, 195, 196, 60, 53, + 99, 52, 61, 81, 204, 53, 53, 52, 52, 81, + 204, 53, 53, 52, 52, 81, 204, 53, 53, 52, + 52, 81, 81, 53, 53, 52, 52, 81, 81, 53, + 53, 52, 52, 81, 81, 53, 53, 52, 52, 53, + 62, 52, 194, 195, 196, 63, 64, 65, 66, 67, + 68, 69, 92, 48, 97, 99, 104, 104, 104, 106, + 112, 115, 117, 120, 120, 120, 120, 123, 128, 129, + 131, 133, 134, 135, 136, 137, 81, 144, 145, 146, + 147, 148, 151, 152, 153, 155, 165, 144, 167, 173, + 175, 176, 177, 178, 179, 180, 182, 183, 151, 191, + 199, 200, 207, 165, 211, 214, 215, 99, 224, 165, + 231, 232, 165, 234, 180, 183, 240, 241, 243, 245, + 183, 99, 250, 180, -127, 254, 180, 99, -129, 99, + 180, -128 ] racc_action_check = [ - 51, 143, 51, 192, 143, 192, 212, 192, 212, 235, - 212, 235, 237, 235, 237, 242, 237, 242, 244, 242, - 244, 166, 244, 150, 166, 150, 164, 150, 164, 209, - 164, 209, 191, 209, 191, 218, 191, 1, 218, 39, - 150, 3, 247, 164, 230, 247, 209, 91, 91, 191, - 230, 230, 230, 51, 192, 192, 7, 212, 212, 9, - 235, 235, 253, 237, 237, 253, 242, 242, 150, 244, - 244, 164, 164, 164, 209, 209, 209, 191, 39, 10, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 42, 33, 2, 33, - 2, 42, 33, 34, 35, 34, 35, 34, 34, 35, - 36, 37, 36, 37, 12, 36, 37, 42, 42, 42, + 51, 39, 51, 191, 1, 191, 211, 191, 211, 234, + 211, 234, 236, 234, 236, 241, 236, 241, 243, 241, + 243, 33, 243, 33, 3, 164, 33, 164, 208, 164, + 208, 150, 208, 150, 190, 150, 190, 7, 190, 34, + 39, 34, 164, 34, 34, 208, 143, 166, 150, 143, + 166, 190, 51, 191, 191, 217, 211, 211, 217, 234, + 234, 9, 236, 236, 246, 241, 241, 246, 243, 243, + 164, 164, 10, 208, 208, 35, 150, 35, 252, 190, + 35, 252, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 42, 229, + 2, 12, 2, 42, 229, 229, 229, 36, 37, 36, + 37, 14, 36, 37, 76, 13, 76, 13, 76, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 4, 13, 71, 13, 71, 4, 4, - 4, 4, 4, 4, 14, 15, 4, 4, 4, 4, + 42, 42, 42, 42, 42, 4, 71, 72, 71, 72, + 4, 4, 4, 4, 4, 4, 91, 91, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 38, 72, 38, 72, 16, - 38, 169, 169, 169, 17, 177, 169, 177, 18, 177, - 177, 178, 83, 178, 83, 178, 178, 179, 84, 179, - 84, 179, 179, 184, 184, 184, 21, 202, 184, 202, - 25, 202, 202, 206, 112, 206, 112, 206, 206, 207, - 114, 207, 114, 207, 207, 76, 77, 76, 77, 76, - 77, 117, 119, 117, 119, 117, 119, 141, 171, 141, - 171, 141, 171, 187, 120, 187, 120, 187, 122, 138, - 122, 138, 142, 26, 142, 220, 220, 220, 27, 28, - 29, 30, 31, 32, 40, 44, 45, 46, 55, 57, - 58, 59, 70, 74, 75, 82, 87, 88, 89, 90, - 98, 99, 105, 107, 108, 109, 110, 111, 116, 123, - 124, 125, 126, 127, 128, 129, 130, 132, 145, 146, - 149, 154, 156, 157, 158, 159, 160, 161, 162, 163, - 167, 168, 172, 174, 181, 183, 185, 188, 190, 194, - 198, 208, 213, 215, 216, 217, 224, 227, 228, 229, - 231, 233, 234, 236, 240, 241, 243, 245, 248, 251, - 254, 255, 258, 259 ] + 4, 4, 4, 4, 4, 4, 4, 38, 83, 38, + 83, 15, 38, 169, 169, 169, 16, 177, 169, 177, + 17, 177, 177, 178, 84, 178, 84, 178, 178, 179, + 112, 179, 112, 179, 179, 184, 184, 184, 18, 201, + 184, 201, 21, 201, 201, 205, 114, 205, 114, 205, + 205, 206, 120, 206, 120, 206, 206, 77, 117, 77, + 117, 77, 117, 119, 141, 119, 141, 119, 141, 171, + 187, 171, 187, 171, 187, 122, 138, 122, 138, 142, + 25, 142, 219, 219, 219, 26, 27, 28, 29, 30, + 31, 32, 40, 44, 45, 46, 55, 57, 58, 59, + 70, 74, 75, 82, 87, 88, 89, 90, 98, 99, + 105, 107, 108, 109, 110, 111, 116, 123, 124, 125, + 126, 127, 128, 129, 130, 132, 145, 146, 149, 154, + 156, 157, 158, 159, 160, 161, 162, 163, 167, 168, + 172, 174, 181, 183, 185, 188, 189, 193, 197, 207, + 212, 214, 215, 216, 223, 226, 227, 228, 230, 232, + 233, 235, 239, 240, 242, 244, 247, 250, 253, 254, + 257, 258 ] racc_action_pointer = [ - nil, 37, 88, 41, 124, nil, nil, 49, nil, 55, - 66, nil, 108, 131, 124, 125, 149, 169, 158, nil, - nil, 176, nil, nil, nil, 180, 223, 228, 244, 245, - 246, 247, 248, 94, 100, 101, 107, 108, 162, 34, - 252, nil, 92, nil, 242, 243, 201, nil, nil, nil, - nil, -5, nil, nil, nil, 238, nil, 239, 240, 241, + nil, 4, 90, 24, 126, nil, nil, 30, nil, 57, + 59, nil, 95, 112, 91, 151, 156, 175, 178, nil, + nil, 182, nil, nil, nil, 220, 225, 226, 242, 243, + 244, 245, 246, 18, 36, 72, 104, 105, 164, -4, + 250, nil, 94, nil, 240, 241, 200, nil, nil, nil, + nil, -5, nil, nil, nil, 236, nil, 237, 238, 239, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 254, 132, 163, nil, 257, 256, 212, 213, nil, nil, - nil, nil, 257, 179, 185, nil, nil, 258, 259, 260, - 228, 43, nil, nil, nil, nil, nil, nil, 227, 266, - nil, nil, nil, nil, nil, 270, nil, 271, 272, 273, - 274, 275, 201, nil, 207, nil, 271, 218, nil, 219, - 231, nil, 235, 274, 237, 240, 271, 281, 237, 228, - 284, nil, 285, nil, nil, nil, nil, nil, 236, nil, - nil, 224, 239, -41, nil, 241, 284, nil, nil, 244, - 20, nil, nil, nil, 270, nil, 271, 272, 273, 274, - 275, 289, 293, 253, 23, nil, -21, 253, 260, 120, - nil, 225, 281, nil, 282, nil, nil, 172, 178, 184, - nil, 261, nil, 258, 142, 265, nil, 230, 266, nil, - 265, 29, 0, nil, 253, nil, nil, nil, 308, nil, - nil, nil, 194, nil, nil, nil, 200, 206, 264, 26, - nil, nil, 3, 310, nil, 308, 267, 274, -7, nil, - 194, nil, nil, nil, 308, nil, nil, 271, 276, 278, - -1, 275, nil, 279, 276, 6, 267, 9, nil, nil, - 303, 317, 12, 281, 15, 306, nil, 0, 320, nil, - nil, 273, nil, 20, 285, 275, nil, nil, 324, 288, - nil, nil ] + 252, 133, 134, nil, 255, 254, 111, 214, nil, nil, + nil, nil, 255, 165, 181, nil, nil, 256, 257, 258, + 226, 142, nil, nil, nil, nil, nil, nil, 225, 264, + nil, nil, nil, nil, nil, 268, nil, 269, 270, 271, + 272, 273, 187, nil, 203, nil, 269, 215, nil, 220, + 209, nil, 232, 272, 235, 238, 269, 279, 235, 227, + 282, nil, 283, nil, nil, nil, nil, nil, 233, nil, + nil, 221, 236, 4, nil, 239, 282, nil, nil, 242, + 28, nil, nil, nil, 268, nil, 269, 270, 271, 272, + 273, 287, 291, 251, 22, nil, 5, 251, 258, 123, + nil, 226, 279, nil, 280, nil, nil, 174, 180, 186, + nil, 259, nil, 256, 145, 263, nil, 227, 264, 263, + 31, 0, nil, 252, nil, nil, nil, 306, nil, nil, + nil, 196, nil, nil, nil, 202, 208, 262, 25, nil, + nil, 3, 308, nil, 306, 265, 272, 13, nil, 192, + nil, nil, nil, 306, nil, nil, 269, 274, 276, 54, + 273, nil, 277, 274, 6, 266, 9, nil, nil, 301, + 315, 12, 279, 15, 304, nil, 22, 318, nil, nil, + 272, nil, 36, 283, 274, nil, nil, 322, 286, nil, + nil ] racc_action_default = [ - -2, -150, -10, -150, -150, -3, -4, -150, 262, -150, - -8, -12, -150, -150, -150, -150, -150, -150, -150, -24, - -25, -150, -29, -30, -31, -150, -150, -150, -150, -150, - -150, -150, -150, -150, -150, -150, -150, -150, -150, -150, - -150, -7, -137, -103, -8, -150, -134, -136, -9, -11, - -13, -141, -101, -102, -140, -15, -92, -16, -17, -150, + -2, -149, -10, -149, -149, -3, -4, -149, 261, -149, + -8, -12, -149, -149, -149, -149, -149, -149, -149, -24, + -25, -149, -29, -30, -31, -149, -149, -149, -149, -149, + -149, -149, -149, -149, -149, -149, -149, -149, -149, -149, + -149, -7, -136, -102, -8, -149, -133, -135, -9, -11, + -13, -140, -100, -101, -139, -15, -91, -16, -17, -149, -21, -26, -32, -35, -38, -41, -42, -43, -44, -45, - -46, -52, -150, -55, -57, -47, -82, -150, -85, -87, - -88, -149, -48, -95, -150, -98, -100, -49, -50, -51, - -150, -150, -5, -1, -104, -138, -105, -106, -150, -150, - -14, -142, -143, -144, -89, -150, -18, -150, -150, -150, - -150, -150, -150, -56, -53, -58, -80, -150, -86, -83, - -150, -99, -96, -150, -150, -150, -150, -150, -110, -150, - -150, -93, -150, -22, -27, -33, -36, -39, -54, -59, - -81, -84, -97, -150, -65, -69, -150, -6, -139, -107, - -108, -111, -135, -90, -150, -19, -150, -150, -150, -150, - -150, -60, -150, -63, -67, -70, -150, -110, -101, -134, - -115, -150, -150, -94, -150, -23, -28, -150, -150, -150, - -61, -150, -66, -69, -134, -101, -74, -150, -150, -79, - -150, -109, -150, -112, -134, -119, -120, -121, -150, -118, - -91, -20, -34, -145, -147, -148, -37, -40, -69, -68, - -71, -72, -150, -150, -77, -150, -69, -101, -150, -126, - -130, -131, -132, -133, -60, -116, -146, -62, -150, -101, - -122, -150, -75, -150, -64, -150, -134, -150, -128, -113, - -150, -60, -150, -124, -150, -150, -78, -150, -60, -127, - -130, -134, -73, -150, -123, -134, -129, -114, -60, -125, - -76, -117 ] + -46, -52, -149, -55, -57, -47, -81, -149, -84, -86, + -87, -148, -48, -94, -149, -97, -99, -49, -50, -51, + -149, -149, -5, -1, -103, -137, -104, -105, -149, -149, + -14, -141, -142, -143, -88, -149, -18, -149, -149, -149, + -149, -149, -149, -56, -53, -58, -79, -149, -85, -82, + -149, -98, -95, -149, -149, -149, -149, -149, -109, -149, + -149, -92, -149, -22, -27, -33, -36, -39, -54, -59, + -80, -83, -96, -149, -65, -69, -149, -6, -138, -106, + -107, -110, -134, -89, -149, -19, -149, -149, -149, -149, + -149, -60, -149, -63, -67, -70, -149, -109, -100, -133, + -114, -149, -149, -93, -149, -23, -28, -149, -149, -149, + -61, -149, -66, -69, -133, -100, -74, -149, -149, -149, + -108, -149, -111, -133, -118, -119, -120, -149, -117, -90, + -20, -34, -144, -146, -147, -37, -40, -69, -68, -71, + -72, -149, -149, -77, -149, -69, -100, -149, -125, -129, + -130, -131, -132, -60, -115, -145, -62, -149, -100, -121, + -149, -75, -149, -64, -149, -133, -149, -127, -112, -149, + -60, -149, -123, -149, -149, -78, -149, -60, -126, -129, + -133, -73, -149, -122, -133, -128, -113, -60, -124, -76, + -116 ] racc_goto_table = [ - 78, 181, 98, 54, 76, 71, 163, 194, 113, 218, - 150, 121, 122, 43, 143, 1, 226, 249, 2, 49, - 226, 226, 211, 74, 249, 86, 86, 86, 86, 231, - 82, 87, 88, 89, 55, 57, 58, 166, 202, 206, - 207, 4, 118, 78, 114, 42, 94, 119, 142, 191, - 121, 113, 247, 96, 93, 5, 40, 126, 238, 253, - 10, 74, 74, 11, 239, 51, 100, 132, 243, 227, - 121, 174, 107, 86, 86, 113, 156, 234, 108, 157, - 109, 252, 158, 78, 138, 118, 110, 141, 257, 159, - 111, 160, 70, 75, 139, 116, 124, 209, 261, 228, - 213, 245, 74, 140, 74, 130, 172, 118, 105, 154, - 86, 149, 86, 198, 240, 127, 169, nil, nil, nil, - nil, nil, nil, nil, nil, 193, nil, nil, 74, nil, - 184, nil, 86, nil, nil, nil, nil, 199, nil, nil, - 210, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 224, nil, nil, 214, nil, nil, nil, 169, 220, nil, + 78, 181, 98, 54, 113, 76, 163, 71, 122, 193, + 217, 121, 150, 143, 248, 49, 55, 57, 58, 43, + 1, 248, 2, 74, 210, 86, 86, 86, 86, 225, + 230, 4, 42, 225, 225, 93, 166, 82, 87, 88, + 89, 5, 118, 78, 142, 40, 114, 113, 119, 96, + 121, 190, 94, 246, 201, 205, 206, 126, 10, 237, + 252, 74, 74, 238, 11, 51, 100, 132, 226, 242, + 121, 113, 174, 86, 86, 107, 233, 156, 108, 157, + 251, 109, 158, 78, 110, 118, 138, 256, 141, 159, + 111, 160, 70, 75, 139, 116, 124, 260, 208, 227, + 212, 244, 74, 140, 74, 130, 172, 118, 105, 154, + 86, 149, 86, 197, 239, 127, 169, nil, nil, nil, + nil, nil, nil, nil, nil, 192, nil, nil, 74, nil, + 184, nil, 86, nil, nil, nil, nil, 198, nil, nil, + 209, nil, nil, nil, nil, nil, nil, nil, nil, 223, + nil, nil, nil, 213, nil, nil, 169, 219, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, 184, nil, nil, 230, nil, + nil, nil, nil, nil, 184, nil, nil, 229, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, 248, nil, nil, nil, nil, nil, nil, nil, - nil, 220, nil, 250, nil, nil, nil, 258, 220, nil, - 254, 260 ] + nil, 247, nil, nil, nil, nil, nil, nil, nil, nil, + 219, nil, 249, nil, nil, nil, 257, 219, nil, 253, + 259 ] racc_goto_check = [ - 44, 41, 45, 36, 51, 34, 40, 46, 35, 62, - 61, 57, 56, 58, 39, 1, 68, 65, 2, 10, - 68, 68, 46, 36, 65, 36, 36, 36, 36, 62, - 33, 33, 33, 33, 14, 14, 14, 39, 22, 22, - 22, 3, 44, 44, 34, 4, 58, 51, 56, 61, - 57, 35, 62, 10, 5, 6, 7, 8, 46, 62, - 9, 36, 36, 11, 41, 12, 13, 15, 46, 40, - 57, 16, 17, 36, 36, 35, 18, 40, 23, 24, - 25, 41, 26, 44, 34, 44, 27, 51, 41, 28, - 29, 30, 31, 32, 37, 38, 42, 43, 41, 47, + 44, 41, 45, 36, 35, 51, 40, 34, 56, 46, + 62, 57, 61, 39, 65, 10, 14, 14, 14, 58, + 1, 65, 2, 36, 46, 36, 36, 36, 36, 68, + 62, 3, 4, 68, 68, 5, 39, 33, 33, 33, + 33, 6, 44, 44, 56, 7, 34, 35, 51, 10, + 57, 61, 58, 62, 22, 22, 22, 8, 9, 46, + 62, 36, 36, 41, 11, 12, 13, 15, 40, 46, + 57, 35, 16, 36, 36, 17, 40, 18, 23, 24, + 41, 25, 26, 44, 27, 44, 34, 41, 51, 28, + 29, 30, 31, 32, 37, 38, 42, 41, 43, 47, 48, 49, 36, 50, 36, 52, 53, 44, 54, 55, 36, 60, 36, 63, 64, 67, 44, nil, nil, nil, nil, nil, nil, nil, nil, 45, nil, nil, 36, nil, 44, nil, 36, nil, nil, nil, nil, 44, nil, nil, - 45, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 45, nil, nil, 44, nil, nil, nil, 44, 44, nil, + 45, nil, nil, nil, nil, nil, nil, nil, nil, 45, + nil, nil, nil, 44, nil, nil, 44, 44, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, 44, nil, nil, 44, nil, + nil, nil, nil, nil, 44, nil, nil, 44, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, 45, nil, nil, nil, nil, nil, nil, nil, - nil, 44, nil, 44, nil, nil, nil, 45, 44, nil, - 44, 45 ] + nil, 45, nil, nil, nil, nil, nil, nil, nil, nil, + 44, nil, 44, nil, nil, nil, 45, 44, nil, 44, + 45 ] racc_goto_pointer = [ - nil, 15, 18, 39, 36, 12, 53, 50, -35, 56, - 9, 59, 52, 15, 20, -39, -84, 12, -57, nil, - nil, nil, -139, 17, -55, 18, -53, 23, -47, 26, - -46, 59, 59, -5, -28, -63, -10, -22, 21, -109, - -139, -160, 5, -86, -34, -44, -162, -113, -86, -131, - -13, -30, 1, -47, 52, -22, -72, -72, 4, nil, - -17, -118, -183, -57, -111, -220, nil, 20, -186 ] + nil, 20, 22, 29, 23, -7, 39, 39, -35, 54, + 5, 60, 52, 15, 2, -39, -83, 15, -56, nil, + nil, nil, -123, 17, -55, 19, -53, 21, -47, 26, + -46, 59, 59, 2, -26, -67, -10, -22, 21, -110, + -139, -160, 5, -85, -34, -44, -160, -112, -86, -130, + -13, -29, 1, -47, 52, -22, -76, -72, 10, nil, + -17, -116, -181, -57, -110, -222, nil, 20, -172 ] racc_goto_default = [ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 45, nil, nil, nil, nil, nil, nil, nil, 22, 23, 24, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 73, 79, nil, nil, nil, - nil, nil, 46, 164, 204, nil, nil, nil, nil, nil, + nil, nil, 46, 164, 203, nil, nil, nil, nil, nil, 80, nil, nil, nil, nil, nil, 83, 85, nil, 44, - nil, nil, nil, nil, nil, 219, 221, nil, 203 ] + nil, nil, nil, nil, nil, 218, 220, nil, 202 ] racc_reduce_table = [ 0, 0, :racc_error, - 5, 60, :_reduce_none, - 0, 61, :_reduce_none, - 2, 61, :_reduce_none, - 0, 66, :_reduce_4, - 0, 67, :_reduce_5, - 5, 65, :_reduce_6, - 2, 65, :_reduce_none, - 0, 69, :_reduce_none, - 1, 69, :_reduce_none, - 0, 62, :_reduce_10, - 3, 62, :_reduce_none, + 5, 59, :_reduce_none, + 0, 60, :_reduce_none, + 2, 60, :_reduce_none, + 0, 65, :_reduce_4, + 0, 66, :_reduce_5, + 5, 64, :_reduce_6, + 2, 64, :_reduce_none, + 0, 68, :_reduce_none, 1, 68, :_reduce_none, - 2, 68, :_reduce_13, - 3, 68, :_reduce_none, - 2, 68, :_reduce_none, - 2, 68, :_reduce_16, - 2, 68, :_reduce_17, - 0, 74, :_reduce_18, - 0, 75, :_reduce_19, - 7, 68, :_reduce_20, - 0, 76, :_reduce_21, - 0, 77, :_reduce_22, - 6, 68, :_reduce_23, - 1, 68, :_reduce_24, - 1, 68, :_reduce_25, - 0, 82, :_reduce_26, - 0, 83, :_reduce_27, - 6, 70, :_reduce_28, - 1, 70, :_reduce_none, - 1, 70, :_reduce_none, - 1, 70, :_reduce_none, - 0, 84, :_reduce_32, - 0, 85, :_reduce_33, - 7, 70, :_reduce_34, - 0, 86, :_reduce_35, - 0, 87, :_reduce_36, - 7, 70, :_reduce_37, - 0, 88, :_reduce_38, - 0, 89, :_reduce_39, - 7, 70, :_reduce_40, - 2, 70, :_reduce_41, - 2, 70, :_reduce_42, - 2, 70, :_reduce_43, - 2, 70, :_reduce_44, - 2, 70, :_reduce_45, - 2, 78, :_reduce_none, - 2, 78, :_reduce_47, - 2, 78, :_reduce_48, - 2, 78, :_reduce_49, - 2, 78, :_reduce_50, - 2, 78, :_reduce_51, - 1, 90, :_reduce_52, - 2, 90, :_reduce_53, - 3, 90, :_reduce_54, - 1, 93, :_reduce_55, - 2, 93, :_reduce_56, - 0, 97, :_reduce_none, - 1, 97, :_reduce_none, - 3, 94, :_reduce_59, - 0, 100, :_reduce_none, - 1, 100, :_reduce_none, - 8, 79, :_reduce_62, - 5, 80, :_reduce_63, - 8, 80, :_reduce_64, - 1, 98, :_reduce_65, - 3, 98, :_reduce_66, - 1, 99, :_reduce_67, - 3, 99, :_reduce_68, - 0, 102, :_reduce_69, - 1, 102, :_reduce_70, - 3, 102, :_reduce_71, - 3, 102, :_reduce_72, - 6, 102, :_reduce_73, - 0, 107, :_reduce_74, - 0, 108, :_reduce_75, - 7, 102, :_reduce_76, - 3, 102, :_reduce_77, - 5, 102, :_reduce_78, - 2, 102, :_reduce_79, + 0, 61, :_reduce_10, + 3, 61, :_reduce_none, + 1, 67, :_reduce_none, + 2, 67, :_reduce_13, + 3, 67, :_reduce_none, + 2, 67, :_reduce_none, + 2, 67, :_reduce_16, + 2, 67, :_reduce_17, + 0, 73, :_reduce_18, + 0, 74, :_reduce_19, + 7, 67, :_reduce_20, + 0, 75, :_reduce_21, + 0, 76, :_reduce_22, + 6, 67, :_reduce_23, + 1, 67, :_reduce_24, + 1, 67, :_reduce_25, + 0, 81, :_reduce_26, + 0, 82, :_reduce_27, + 6, 69, :_reduce_28, + 1, 69, :_reduce_none, + 1, 69, :_reduce_none, + 1, 69, :_reduce_none, + 0, 83, :_reduce_32, + 0, 84, :_reduce_33, + 7, 69, :_reduce_34, + 0, 85, :_reduce_35, + 0, 86, :_reduce_36, + 7, 69, :_reduce_37, + 0, 87, :_reduce_38, + 0, 88, :_reduce_39, + 7, 69, :_reduce_40, + 2, 69, :_reduce_41, + 2, 69, :_reduce_42, + 2, 69, :_reduce_43, + 2, 69, :_reduce_44, + 2, 69, :_reduce_45, + 2, 77, :_reduce_none, + 2, 77, :_reduce_47, + 2, 77, :_reduce_48, + 2, 77, :_reduce_49, + 2, 77, :_reduce_50, + 2, 77, :_reduce_51, + 1, 89, :_reduce_52, + 2, 89, :_reduce_53, + 3, 89, :_reduce_54, + 1, 92, :_reduce_55, + 2, 92, :_reduce_56, 0, 96, :_reduce_none, - 1, 96, :_reduce_81, - 1, 91, :_reduce_82, - 2, 91, :_reduce_83, - 3, 91, :_reduce_84, - 1, 110, :_reduce_85, - 2, 110, :_reduce_86, - 1, 103, :_reduce_none, - 1, 103, :_reduce_none, + 1, 96, :_reduce_none, + 3, 93, :_reduce_59, + 0, 99, :_reduce_none, + 1, 99, :_reduce_none, + 8, 78, :_reduce_62, + 5, 79, :_reduce_63, + 8, 79, :_reduce_64, + 1, 97, :_reduce_65, + 3, 97, :_reduce_66, + 1, 98, :_reduce_67, + 3, 98, :_reduce_68, + 0, 101, :_reduce_69, + 1, 101, :_reduce_70, + 3, 101, :_reduce_71, + 3, 101, :_reduce_72, + 6, 101, :_reduce_73, + 0, 106, :_reduce_74, + 0, 107, :_reduce_75, + 7, 101, :_reduce_76, + 3, 101, :_reduce_77, + 5, 101, :_reduce_78, + 0, 95, :_reduce_none, + 1, 95, :_reduce_80, + 1, 90, :_reduce_81, + 2, 90, :_reduce_82, + 3, 90, :_reduce_83, + 1, 109, :_reduce_84, + 2, 109, :_reduce_85, + 1, 102, :_reduce_none, + 1, 102, :_reduce_none, + 0, 110, :_reduce_88, 0, 111, :_reduce_89, - 0, 112, :_reduce_90, - 6, 73, :_reduce_91, + 6, 72, :_reduce_90, + 0, 112, :_reduce_91, 0, 113, :_reduce_92, - 0, 114, :_reduce_93, - 5, 73, :_reduce_94, - 1, 92, :_reduce_95, - 2, 92, :_reduce_96, - 3, 92, :_reduce_97, - 1, 115, :_reduce_98, - 2, 115, :_reduce_99, - 1, 116, :_reduce_none, - 1, 95, :_reduce_101, - 1, 95, :_reduce_102, - 1, 63, :_reduce_none, - 2, 63, :_reduce_none, - 2, 117, :_reduce_none, - 2, 117, :_reduce_none, - 4, 118, :_reduce_107, - 1, 119, :_reduce_108, - 3, 119, :_reduce_109, - 0, 120, :_reduce_110, - 1, 120, :_reduce_111, - 3, 120, :_reduce_112, - 5, 120, :_reduce_113, - 7, 120, :_reduce_114, + 5, 72, :_reduce_93, + 1, 91, :_reduce_94, + 2, 91, :_reduce_95, + 3, 91, :_reduce_96, + 1, 114, :_reduce_97, + 2, 114, :_reduce_98, + 1, 115, :_reduce_none, + 1, 94, :_reduce_100, + 1, 94, :_reduce_101, + 1, 62, :_reduce_none, + 2, 62, :_reduce_none, + 2, 116, :_reduce_none, + 2, 116, :_reduce_none, + 4, 117, :_reduce_106, + 1, 118, :_reduce_107, + 3, 118, :_reduce_108, + 0, 119, :_reduce_109, + 1, 119, :_reduce_110, + 3, 119, :_reduce_111, + 5, 119, :_reduce_112, + 7, 119, :_reduce_113, + 0, 121, :_reduce_114, 0, 122, :_reduce_115, - 0, 123, :_reduce_116, - 8, 120, :_reduce_117, - 3, 120, :_reduce_118, - 1, 105, :_reduce_119, - 1, 105, :_reduce_120, + 8, 119, :_reduce_116, + 3, 119, :_reduce_117, + 1, 104, :_reduce_118, + 1, 104, :_reduce_119, + 1, 104, :_reduce_120, 1, 105, :_reduce_121, - 1, 106, :_reduce_122, - 3, 106, :_reduce_123, - 2, 106, :_reduce_124, - 4, 106, :_reduce_125, - 1, 121, :_reduce_126, - 3, 121, :_reduce_127, - 2, 121, :_reduce_128, - 4, 121, :_reduce_129, - 1, 124, :_reduce_none, - 1, 124, :_reduce_none, - 1, 125, :_reduce_132, - 1, 125, :_reduce_133, - 0, 104, :_reduce_none, - 3, 104, :_reduce_135, - 1, 101, :_reduce_none, - 0, 64, :_reduce_none, - 0, 126, :_reduce_138, - 3, 64, :_reduce_139, + 3, 105, :_reduce_122, + 2, 105, :_reduce_123, + 4, 105, :_reduce_124, + 1, 120, :_reduce_125, + 3, 120, :_reduce_126, + 2, 120, :_reduce_127, + 4, 120, :_reduce_128, + 1, 123, :_reduce_none, + 1, 123, :_reduce_none, + 1, 124, :_reduce_131, + 1, 124, :_reduce_132, + 0, 103, :_reduce_none, + 3, 103, :_reduce_134, + 1, 100, :_reduce_none, + 0, 63, :_reduce_none, + 0, 125, :_reduce_137, + 3, 63, :_reduce_138, + 1, 70, :_reduce_none, + 0, 71, :_reduce_none, + 1, 71, :_reduce_none, 1, 71, :_reduce_none, - 0, 72, :_reduce_none, - 1, 72, :_reduce_none, - 1, 72, :_reduce_none, - 1, 72, :_reduce_none, - 1, 81, :_reduce_145, - 2, 81, :_reduce_146, - 1, 127, :_reduce_none, - 1, 127, :_reduce_none, - 1, 109, :_reduce_149 ] + 1, 71, :_reduce_none, + 1, 80, :_reduce_144, + 2, 80, :_reduce_145, + 1, 126, :_reduce_none, + 1, 126, :_reduce_none, + 1, 108, :_reduce_148 ] -racc_reduce_n = 150 +racc_reduce_n = 149 -racc_shift_n = 262 +racc_shift_n = 261 racc_token_table = { false => 0, @@ -1130,17 +1129,16 @@ def raise_parse_error(error_message, location) "%empty" => 47, "%prec" => 48, "%if" => 49, - "%endif" => 50, - "?" => 51, - "+" => 52, - "*" => 53, - "%true" => 54, - "%false" => 55, - "[" => 56, - "]" => 57, - "{...}" => 58 } - -racc_nt_base = 59 + "?" => 50, + "+" => 51, + "*" => 52, + "%true" => 53, + "%false" => 54, + "[" => 55, + "]" => 56, + "{...}" => 57 } + +racc_nt_base = 58 racc_use_result_var = true @@ -1212,7 +1210,6 @@ def raise_parse_error(error_message, location) "\"%empty\"", "\"%prec\"", "\"%if\"", - "\"%endif\"", "\"?\"", "\"+\"", "\"*\"", @@ -1738,13 +1735,12 @@ def _reduce_62(val, _values, result) def _reduce_63(val, _values, result) rule = Grammar::ParameterizingRule::Rule.new(val[2].s_value, [], val[4], is_inline: true) @grammar.add_parameterizing_rule(rule) - @grammar.initialize_if_count result end .,., -module_eval(<<'.,.,', 'parser.y', 249) +module_eval(<<'.,.,', 'parser.y', 248) def _reduce_64(val, _values, result) rule = Grammar::ParameterizingRule::Rule.new(val[2].s_value, val[4], val[7], is_inline: true) @grammar.add_parameterizing_rule(rule) @@ -1753,21 +1749,21 @@ def _reduce_64(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 253) +module_eval(<<'.,.,', 'parser.y', 252) def _reduce_65(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 254) +module_eval(<<'.,.,', 'parser.y', 253) def _reduce_66(val, _values, result) result = val[0].append(val[2]) result end .,., -module_eval(<<'.,.,', 'parser.y', 258) +module_eval(<<'.,.,', 'parser.y', 257) def _reduce_67(val, _values, result) builder = val[0] result = [builder] @@ -1776,7 +1772,7 @@ def _reduce_67(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 263) +module_eval(<<'.,.,', 'parser.y', 262) def _reduce_68(val, _values, result) builder = val[2] result = val[0].append(builder) @@ -1785,7 +1781,7 @@ def _reduce_68(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 269) +module_eval(<<'.,.,', 'parser.y', 268) def _reduce_69(val, _values, result) reset_precs result = Grammar::ParameterizingRule::Rhs.new @@ -1794,7 +1790,7 @@ def _reduce_69(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 274) +module_eval(<<'.,.,', 'parser.y', 273) def _reduce_70(val, _values, result) reset_precs result = Grammar::ParameterizingRule::Rhs.new @@ -1803,7 +1799,7 @@ def _reduce_70(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 279) +module_eval(<<'.,.,', 'parser.y', 278) def _reduce_71(val, _values, result) token = val[1] token.alias_name = val[2] @@ -1815,7 +1811,7 @@ def _reduce_71(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 287) +module_eval(<<'.,.,', 'parser.y', 286) def _reduce_72(val, _values, result) builder = val[0] builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]]) @@ -1825,7 +1821,7 @@ def _reduce_72(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 293) +module_eval(<<'.,.,', 'parser.y', 292) def _reduce_73(val, _values, result) builder = val[0] builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[5]) @@ -1835,7 +1831,7 @@ def _reduce_73(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 299) +module_eval(<<'.,.,', 'parser.y', 298) def _reduce_74(val, _values, result) if @prec_seen on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec @@ -1847,7 +1843,7 @@ def _reduce_74(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 307) +module_eval(<<'.,.,', 'parser.y', 306) def _reduce_75(val, _values, result) end_c_declaration @@ -1855,7 +1851,7 @@ def _reduce_75(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 311) +module_eval(<<'.,.,', 'parser.y', 310) def _reduce_76(val, _values, result) user_code = val[3] user_code.alias_name = val[6] @@ -1867,7 +1863,7 @@ def _reduce_76(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 319) +module_eval(<<'.,.,', 'parser.y', 318) def _reduce_77(val, _values, result) sym = @grammar.find_symbol_by_id!(val[2]) @prec_seen = true @@ -1879,192 +1875,179 @@ def _reduce_77(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 327) +module_eval(<<'.,.,', 'parser.y', 326) def _reduce_78(val, _values, result) builder = val[0] builder.symbols << Lrama::Lexer::Token::ControlSyntax.new(s_value: val[1], location: @lexer.location, condition: val[3]) - @grammar.if_count += 1 result = builder result end .,., -module_eval(<<'.,.,', 'parser.y', 334) - def _reduce_79(val, _values, result) - on_action_error("no %if before %endif", val[0]) if @grammar.if_count == 0 - builder = val[0] - builder.symbols << Lrama::Lexer::Token::ControlSyntax.new(s_value: val[1], location: @lexer.location) - @grammar.if_count -= 1 - result = builder +# reduce 79 omitted - result - end -.,., - -# reduce 80 omitted - -module_eval(<<'.,.,', 'parser.y', 342) - def _reduce_81(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 332) + def _reduce_80(val, _values, result) result = val[0].s_value result end .,., -module_eval(<<'.,.,', 'parser.y', 346) - def _reduce_82(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 336) + def _reduce_81(val, _values, result) result = [{tag: nil, tokens: val[0]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 350) - def _reduce_83(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 340) + def _reduce_82(val, _values, result) result = [{tag: val[0], tokens: val[1]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 354) - def _reduce_84(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 344) + def _reduce_83(val, _values, result) result = val[0].append({tag: val[1], tokens: val[2]}) result end .,., -module_eval(<<'.,.,', 'parser.y', 357) - def _reduce_85(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 347) + def _reduce_84(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 358) - def _reduce_86(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 348) + def _reduce_85(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 87 omitted +# reduce 86 omitted -# reduce 88 omitted +# reduce 87 omitted -module_eval(<<'.,.,', 'parser.y', 365) - def _reduce_89(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 355) + def _reduce_88(val, _values, result) begin_c_declaration("}") result end .,., -module_eval(<<'.,.,', 'parser.y', 369) - def _reduce_90(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 359) + def _reduce_89(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 373) - def _reduce_91(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 363) + def _reduce_90(val, _values, result) result = val[0].append(val[3]) result end .,., -module_eval(<<'.,.,', 'parser.y', 377) - def _reduce_92(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 367) + def _reduce_91(val, _values, result) begin_c_declaration("}") result end .,., -module_eval(<<'.,.,', 'parser.y', 381) - def _reduce_93(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 371) + def _reduce_92(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 385) - def _reduce_94(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 375) + def _reduce_93(val, _values, result) result = [val[2]] result end .,., -module_eval(<<'.,.,', 'parser.y', 390) - def _reduce_95(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 380) + def _reduce_94(val, _values, result) result = [{tag: nil, tokens: val[0]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 394) - def _reduce_96(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 384) + def _reduce_95(val, _values, result) result = [{tag: val[0], tokens: val[1]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 398) - def _reduce_97(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 388) + def _reduce_96(val, _values, result) result = val[0].append({tag: val[1], tokens: val[2]}) result end .,., -module_eval(<<'.,.,', 'parser.y', 401) - def _reduce_98(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 391) + def _reduce_97(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 402) - def _reduce_99(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 392) + def _reduce_98(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 100 omitted +# reduce 99 omitted -module_eval(<<'.,.,', 'parser.y', 406) - def _reduce_101(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 396) + def _reduce_100(val, _values, result) on_action_error("ident after %prec", val[0]) if @prec_seen result end .,., -module_eval(<<'.,.,', 'parser.y', 407) - def _reduce_102(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 397) + def _reduce_101(val, _values, result) on_action_error("char after %prec", val[0]) if @prec_seen result end .,., +# reduce 102 omitted + # reduce 103 omitted # reduce 104 omitted # reduce 105 omitted -# reduce 106 omitted - -module_eval(<<'.,.,', 'parser.y', 417) - def _reduce_107(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 407) + def _reduce_106(val, _values, result) lhs = val[0] lhs.alias_name = val[1] val[3].each do |builder| @@ -2077,8 +2060,8 @@ def _reduce_107(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 428) - def _reduce_108(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 418) + def _reduce_107(val, _values, result) builder = val[0] if !builder.line builder.line = @lexer.line - 1 @@ -2089,8 +2072,8 @@ def _reduce_108(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 436) - def _reduce_109(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 426) + def _reduce_108(val, _values, result) builder = val[2] if !builder.line builder.line = @lexer.line - 1 @@ -2101,8 +2084,8 @@ def _reduce_109(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 445) - def _reduce_110(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 435) + def _reduce_109(val, _values, result) reset_precs result = @grammar.create_rule_builder(@rule_counter, @midrule_action_counter) @@ -2110,8 +2093,8 @@ def _reduce_110(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 450) - def _reduce_111(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 440) + def _reduce_110(val, _values, result) reset_precs result = @grammar.create_rule_builder(@rule_counter, @midrule_action_counter) @@ -2119,8 +2102,8 @@ def _reduce_111(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 455) - def _reduce_112(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 445) + def _reduce_111(val, _values, result) token = val[1] token.alias_name = val[2] builder = val[0] @@ -2131,8 +2114,8 @@ def _reduce_112(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 463) - def _reduce_113(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 453) + def _reduce_112(val, _values, result) token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], alias_name: val[3], location: @lexer.location, args: [val[1]], lhs_tag: val[4]) builder = val[0] builder.add_rhs(token) @@ -2143,8 +2126,8 @@ def _reduce_113(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 471) - def _reduce_114(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 461) + def _reduce_113(val, _values, result) token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, alias_name: val[5], location: @lexer.location, args: val[3], lhs_tag: val[6]) builder = val[0] builder.add_rhs(token) @@ -2155,8 +2138,8 @@ def _reduce_114(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 479) - def _reduce_115(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 469) + def _reduce_114(val, _values, result) if @prec_seen on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec @code_after_prec = true @@ -2167,16 +2150,16 @@ def _reduce_115(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 487) - def _reduce_116(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 477) + def _reduce_115(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 491) - def _reduce_117(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 481) + def _reduce_116(val, _values, result) user_code = val[3] user_code.alias_name = val[6] user_code.tag = val[7] @@ -2188,8 +2171,8 @@ def _reduce_117(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 500) - def _reduce_118(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 490) + def _reduce_117(val, _values, result) sym = @grammar.find_symbol_by_id!(val[2]) @prec_seen = true builder = val[0] @@ -2200,116 +2183,116 @@ def _reduce_118(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 507) - def _reduce_119(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 497) + def _reduce_118(val, _values, result) result = "option" result end .,., -module_eval(<<'.,.,', 'parser.y', 508) - def _reduce_120(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 498) + def _reduce_119(val, _values, result) result = "nonempty_list" result end .,., -module_eval(<<'.,.,', 'parser.y', 509) - def _reduce_121(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 499) + def _reduce_120(val, _values, result) result = "list" result end .,., -module_eval(<<'.,.,', 'parser.y', 511) - def _reduce_122(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 501) + def _reduce_121(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 512) - def _reduce_123(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 502) + def _reduce_122(val, _values, result) result = val[0].append(val[2]) result end .,., -module_eval(<<'.,.,', 'parser.y', 513) - def _reduce_124(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 503) + def _reduce_123(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] result end .,., -module_eval(<<'.,.,', 'parser.y', 514) - def _reduce_125(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 504) + def _reduce_124(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] result end .,., -module_eval(<<'.,.,', 'parser.y', 516) - def _reduce_126(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 506) + def _reduce_125(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 517) - def _reduce_127(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 507) + def _reduce_126(val, _values, result) result = val[0].append(val[2]) result end .,., -module_eval(<<'.,.,', 'parser.y', 518) - def _reduce_128(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 508) + def _reduce_127(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] result end .,., -module_eval(<<'.,.,', 'parser.y', 519) - def _reduce_129(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 509) + def _reduce_128(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] result end .,., -# reduce 130 omitted +# reduce 129 omitted -# reduce 131 omitted +# reduce 130 omitted -module_eval(<<'.,.,', 'parser.y', 524) - def _reduce_132(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 514) + def _reduce_131(val, _values, result) result = Lrama::Lexer::Token::Ident.new(s_value: true) result end .,., -module_eval(<<'.,.,', 'parser.y', 525) - def _reduce_133(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 515) + def _reduce_132(val, _values, result) result = Lrama::Lexer::Token::Ident.new(s_value: false) result end .,., -# reduce 134 omitted +# reduce 133 omitted -module_eval(<<'.,.,', 'parser.y', 528) - def _reduce_135(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 518) + def _reduce_134(val, _values, result) result = val[1].s_value result end .,., -# reduce 136 omitted +# reduce 135 omitted -# reduce 137 omitted +# reduce 136 omitted -module_eval(<<'.,.,', 'parser.y', 535) - def _reduce_138(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 525) + def _reduce_137(val, _values, result) begin_c_declaration('\Z') @grammar.epilogue_first_lineno = @lexer.line + 1 @@ -2317,8 +2300,8 @@ def _reduce_138(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 540) - def _reduce_139(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 530) + def _reduce_138(val, _values, result) end_c_declaration @grammar.epilogue = val[2].s_value @@ -2326,6 +2309,8 @@ def _reduce_139(val, _values, result) end .,., +# reduce 139 omitted + # reduce 140 omitted # reduce 141 omitted @@ -2334,28 +2319,26 @@ def _reduce_139(val, _values, result) # reduce 143 omitted -# reduce 144 omitted - -module_eval(<<'.,.,', 'parser.y', 551) - def _reduce_145(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 541) + def _reduce_144(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 552) - def _reduce_146(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 542) + def _reduce_145(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 147 omitted +# reduce 146 omitted -# reduce 148 omitted +# reduce 147 omitted -module_eval(<<'.,.,', 'parser.y', 557) - def _reduce_149(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 547) + def _reduce_148(val, _values, result) result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) result end diff --git a/parser.y b/parser.y index 63abaf1b..70e29f68 100644 --- a/parser.y +++ b/parser.y @@ -243,7 +243,6 @@ rule { rule = Grammar::ParameterizingRule::Rule.new(val[2].s_value, [], val[4], is_inline: true) @grammar.add_parameterizing_rule(rule) - @grammar.initialize_if_count } | "%rule" "%inline" IDENTIFIER "(" rule_args ")" ":" rule_rhs_list { @@ -327,15 +326,6 @@ rule { builder = val[0] builder.symbols << Lrama::Lexer::Token::ControlSyntax.new(s_value: val[1], location: @lexer.location, condition: val[3]) - @grammar.if_count += 1 - result = builder - } - | rule_rhs "%endif" - { - on_action_error("no %if before %endif", val[0]) if @grammar.if_count == 0 - builder = val[0] - builder.symbols << Lrama::Lexer::Token::ControlSyntax.new(s_value: val[1], location: @lexer.location) - @grammar.if_count -= 1 result = builder } diff --git a/sig/lrama/grammar/parameterizing_rule/rhs.rbs b/sig/lrama/grammar/parameterizing_rule/rhs.rbs index 4d4c1342..bc207d52 100644 --- a/sig/lrama/grammar/parameterizing_rule/rhs.rbs +++ b/sig/lrama/grammar/parameterizing_rule/rhs.rbs @@ -8,7 +8,6 @@ module Lrama def initialize: () -> void def skip?: (Grammar::Binding bindings) -> bool - def resolve_symbols: (Grammar::Binding bindings) -> Array[untyped] def resolve_user_code: (Grammar::Binding bindings) -> Lexer::Token::UserCode? end end diff --git a/sig/lrama/lexer/token/control_syntax.rbs b/sig/lrama/lexer/token/control_syntax.rbs index 9701c685..c6f06114 100644 --- a/sig/lrama/lexer/token/control_syntax.rbs +++ b/sig/lrama/lexer/token/control_syntax.rbs @@ -6,7 +6,6 @@ module Lrama def initialize: (s_value: String, location: Location, ?condition: Lexer::Token::Ident?) -> void def if?: () -> bool - def endif?: () -> bool def true?: () -> bool def false?: () -> bool def condition_value: () -> String? diff --git a/spec/fixtures/parameterizing_rules/user_defined/if.y b/spec/fixtures/parameterizing_rules/user_defined/if.y index 97c6de2a..ffacc836 100644 --- a/spec/fixtures/parameterizing_rules/user_defined/if.y +++ b/spec/fixtures/parameterizing_rules/user_defined/if.y @@ -16,7 +16,6 @@ static int yyerror(YYLTYPE *loc, const char *str); %rule defined_rule(X, condition): /* empty */ | X { $$ = $1; } %if(condition) - | %if(condition) X %endif X { $$ = $1; } ; %% diff --git a/spec/lrama/parser_spec.rb b/spec/lrama/parser_spec.rb index c6135a6a..3eb2110d 100644 --- a/spec/lrama/parser_spec.rb +++ b/spec/lrama/parser_spec.rb @@ -2358,7 +2358,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"), - lineno: 24, + lineno: 23, ), Rule.new( id: 1, @@ -2367,7 +2367,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 24, + lineno: 23, ), Rule.new( id: 2, @@ -2378,22 +2378,10 @@ token_code: T::UserCode.new(s_value: " $$ = $1; "), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number"), - lineno: 24, + lineno: 23, ), Rule.new( id: 3, - lhs: grammar.find_symbol_by_s_value!("defined_rule_number_true"), - rhs: [ - grammar.find_symbol_by_s_value!("number"), - grammar.find_symbol_by_s_value!("number"), - ], - token_code: T::UserCode.new(s_value: " $$ = $1; "), - nullable: false, - precedence_sym: grammar.find_symbol_by_s_value!("number"), - lineno: 24, - ), - Rule.new( - id: 4, lhs: grammar.find_symbol_by_s_value!("r_true"), rhs: [ grammar.find_symbol_by_s_value!("defined_rule_number_true"), @@ -2401,38 +2389,27 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 24, + lineno: 23, ), Rule.new( - id: 5, + id: 4, lhs: grammar.find_symbol_by_s_value!("defined_rule_number_false"), rhs: [], token_code: nil, nullable: true, precedence_sym: nil, - lineno: 27, - ), - Rule.new( - id: 6, - lhs: grammar.find_symbol_by_s_value!("defined_rule_number_false"), - rhs: [ - grammar.find_symbol_by_s_value!("number"), - ], - token_code: T::UserCode.new(s_value: " $$ = $1; "), - nullable: false, - precedence_sym: grammar.find_symbol_by_s_value!("number"), - lineno: 27, + lineno: 26, ), Rule.new( - id: 7, + id: 5, lhs: grammar.find_symbol_by_s_value!("r_false"), rhs: [ - grammar.find_symbol_by_s_value!("defined_rule_number_false"), + grammar.find_symbol_by_s_value!("defined_rule_number_false") ], token_code: nil, nullable: true, precedence_sym: nil, - lineno: 27, + lineno: 26, ), ]) end From 192d0c92a6485282e745e487a9739607767cbc65 Mon Sep 17 00:00:00 2001 From: ydah Date: Sun, 9 Jun 2024 14:18:32 +0900 Subject: [PATCH 3/5] Change %if directives to be available only at the end of rhs --- lib/lrama/parser.rb | 704 ++++++++++++++++++++++---------------------- parser.y | 13 +- 2 files changed, 364 insertions(+), 353 deletions(-) diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index ecfb8e0e..57a3e33d 100644 --- a/lib/lrama/parser.rb +++ b/lib/lrama/parser.rb @@ -654,7 +654,7 @@ def token_to_str(t) module Lrama class Parser < Racc::Parser -module_eval(<<'...end parser.y/module_eval...', 'parser.y', 552) +module_eval(<<'...end parser.y/module_eval...', 'parser.y', 553) include Lrama::Report::Duration @@ -728,53 +728,53 @@ def raise_parse_error(error_message, location) ##### State transition tables begin ### racc_action_table = [ - 101, 90, 102, 53, 3, 216, 53, 81, 228, 53, - 81, 216, 53, 81, 52, 53, 81, 216, 53, 81, - 52, 53, 81, 52, 8, 53, 72, 185, 53, 81, - 185, 53, 81, 168, 53, 81, 168, 41, 81, 53, - 91, 52, 186, 81, 77, 186, 161, 189, 170, 162, - 162, 170, 103, 221, 222, 235, 221, 222, 236, 221, - 222, 47, 221, 222, 255, 221, 222, 236, 221, 222, - 187, 188, 48, 187, 188, 53, 171, 52, 258, 171, - 84, 236, 21, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 47, -129, - 6, 50, 7, 95, 194, 195, 196, 53, 53, 52, + 101, 90, 102, 53, 3, 218, 53, 81, 231, 53, + 81, 218, 53, 81, 52, 53, 81, 218, 53, 81, + 52, 53, 81, 52, 8, 53, 72, 187, 53, 81, + 187, 53, 81, 168, 53, 81, 168, 41, 81, 53, + 91, 52, 188, 81, 77, 188, 161, 191, 170, 162, + 162, 170, 103, 223, 224, 238, 223, 224, 239, 223, + 224, 47, 223, 224, 258, 223, 224, 239, 223, 224, + 189, 190, 48, 189, 190, 53, 171, 52, 261, 171, + 84, 239, 21, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 47, -131, + 6, 50, 7, 95, 196, 197, 198, 53, 53, 52, 52, 56, 84, 84, 53, 53, 52, 52, 81, 21, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 9, 53, 53, 52, 52, 12, 13, 14, 15, 16, 17, 47, 125, 18, 19, 20, 21, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 53, 53, 52, - 52, 56, 84, 194, 195, 196, 56, 53, 99, 52, - 59, 81, 204, 53, 53, 52, 52, 81, 204, 53, - 53, 52, 52, 81, 204, 194, 195, 196, 60, 53, - 99, 52, 61, 81, 204, 53, 53, 52, 52, 81, - 204, 53, 53, 52, 52, 81, 204, 53, 53, 52, + 52, 56, 84, 196, 197, 198, 56, 53, 99, 52, + 59, 81, 206, 53, 53, 52, 52, 81, 206, 53, + 53, 52, 52, 81, 206, 196, 197, 198, 60, 53, + 99, 52, 61, 81, 206, 53, 53, 52, 52, 81, + 206, 53, 53, 52, 52, 81, 206, 53, 53, 52, 52, 81, 81, 53, 53, 52, 52, 81, 81, 53, 53, 52, 52, 81, 81, 53, 53, 52, 52, 53, - 62, 52, 194, 195, 196, 63, 64, 65, 66, 67, + 62, 52, 196, 197, 198, 63, 64, 65, 66, 67, 68, 69, 92, 48, 97, 99, 104, 104, 104, 106, 112, 115, 117, 120, 120, 120, 120, 123, 128, 129, 131, 133, 134, 135, 136, 137, 81, 144, 145, 146, 147, 148, 151, 152, 153, 155, 165, 144, 167, 173, - 175, 176, 177, 178, 179, 180, 182, 183, 151, 191, - 199, 200, 207, 165, 211, 214, 215, 99, 224, 165, - 231, 232, 165, 234, 180, 183, 240, 241, 243, 245, - 183, 99, 250, 180, -127, 254, 180, 99, -129, 99, - 180, -128 ] + 175, 176, 177, 178, 179, 180, 182, 183, 151, 193, + 201, 202, 209, 165, 213, 216, 217, 99, 226, 165, + 234, 235, 165, 237, 180, 183, 243, 244, 246, 248, + 183, 99, 253, 180, -129, 257, 180, 99, -131, 99, + 180, -130 ] racc_action_check = [ - 51, 39, 51, 191, 1, 191, 211, 191, 211, 234, - 211, 234, 236, 234, 236, 241, 236, 241, 243, 241, - 243, 33, 243, 33, 3, 164, 33, 164, 208, 164, - 208, 150, 208, 150, 190, 150, 190, 7, 190, 34, - 39, 34, 164, 34, 34, 208, 143, 166, 150, 143, - 166, 190, 51, 191, 191, 217, 211, 211, 217, 234, - 234, 9, 236, 236, 246, 241, 241, 246, 243, 243, - 164, 164, 10, 208, 208, 35, 150, 35, 252, 190, - 35, 252, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 42, 229, - 2, 12, 2, 42, 229, 229, 229, 36, 37, 36, + 51, 39, 51, 193, 1, 193, 213, 193, 213, 237, + 213, 237, 239, 237, 239, 244, 239, 244, 246, 244, + 246, 33, 246, 33, 3, 164, 33, 164, 210, 164, + 210, 150, 210, 150, 192, 150, 192, 7, 192, 34, + 39, 34, 164, 34, 34, 210, 143, 166, 150, 143, + 166, 192, 51, 193, 193, 219, 213, 213, 219, 237, + 237, 9, 239, 239, 249, 244, 244, 249, 246, 246, + 164, 164, 10, 210, 210, 35, 150, 35, 255, 192, + 35, 255, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 42, 232, + 2, 12, 2, 42, 232, 232, 232, 36, 37, 36, 37, 14, 36, 37, 76, 13, 76, 13, 76, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 4, 71, 72, 71, 72, @@ -783,21 +783,21 @@ def raise_parse_error(error_message, location) 4, 4, 4, 4, 4, 4, 4, 38, 83, 38, 83, 15, 38, 169, 169, 169, 16, 177, 169, 177, 17, 177, 177, 178, 84, 178, 84, 178, 178, 179, - 112, 179, 112, 179, 179, 184, 184, 184, 18, 201, - 184, 201, 21, 201, 201, 205, 114, 205, 114, 205, - 205, 206, 120, 206, 120, 206, 206, 77, 117, 77, + 112, 179, 112, 179, 179, 186, 186, 186, 18, 203, + 186, 203, 21, 203, 203, 207, 114, 207, 114, 207, + 207, 208, 120, 208, 120, 208, 208, 77, 117, 77, 117, 77, 117, 119, 141, 119, 141, 119, 141, 171, - 187, 171, 187, 171, 187, 122, 138, 122, 138, 142, - 25, 142, 219, 219, 219, 26, 27, 28, 29, 30, + 189, 171, 189, 171, 189, 122, 138, 122, 138, 142, + 25, 142, 221, 221, 221, 26, 27, 28, 29, 30, 31, 32, 40, 44, 45, 46, 55, 57, 58, 59, 70, 74, 75, 82, 87, 88, 89, 90, 98, 99, 105, 107, 108, 109, 110, 111, 116, 123, 124, 125, 126, 127, 128, 129, 130, 132, 145, 146, 149, 154, 156, 157, 158, 159, 160, 161, 162, 163, 167, 168, - 172, 174, 181, 183, 185, 188, 189, 193, 197, 207, - 212, 214, 215, 216, 223, 226, 227, 228, 230, 232, - 233, 235, 239, 240, 242, 244, 247, 250, 253, 254, - 257, 258 ] + 172, 174, 181, 183, 187, 190, 191, 195, 199, 209, + 214, 216, 217, 218, 225, 228, 230, 231, 233, 235, + 236, 238, 242, 243, 245, 247, 250, 253, 256, 257, + 260, 261 ] racc_action_pointer = [ nil, 4, 90, 24, 126, nil, nil, 30, nil, 57, @@ -818,110 +818,112 @@ def raise_parse_error(error_message, location) 28, nil, nil, nil, 268, nil, 269, 270, 271, 272, 273, 287, 291, 251, 22, nil, 5, 251, 258, 123, nil, 226, 279, nil, 280, nil, nil, 174, 180, 186, - nil, 259, nil, 256, 145, 263, nil, 227, 264, 263, - 31, 0, nil, 252, nil, nil, nil, 306, nil, nil, - nil, 196, nil, nil, nil, 202, 208, 262, 25, nil, - nil, 3, 308, nil, 306, 265, 272, 13, nil, 192, - nil, nil, nil, 306, nil, nil, 269, 274, 276, 54, - 273, nil, 277, 274, 6, 266, 9, nil, nil, 301, - 315, 12, 279, 15, 304, nil, 22, 318, nil, nil, - 272, nil, 36, 283, 274, nil, nil, 322, 286, nil, - nil ] + nil, 259, nil, 256, nil, nil, 145, 263, nil, 227, + 264, 263, 31, 0, nil, 252, nil, nil, nil, 306, + nil, nil, nil, 196, nil, nil, nil, 202, 208, 262, + 25, nil, nil, 3, 308, nil, 306, 265, 272, 13, + nil, 192, nil, nil, nil, 306, nil, nil, 269, nil, + 274, 276, 54, 273, nil, 277, 274, 6, 266, 9, + nil, nil, 301, 315, 12, 279, 15, 304, nil, 22, + 318, nil, nil, 272, nil, 36, 283, 274, nil, nil, + 322, 286, nil, nil ] racc_action_default = [ - -2, -149, -10, -149, -149, -3, -4, -149, 261, -149, - -8, -12, -149, -149, -149, -149, -149, -149, -149, -24, - -25, -149, -29, -30, -31, -149, -149, -149, -149, -149, - -149, -149, -149, -149, -149, -149, -149, -149, -149, -149, - -149, -7, -136, -102, -8, -149, -133, -135, -9, -11, - -13, -140, -100, -101, -139, -15, -91, -16, -17, -149, + -2, -151, -10, -151, -151, -3, -4, -151, 264, -151, + -8, -12, -151, -151, -151, -151, -151, -151, -151, -24, + -25, -151, -29, -30, -31, -151, -151, -151, -151, -151, + -151, -151, -151, -151, -151, -151, -151, -151, -151, -151, + -151, -7, -138, -104, -8, -151, -135, -137, -9, -11, + -13, -142, -102, -103, -141, -15, -93, -16, -17, -151, -21, -26, -32, -35, -38, -41, -42, -43, -44, -45, - -46, -52, -149, -55, -57, -47, -81, -149, -84, -86, - -87, -148, -48, -94, -149, -97, -99, -49, -50, -51, - -149, -149, -5, -1, -103, -137, -104, -105, -149, -149, - -14, -141, -142, -143, -88, -149, -18, -149, -149, -149, - -149, -149, -149, -56, -53, -58, -79, -149, -85, -82, - -149, -98, -95, -149, -149, -149, -149, -149, -109, -149, - -149, -92, -149, -22, -27, -33, -36, -39, -54, -59, - -80, -83, -96, -149, -65, -69, -149, -6, -138, -106, - -107, -110, -134, -89, -149, -19, -149, -149, -149, -149, - -149, -60, -149, -63, -67, -70, -149, -109, -100, -133, - -114, -149, -149, -93, -149, -23, -28, -149, -149, -149, - -61, -149, -66, -69, -133, -100, -74, -149, -149, -149, - -108, -149, -111, -133, -118, -119, -120, -149, -117, -90, - -20, -34, -144, -146, -147, -37, -40, -69, -68, -71, - -72, -149, -149, -77, -149, -69, -100, -149, -125, -129, - -130, -131, -132, -60, -115, -145, -62, -149, -100, -121, - -149, -75, -149, -64, -149, -133, -149, -127, -112, -149, - -60, -149, -123, -149, -149, -78, -149, -60, -126, -129, - -133, -73, -149, -122, -133, -128, -113, -60, -124, -76, - -116 ] + -46, -52, -151, -55, -57, -47, -83, -151, -86, -88, + -89, -150, -48, -96, -151, -99, -101, -49, -50, -51, + -151, -151, -5, -1, -105, -139, -106, -107, -151, -151, + -14, -143, -144, -145, -90, -151, -18, -151, -151, -151, + -151, -151, -151, -56, -53, -58, -81, -151, -87, -84, + -151, -100, -97, -151, -151, -151, -151, -151, -111, -151, + -151, -94, -151, -22, -27, -33, -36, -39, -54, -59, + -82, -85, -98, -151, -65, -71, -151, -6, -140, -108, + -109, -112, -136, -91, -151, -19, -151, -151, -151, -151, + -151, -60, -151, -63, -67, -72, -151, -111, -102, -135, + -116, -151, -151, -95, -151, -23, -28, -151, -151, -151, + -61, -151, -66, -71, -68, -69, -135, -102, -76, -151, + -151, -151, -110, -151, -113, -135, -120, -121, -122, -151, + -119, -92, -20, -34, -146, -148, -149, -37, -40, -71, + -67, -73, -74, -151, -151, -79, -151, -71, -102, -151, + -127, -131, -132, -133, -134, -60, -117, -147, -62, -70, + -151, -102, -123, -151, -77, -151, -64, -151, -135, -151, + -129, -114, -151, -60, -151, -125, -151, -151, -80, -151, + -60, -128, -131, -135, -75, -151, -124, -135, -130, -115, + -60, -126, -78, -118 ] racc_goto_table = [ - 78, 181, 98, 54, 113, 76, 163, 71, 122, 193, - 217, 121, 150, 143, 248, 49, 55, 57, 58, 43, - 1, 248, 2, 74, 210, 86, 86, 86, 86, 225, - 230, 4, 42, 225, 225, 93, 166, 82, 87, 88, - 89, 5, 118, 78, 142, 40, 114, 113, 119, 96, - 121, 190, 94, 246, 201, 205, 206, 126, 10, 237, - 252, 74, 74, 238, 11, 51, 100, 132, 226, 242, - 121, 113, 174, 86, 86, 107, 233, 156, 108, 157, - 251, 109, 158, 78, 110, 118, 138, 256, 141, 159, - 111, 160, 70, 75, 139, 116, 124, 260, 208, 227, - 212, 244, 74, 140, 74, 130, 172, 118, 105, 154, - 86, 149, 86, 197, 239, 127, 169, nil, nil, nil, - nil, nil, nil, nil, nil, 192, nil, nil, 74, nil, - 184, nil, 86, nil, nil, nil, nil, 198, nil, nil, - 209, nil, nil, nil, nil, nil, nil, nil, nil, 223, - nil, nil, nil, 213, nil, nil, 169, 219, nil, nil, + 78, 76, 98, 54, 181, 163, 121, 195, 71, 113, + 150, 185, 219, 43, 122, 143, 227, 49, 1, 2, + 227, 227, 251, 74, 212, 86, 86, 86, 86, 251, + 4, 42, 233, 82, 87, 88, 89, 93, 166, 55, + 57, 58, 118, 78, 119, 121, 94, 114, 5, 192, + 142, 96, 113, 203, 207, 208, 249, 229, 40, 240, + 126, 74, 74, 255, 10, 121, 11, 51, 241, 228, + 245, 100, 132, 86, 86, 174, 113, 236, 107, 156, + 108, 157, 109, 78, 141, 118, 254, 138, 158, 110, + 159, 111, 160, 259, 70, 75, 139, 116, 124, 210, + 230, 214, 74, 263, 74, 247, 140, 118, 130, 172, + 86, 105, 86, 154, 149, 199, 169, 242, 127, nil, + nil, nil, nil, nil, nil, 194, nil, nil, 74, nil, + 186, nil, 86, nil, nil, nil, nil, 200, nil, nil, + nil, nil, 211, nil, nil, nil, nil, nil, nil, nil, + nil, 225, nil, nil, nil, 215, nil, nil, 169, 221, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, 184, nil, nil, 229, nil, nil, + nil, nil, nil, nil, nil, nil, 186, nil, nil, 232, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, 247, nil, nil, nil, nil, nil, nil, nil, nil, - 219, nil, 249, nil, nil, nil, 257, 219, nil, 253, - 259 ] + nil, nil, nil, nil, 250, nil, nil, nil, nil, nil, + nil, nil, nil, 221, nil, 252, nil, nil, nil, 260, + 221, nil, 256, 262 ] racc_goto_check = [ - 44, 41, 45, 36, 35, 51, 40, 34, 56, 46, - 62, 57, 61, 39, 65, 10, 14, 14, 14, 58, - 1, 65, 2, 36, 46, 36, 36, 36, 36, 68, - 62, 3, 4, 68, 68, 5, 39, 33, 33, 33, - 33, 6, 44, 44, 56, 7, 34, 35, 51, 10, - 57, 61, 58, 62, 22, 22, 22, 8, 9, 46, - 62, 36, 36, 41, 11, 12, 13, 15, 40, 46, - 57, 35, 16, 36, 36, 17, 40, 18, 23, 24, - 41, 25, 26, 44, 27, 44, 34, 41, 51, 28, - 29, 30, 31, 32, 37, 38, 42, 41, 43, 47, - 48, 49, 36, 50, 36, 52, 53, 44, 54, 55, - 36, 60, 36, 63, 64, 67, 44, nil, nil, nil, - nil, nil, nil, nil, nil, 45, nil, nil, 36, nil, - 44, nil, 36, nil, nil, nil, nil, 44, nil, nil, - 45, nil, nil, nil, nil, nil, nil, nil, nil, 45, - nil, nil, nil, 44, nil, nil, 44, 44, nil, nil, + 46, 53, 47, 36, 41, 40, 59, 48, 34, 35, + 63, 45, 64, 60, 58, 39, 70, 10, 1, 2, + 70, 70, 67, 36, 48, 36, 36, 36, 36, 67, + 3, 4, 64, 33, 33, 33, 33, 5, 39, 14, + 14, 14, 46, 46, 53, 59, 60, 34, 6, 63, + 58, 10, 35, 22, 22, 22, 64, 45, 7, 48, + 8, 36, 36, 64, 9, 59, 11, 12, 41, 40, + 48, 13, 15, 36, 36, 16, 35, 40, 17, 18, + 23, 24, 25, 46, 53, 46, 41, 34, 26, 27, + 28, 29, 30, 41, 31, 32, 37, 38, 42, 43, + 49, 50, 36, 41, 36, 51, 52, 46, 54, 55, + 36, 56, 36, 57, 62, 65, 46, 66, 69, nil, + nil, nil, nil, nil, nil, 47, nil, nil, 36, nil, + 46, nil, 36, nil, nil, nil, nil, 46, nil, nil, + nil, nil, 47, nil, nil, nil, nil, nil, nil, nil, + nil, 47, nil, nil, nil, 46, nil, nil, 46, 46, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, 44, nil, nil, 44, nil, nil, + nil, nil, nil, nil, nil, nil, 46, nil, nil, 46, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, 45, nil, nil, nil, nil, nil, nil, nil, nil, - 44, nil, 44, nil, nil, nil, 45, 44, nil, 44, - 45 ] + nil, nil, nil, nil, 47, nil, nil, nil, nil, nil, + nil, nil, nil, 46, nil, 46, nil, nil, nil, 47, + 46, nil, 46, 47 ] racc_goto_pointer = [ - nil, 20, 22, 29, 23, -7, 39, 39, -35, 54, - 5, 60, 52, 15, 2, -39, -83, 15, -56, nil, - nil, nil, -123, 17, -55, 19, -53, 21, -47, 26, - -46, 59, 59, 2, -26, -67, -10, -22, 21, -110, - -139, -160, 5, -85, -34, -44, -160, -112, -86, -130, - -13, -29, 1, -47, 52, -22, -76, -72, 10, nil, - -17, -116, -181, -57, -110, -222, nil, 20, -172 ] + nil, 18, 19, 28, 22, -5, 46, 52, -32, 60, + 7, 62, 54, 20, 25, -34, -80, 18, -54, nil, + nil, nil, -124, 19, -53, 20, -47, 26, -46, 27, + -45, 61, 61, -2, -25, -62, -10, -20, 23, -108, + -140, -157, 7, -84, nil, -153, -34, -44, -162, -113, + -87, -129, -10, -33, 4, -44, 55, -18, -70, -77, + 4, nil, -14, -118, -181, -55, -109, -217, nil, 23, + -187 ] racc_goto_default = [ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 45, nil, nil, nil, nil, nil, nil, nil, 22, 23, 24, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 73, 79, nil, nil, nil, - nil, nil, 46, 164, 203, nil, nil, nil, nil, nil, - 80, nil, nil, nil, nil, nil, 83, 85, nil, 44, - nil, nil, nil, nil, nil, 218, 220, nil, 202 ] + nil, nil, 46, 164, 184, nil, 205, nil, nil, nil, + nil, nil, 80, nil, nil, nil, nil, nil, 83, 85, + nil, 44, nil, nil, nil, nil, nil, 220, 222, nil, + 204 ] racc_reduce_table = [ 0, 0, :racc_error, @@ -991,92 +993,94 @@ def raise_parse_error(error_message, location) 8, 79, :_reduce_64, 1, 97, :_reduce_65, 3, 97, :_reduce_66, - 1, 98, :_reduce_67, - 3, 98, :_reduce_68, - 0, 101, :_reduce_69, - 1, 101, :_reduce_70, - 3, 101, :_reduce_71, - 3, 101, :_reduce_72, - 6, 101, :_reduce_73, - 0, 106, :_reduce_74, - 0, 107, :_reduce_75, - 7, 101, :_reduce_76, - 3, 101, :_reduce_77, - 5, 101, :_reduce_78, + 0, 103, :_reduce_none, + 1, 103, :_reduce_none, + 2, 98, :_reduce_69, + 4, 98, :_reduce_70, + 0, 101, :_reduce_71, + 1, 101, :_reduce_72, + 3, 101, :_reduce_73, + 3, 101, :_reduce_74, + 6, 101, :_reduce_75, + 0, 108, :_reduce_76, + 0, 109, :_reduce_77, + 7, 101, :_reduce_78, + 3, 101, :_reduce_79, + 4, 102, :_reduce_80, 0, 95, :_reduce_none, - 1, 95, :_reduce_80, - 1, 90, :_reduce_81, - 2, 90, :_reduce_82, - 3, 90, :_reduce_83, - 1, 109, :_reduce_84, - 2, 109, :_reduce_85, - 1, 102, :_reduce_none, - 1, 102, :_reduce_none, - 0, 110, :_reduce_88, - 0, 111, :_reduce_89, - 6, 72, :_reduce_90, - 0, 112, :_reduce_91, - 0, 113, :_reduce_92, - 5, 72, :_reduce_93, - 1, 91, :_reduce_94, - 2, 91, :_reduce_95, - 3, 91, :_reduce_96, - 1, 114, :_reduce_97, - 2, 114, :_reduce_98, - 1, 115, :_reduce_none, - 1, 94, :_reduce_100, - 1, 94, :_reduce_101, + 1, 95, :_reduce_82, + 1, 90, :_reduce_83, + 2, 90, :_reduce_84, + 3, 90, :_reduce_85, + 1, 111, :_reduce_86, + 2, 111, :_reduce_87, + 1, 104, :_reduce_none, + 1, 104, :_reduce_none, + 0, 112, :_reduce_90, + 0, 113, :_reduce_91, + 6, 72, :_reduce_92, + 0, 114, :_reduce_93, + 0, 115, :_reduce_94, + 5, 72, :_reduce_95, + 1, 91, :_reduce_96, + 2, 91, :_reduce_97, + 3, 91, :_reduce_98, + 1, 116, :_reduce_99, + 2, 116, :_reduce_100, + 1, 117, :_reduce_none, + 1, 94, :_reduce_102, + 1, 94, :_reduce_103, 1, 62, :_reduce_none, 2, 62, :_reduce_none, - 2, 116, :_reduce_none, - 2, 116, :_reduce_none, - 4, 117, :_reduce_106, - 1, 118, :_reduce_107, - 3, 118, :_reduce_108, - 0, 119, :_reduce_109, - 1, 119, :_reduce_110, - 3, 119, :_reduce_111, - 5, 119, :_reduce_112, - 7, 119, :_reduce_113, - 0, 121, :_reduce_114, - 0, 122, :_reduce_115, - 8, 119, :_reduce_116, - 3, 119, :_reduce_117, - 1, 104, :_reduce_118, - 1, 104, :_reduce_119, - 1, 104, :_reduce_120, - 1, 105, :_reduce_121, - 3, 105, :_reduce_122, - 2, 105, :_reduce_123, - 4, 105, :_reduce_124, - 1, 120, :_reduce_125, - 3, 120, :_reduce_126, - 2, 120, :_reduce_127, - 4, 120, :_reduce_128, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 124, :_reduce_131, - 1, 124, :_reduce_132, - 0, 103, :_reduce_none, - 3, 103, :_reduce_134, + 2, 118, :_reduce_none, + 2, 118, :_reduce_none, + 4, 119, :_reduce_108, + 1, 120, :_reduce_109, + 3, 120, :_reduce_110, + 0, 121, :_reduce_111, + 1, 121, :_reduce_112, + 3, 121, :_reduce_113, + 5, 121, :_reduce_114, + 7, 121, :_reduce_115, + 0, 123, :_reduce_116, + 0, 124, :_reduce_117, + 8, 121, :_reduce_118, + 3, 121, :_reduce_119, + 1, 106, :_reduce_120, + 1, 106, :_reduce_121, + 1, 106, :_reduce_122, + 1, 107, :_reduce_123, + 3, 107, :_reduce_124, + 2, 107, :_reduce_125, + 4, 107, :_reduce_126, + 1, 122, :_reduce_127, + 3, 122, :_reduce_128, + 2, 122, :_reduce_129, + 4, 122, :_reduce_130, + 1, 125, :_reduce_none, + 1, 125, :_reduce_none, + 1, 126, :_reduce_133, + 1, 126, :_reduce_134, + 0, 105, :_reduce_none, + 3, 105, :_reduce_136, 1, 100, :_reduce_none, 0, 63, :_reduce_none, - 0, 125, :_reduce_137, - 3, 63, :_reduce_138, + 0, 127, :_reduce_139, + 3, 63, :_reduce_140, 1, 70, :_reduce_none, 0, 71, :_reduce_none, 1, 71, :_reduce_none, 1, 71, :_reduce_none, 1, 71, :_reduce_none, - 1, 80, :_reduce_144, - 2, 80, :_reduce_145, - 1, 126, :_reduce_none, - 1, 126, :_reduce_none, - 1, 108, :_reduce_148 ] + 1, 80, :_reduce_146, + 2, 80, :_reduce_147, + 1, 128, :_reduce_none, + 1, 128, :_reduce_none, + 1, 110, :_reduce_150 ] -racc_reduce_n = 149 +racc_reduce_n = 151 -racc_shift_n = 261 +racc_shift_n = 264 racc_token_table = { false => 0, @@ -1262,6 +1266,8 @@ def raise_parse_error(error_message, location) "\"-option@TAG\"", "id_colon", "rule_rhs", + "if_clause", + "\"-option@if_clause\"", "symbol", "named_ref_opt", "parameterizing_suffix", @@ -1763,26 +1769,32 @@ def _reduce_66(val, _values, result) end .,., +# reduce 67 omitted + +# reduce 68 omitted + module_eval(<<'.,.,', 'parser.y', 257) - def _reduce_67(val, _values, result) + def _reduce_69(val, _values, result) builder = val[0] + builder.symbols << val[1] if val[1] result = [builder] result end .,., -module_eval(<<'.,.,', 'parser.y', 262) - def _reduce_68(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 263) + def _reduce_70(val, _values, result) builder = val[2] + builder.symbols << val[3] if val[3] result = val[0].append(builder) result end .,., -module_eval(<<'.,.,', 'parser.y', 268) - def _reduce_69(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 270) + def _reduce_71(val, _values, result) reset_precs result = Grammar::ParameterizingRule::Rhs.new @@ -1790,8 +1802,8 @@ def _reduce_69(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 273) - def _reduce_70(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 275) + def _reduce_72(val, _values, result) reset_precs result = Grammar::ParameterizingRule::Rhs.new @@ -1799,8 +1811,8 @@ def _reduce_70(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 278) - def _reduce_71(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 280) + def _reduce_73(val, _values, result) token = val[1] token.alias_name = val[2] builder = val[0] @@ -1811,8 +1823,8 @@ def _reduce_71(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 286) - def _reduce_72(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 288) + def _reduce_74(val, _values, result) builder = val[0] builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]]) result = builder @@ -1821,8 +1833,8 @@ def _reduce_72(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 292) - def _reduce_73(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 294) + def _reduce_75(val, _values, result) builder = val[0] builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[5]) result = builder @@ -1831,8 +1843,8 @@ def _reduce_73(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 298) - def _reduce_74(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 300) + def _reduce_76(val, _values, result) if @prec_seen on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec @code_after_prec = true @@ -1843,16 +1855,16 @@ def _reduce_74(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 306) - def _reduce_75(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 308) + def _reduce_77(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 310) - def _reduce_76(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 312) + def _reduce_78(val, _values, result) user_code = val[3] user_code.alias_name = val[6] builder = val[0] @@ -1863,8 +1875,8 @@ def _reduce_76(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 318) - def _reduce_77(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 320) + def _reduce_79(val, _values, result) sym = @grammar.find_symbol_by_id!(val[2]) @prec_seen = true builder = val[0] @@ -1875,179 +1887,177 @@ def _reduce_77(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 326) - def _reduce_78(val, _values, result) - builder = val[0] - builder.symbols << Lrama::Lexer::Token::ControlSyntax.new(s_value: val[1], location: @lexer.location, condition: val[3]) - result = builder +module_eval(<<'.,.,', 'parser.y', 329) + def _reduce_80(val, _values, result) + result = Lrama::Lexer::Token::ControlSyntax.new(s_value: val[0], location: @lexer.location, condition: val[2]) result end .,., -# reduce 79 omitted +# reduce 81 omitted -module_eval(<<'.,.,', 'parser.y', 332) - def _reduce_80(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 333) + def _reduce_82(val, _values, result) result = val[0].s_value result end .,., -module_eval(<<'.,.,', 'parser.y', 336) - def _reduce_81(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 337) + def _reduce_83(val, _values, result) result = [{tag: nil, tokens: val[0]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 340) - def _reduce_82(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 341) + def _reduce_84(val, _values, result) result = [{tag: val[0], tokens: val[1]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 344) - def _reduce_83(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 345) + def _reduce_85(val, _values, result) result = val[0].append({tag: val[1], tokens: val[2]}) result end .,., -module_eval(<<'.,.,', 'parser.y', 347) - def _reduce_84(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 348) + def _reduce_86(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 348) - def _reduce_85(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 349) + def _reduce_87(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 86 omitted +# reduce 88 omitted -# reduce 87 omitted +# reduce 89 omitted -module_eval(<<'.,.,', 'parser.y', 355) - def _reduce_88(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 356) + def _reduce_90(val, _values, result) begin_c_declaration("}") result end .,., -module_eval(<<'.,.,', 'parser.y', 359) - def _reduce_89(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 360) + def _reduce_91(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 363) - def _reduce_90(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 364) + def _reduce_92(val, _values, result) result = val[0].append(val[3]) result end .,., -module_eval(<<'.,.,', 'parser.y', 367) - def _reduce_91(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 368) + def _reduce_93(val, _values, result) begin_c_declaration("}") result end .,., -module_eval(<<'.,.,', 'parser.y', 371) - def _reduce_92(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 372) + def _reduce_94(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 375) - def _reduce_93(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 376) + def _reduce_95(val, _values, result) result = [val[2]] result end .,., -module_eval(<<'.,.,', 'parser.y', 380) - def _reduce_94(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 381) + def _reduce_96(val, _values, result) result = [{tag: nil, tokens: val[0]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 384) - def _reduce_95(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 385) + def _reduce_97(val, _values, result) result = [{tag: val[0], tokens: val[1]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 388) - def _reduce_96(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 389) + def _reduce_98(val, _values, result) result = val[0].append({tag: val[1], tokens: val[2]}) result end .,., -module_eval(<<'.,.,', 'parser.y', 391) - def _reduce_97(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 392) + def _reduce_99(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 392) - def _reduce_98(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 393) + def _reduce_100(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 99 omitted +# reduce 101 omitted -module_eval(<<'.,.,', 'parser.y', 396) - def _reduce_100(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 397) + def _reduce_102(val, _values, result) on_action_error("ident after %prec", val[0]) if @prec_seen result end .,., -module_eval(<<'.,.,', 'parser.y', 397) - def _reduce_101(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 398) + def _reduce_103(val, _values, result) on_action_error("char after %prec", val[0]) if @prec_seen result end .,., -# reduce 102 omitted - -# reduce 103 omitted - # reduce 104 omitted # reduce 105 omitted -module_eval(<<'.,.,', 'parser.y', 407) - def _reduce_106(val, _values, result) +# reduce 106 omitted + +# reduce 107 omitted + +module_eval(<<'.,.,', 'parser.y', 408) + def _reduce_108(val, _values, result) lhs = val[0] lhs.alias_name = val[1] val[3].each do |builder| @@ -2060,8 +2070,8 @@ def _reduce_106(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 418) - def _reduce_107(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 419) + def _reduce_109(val, _values, result) builder = val[0] if !builder.line builder.line = @lexer.line - 1 @@ -2072,8 +2082,8 @@ def _reduce_107(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 426) - def _reduce_108(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 427) + def _reduce_110(val, _values, result) builder = val[2] if !builder.line builder.line = @lexer.line - 1 @@ -2084,8 +2094,8 @@ def _reduce_108(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 435) - def _reduce_109(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 436) + def _reduce_111(val, _values, result) reset_precs result = @grammar.create_rule_builder(@rule_counter, @midrule_action_counter) @@ -2093,8 +2103,8 @@ def _reduce_109(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 440) - def _reduce_110(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 441) + def _reduce_112(val, _values, result) reset_precs result = @grammar.create_rule_builder(@rule_counter, @midrule_action_counter) @@ -2102,8 +2112,8 @@ def _reduce_110(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 445) - def _reduce_111(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 446) + def _reduce_113(val, _values, result) token = val[1] token.alias_name = val[2] builder = val[0] @@ -2114,8 +2124,8 @@ def _reduce_111(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 453) - def _reduce_112(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 454) + def _reduce_114(val, _values, result) token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], alias_name: val[3], location: @lexer.location, args: [val[1]], lhs_tag: val[4]) builder = val[0] builder.add_rhs(token) @@ -2126,8 +2136,8 @@ def _reduce_112(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 461) - def _reduce_113(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 462) + def _reduce_115(val, _values, result) token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, alias_name: val[5], location: @lexer.location, args: val[3], lhs_tag: val[6]) builder = val[0] builder.add_rhs(token) @@ -2138,8 +2148,8 @@ def _reduce_113(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 469) - def _reduce_114(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 470) + def _reduce_116(val, _values, result) if @prec_seen on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec @code_after_prec = true @@ -2150,16 +2160,16 @@ def _reduce_114(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 477) - def _reduce_115(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 478) + def _reduce_117(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 481) - def _reduce_116(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 482) + def _reduce_118(val, _values, result) user_code = val[3] user_code.alias_name = val[6] user_code.tag = val[7] @@ -2171,8 +2181,8 @@ def _reduce_116(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 490) - def _reduce_117(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 491) + def _reduce_119(val, _values, result) sym = @grammar.find_symbol_by_id!(val[2]) @prec_seen = true builder = val[0] @@ -2183,116 +2193,116 @@ def _reduce_117(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 497) - def _reduce_118(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 498) + def _reduce_120(val, _values, result) result = "option" result end .,., -module_eval(<<'.,.,', 'parser.y', 498) - def _reduce_119(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 499) + def _reduce_121(val, _values, result) result = "nonempty_list" result end .,., -module_eval(<<'.,.,', 'parser.y', 499) - def _reduce_120(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 500) + def _reduce_122(val, _values, result) result = "list" result end .,., -module_eval(<<'.,.,', 'parser.y', 501) - def _reduce_121(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 502) + def _reduce_123(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 502) - def _reduce_122(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 503) + def _reduce_124(val, _values, result) result = val[0].append(val[2]) result end .,., -module_eval(<<'.,.,', 'parser.y', 503) - def _reduce_123(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 504) + def _reduce_125(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] result end .,., -module_eval(<<'.,.,', 'parser.y', 504) - def _reduce_124(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 505) + def _reduce_126(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] result end .,., -module_eval(<<'.,.,', 'parser.y', 506) - def _reduce_125(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 507) + def _reduce_127(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 507) - def _reduce_126(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 508) + def _reduce_128(val, _values, result) result = val[0].append(val[2]) result end .,., -module_eval(<<'.,.,', 'parser.y', 508) - def _reduce_127(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 509) + def _reduce_129(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] result end .,., -module_eval(<<'.,.,', 'parser.y', 509) - def _reduce_128(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 510) + def _reduce_130(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] result end .,., -# reduce 129 omitted +# reduce 131 omitted -# reduce 130 omitted +# reduce 132 omitted -module_eval(<<'.,.,', 'parser.y', 514) - def _reduce_131(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 515) + def _reduce_133(val, _values, result) result = Lrama::Lexer::Token::Ident.new(s_value: true) result end .,., -module_eval(<<'.,.,', 'parser.y', 515) - def _reduce_132(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 516) + def _reduce_134(val, _values, result) result = Lrama::Lexer::Token::Ident.new(s_value: false) result end .,., -# reduce 133 omitted +# reduce 135 omitted -module_eval(<<'.,.,', 'parser.y', 518) - def _reduce_134(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 519) + def _reduce_136(val, _values, result) result = val[1].s_value result end .,., -# reduce 135 omitted +# reduce 137 omitted -# reduce 136 omitted +# reduce 138 omitted -module_eval(<<'.,.,', 'parser.y', 525) - def _reduce_137(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 526) + def _reduce_139(val, _values, result) begin_c_declaration('\Z') @grammar.epilogue_first_lineno = @lexer.line + 1 @@ -2300,8 +2310,8 @@ def _reduce_137(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 530) - def _reduce_138(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 531) + def _reduce_140(val, _values, result) end_c_declaration @grammar.epilogue = val[2].s_value @@ -2309,36 +2319,36 @@ def _reduce_138(val, _values, result) end .,., -# reduce 139 omitted - -# reduce 140 omitted - # reduce 141 omitted # reduce 142 omitted # reduce 143 omitted -module_eval(<<'.,.,', 'parser.y', 541) - def _reduce_144(val, _values, result) +# reduce 144 omitted + +# reduce 145 omitted + +module_eval(<<'.,.,', 'parser.y', 542) + def _reduce_146(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 542) - def _reduce_145(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 543) + def _reduce_147(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 146 omitted +# reduce 148 omitted -# reduce 147 omitted +# reduce 149 omitted -module_eval(<<'.,.,', 'parser.y', 547) - def _reduce_148(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 548) + def _reduce_150(val, _values, result) result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) result end diff --git a/parser.y b/parser.y index 70e29f68..6642491b 100644 --- a/parser.y +++ b/parser.y @@ -253,14 +253,16 @@ rule rule_args: IDENTIFIER { result = [val[0]] } | rule_args "," IDENTIFIER { result = val[0].append(val[2]) } - rule_rhs_list: rule_rhs + rule_rhs_list: rule_rhs if_clause? { builder = val[0] + builder.symbols << val[1] if val[1] result = [builder] } - | rule_rhs_list "|" rule_rhs + | rule_rhs_list "|" rule_rhs if_clause? { builder = val[2] + builder.symbols << val[3] if val[3] result = val[0].append(builder) } @@ -322,11 +324,10 @@ rule builder.precedence_sym = sym result = builder } - | rule_rhs "%if" "(" IDENTIFIER ")" + + if_clause: "%if" "(" IDENTIFIER ")" { - builder = val[0] - builder.symbols << Lrama::Lexer::Token::ControlSyntax.new(s_value: val[1], location: @lexer.location, condition: val[3]) - result = builder + result = Lrama::Lexer::Token::ControlSyntax.new(s_value: val[0], location: @lexer.location, condition: val[2]) } alias: # empty From 77218fe798696241e5abd17a121fa5b09d9a8f52 Mon Sep 17 00:00:00 2001 From: ydah Date: Thu, 27 Jun 2024 21:21:18 +0900 Subject: [PATCH 4/5] Remove unused variable --- lib/lrama/grammar.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/lrama/grammar.rb b/lib/lrama/grammar.rb index 9478977f..3724f828 100644 --- a/lib/lrama/grammar.rb +++ b/lib/lrama/grammar.rb @@ -57,7 +57,6 @@ def initialize(rule_counter) @aux = Auxiliary.new @no_stdlib = false @locations = false - @if_count = 0 append_special_symbols end From 78e623106d7bc61479e9899db725608497f56387 Mon Sep 17 00:00:00 2001 From: ydah Date: Wed, 21 Aug 2024 23:26:05 +0900 Subject: [PATCH 5/5] Use `if_clause` instead of symbols --- lib/lrama/grammar/parameterizing_rule/rhs.rb | 10 ++++++---- lib/lrama/parser.rb | 4 ++-- parser.y | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/lrama/grammar/parameterizing_rule/rhs.rb b/lib/lrama/grammar/parameterizing_rule/rhs.rb index b1b4a83d..a5c6ef35 100644 --- a/lib/lrama/grammar/parameterizing_rule/rhs.rb +++ b/lib/lrama/grammar/parameterizing_rule/rhs.rb @@ -4,18 +4,20 @@ module Lrama class Grammar class ParameterizingRule class Rhs - attr_accessor :symbols, :user_code, :precedence_sym + attr_accessor :symbols, :user_code, :precedence_sym, :if_clause def initialize @symbols = [] @user_code = nil @precedence_sym = nil + @if_clause = nil end def skip?(bindings) - return false unless @symbols.last - last_sym = bindings.resolve_symbol(@symbols.last) - last_sym.is_a?(Lexer::Token::ControlSyntax) && last_sym.if? && last_sym.false? + return false unless @if_clause + + resolved = bindings.resolve_symbol(@if_clause) + resolved.is_a?(Lexer::Token::ControlSyntax) && resolved.if? && resolved.false? end def resolve_user_code(bindings) diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index 3e84c0a5..1507395b 100644 --- a/lib/lrama/parser.rb +++ b/lib/lrama/parser.rb @@ -1689,7 +1689,7 @@ def _reduce_61(val, _values, result) module_eval(<<'.,.,', 'parser.y', 201) def _reduce_64(val, _values, result) builder = val[0] - builder.symbols << val[1] if val[1] + builder.if_clause = val[1] result = [builder] result @@ -1699,7 +1699,7 @@ def _reduce_64(val, _values, result) module_eval(<<'.,.,', 'parser.y', 207) def _reduce_65(val, _values, result) builder = val[2] - builder.symbols << val[3] if val[3] + builder.if_clause = val[3] result = val[0].append(builder) result diff --git a/parser.y b/parser.y index aab9d252..75351b9c 100644 --- a/parser.y +++ b/parser.y @@ -200,13 +200,13 @@ rule rule_rhs_list: rule_rhs if_clause? { builder = val[0] - builder.symbols << val[1] if val[1] + builder.if_clause = val[1] result = [builder] } | rule_rhs_list "|" rule_rhs if_clause? { builder = val[2] - builder.symbols << val[3] if val[3] + builder.if_clause = val[3] result = val[0].append(builder) }