diff --git a/lib/lrama/grammar.rb b/lib/lrama/grammar.rb index 8da205e4..49adcf21 100644 --- a/lib/lrama/grammar.rb +++ b/lib/lrama/grammar.rb @@ -46,12 +46,12 @@ def add_percent_code(id:, code:) @percent_codes << PercentCode.new(id, code) end - def add_printer(ident_or_tags:, code:, lineno:) - @printers << Printer.new(ident_or_tags: ident_or_tags, code: code, lineno: lineno) + def add_printer(ident_or_tags:, token_code:, lineno:) + @printers << Printer.new(ident_or_tags: ident_or_tags, token_code: token_code, lineno: lineno) end - def add_error_token(ident_or_tags:, code:, lineno:) - @error_tokens << ErrorToken.new(ident_or_tags: ident_or_tags, code: code, lineno: lineno) + def add_error_token(ident_or_tags:, token_code:, lineno:) + @error_tokens << ErrorToken.new(ident_or_tags: ident_or_tags, token_code: token_code, lineno: lineno) end def add_term(id:, alias_name: nil, tag: nil, token_id: nil, replace: false) @@ -399,7 +399,7 @@ def normalize_rules accept = find_symbol_by_s_value!("$accept") eof = find_symbol_by_number!(0) lineno = @_rules.first ? @_rules.first[2] : 0 - @rules << Rule.new(id: @rules.count, lhs: accept, rhs: [@_rules.first[0], eof], code: nil, lineno: lineno) + @rules << Rule.new(id: @rules.count, lhs: accept, rhs: [@_rules.first[0], eof], token_code: nil, lineno: lineno) extracted_action_number = 1 # @n as nterm @@ -467,15 +467,14 @@ def normalize_rules # Extract actions in the middle of RHS # into new rules. a.each do |new_token, code| - @rules << Rule.new(id: @rules.count, lhs: new_token, rhs: [], code: Code::RuleAction.new(type: :rule_action, token_code: code), lineno: code.line) + @rules << Rule.new(id: @rules.count, lhs: new_token, rhs: [], token_code: code, lineno: code.line) end - c = code ? Code::RuleAction.new(type: :rule_action, token_code: code) : nil # Expand Parameterizing rules if rhs2.any? {|r| r.is_a?(Lrama::Lexer::Token::Parameterizing) } - expand_parameterizing_rules(lhs, rhs2, c, precedence_sym, lineno) + expand_parameterizing_rules(lhs, rhs2, code, precedence_sym, lineno) else - @rules << Rule.new(id: @rules.count, lhs: lhs, rhs: rhs2, code: c, precedence_sym: precedence_sym, lineno: lineno) + @rules << Rule.new(id: @rules.count, lhs: lhs, rhs: rhs2, token_code: code, precedence_sym: precedence_sym, lineno: lineno) end add_nterm(id: lhs) a.each do |new_token, _| @@ -489,21 +488,21 @@ def expand_parameterizing_rules(lhs, rhs, code, precedence_sym, lineno) if rhs.any? {|r| r.is_a?(Lrama::Lexer::Token::Parameterizing) && r.option? } option_token = Lrama::Lexer::Token::Ident.new(s_value: "option_#{rhs[0].s_value}") add_term(id: option_token) - @rules << Rule.new(id: @rules.count, lhs: lhs, rhs: [option_token], code: code, precedence_sym: precedence_sym, lineno: lineno) - @rules << Rule.new(id: @rules.count, lhs: option_token, rhs: [], code: code, precedence_sym: precedence_sym, lineno: lineno) - @rules << Rule.new(id: @rules.count, lhs: option_token, rhs: [token], code: code, precedence_sym: precedence_sym, lineno: lineno) + @rules << Rule.new(id: @rules.count, lhs: lhs, rhs: [option_token], token_code: code, precedence_sym: precedence_sym, lineno: lineno) + @rules << Rule.new(id: @rules.count, lhs: option_token, rhs: [], token_code: code, precedence_sym: precedence_sym, lineno: lineno) + @rules << Rule.new(id: @rules.count, lhs: option_token, rhs: [token], token_code: code, precedence_sym: precedence_sym, lineno: lineno) elsif rhs.any? {|r| r.is_a?(Lrama::Lexer::Token::Parameterizing) && r.nonempty_list? } nonempty_list_token = Lrama::Lexer::Token::Ident.new(s_value: "nonempty_list_#{rhs[0].s_value}") add_term(id: nonempty_list_token) - @rules << Rule.new(id: @rules.count, lhs: lhs, rhs: [nonempty_list_token], code: code, precedence_sym: precedence_sym, lineno: lineno) - @rules << Rule.new(id: @rules.count, lhs: nonempty_list_token, rhs: [token], code: code, precedence_sym: precedence_sym, lineno: lineno) - @rules << Rule.new(id: @rules.count, lhs: nonempty_list_token, rhs: [nonempty_list_token, token], code: code, precedence_sym: precedence_sym, lineno: lineno) + @rules << Rule.new(id: @rules.count, lhs: lhs, rhs: [nonempty_list_token], token_code: code, precedence_sym: precedence_sym, lineno: lineno) + @rules << Rule.new(id: @rules.count, lhs: nonempty_list_token, rhs: [token], token_code: code, precedence_sym: precedence_sym, lineno: lineno) + @rules << Rule.new(id: @rules.count, lhs: nonempty_list_token, rhs: [nonempty_list_token, token], token_code: code, precedence_sym: precedence_sym, lineno: lineno) elsif rhs.any? {|r| r.is_a?(Lrama::Lexer::Token::Parameterizing) && r.list? } list_token = Lrama::Lexer::Token::Ident.new(s_value: "list_#{rhs[0].s_value}") add_term(id: list_token) - @rules << Rule.new(id: @rules.count, lhs: lhs, rhs: [list_token], code: code, precedence_sym: precedence_sym, lineno: lineno) - @rules << Rule.new(id: @rules.count, lhs: list_token, rhs: [], code: code, precedence_sym: precedence_sym, lineno: lineno) - @rules << Rule.new(id: @rules.count, lhs: list_token, rhs: [list_token, token], code: code, precedence_sym: precedence_sym, lineno: lineno) + @rules << Rule.new(id: @rules.count, lhs: lhs, rhs: [list_token], token_code: code, precedence_sym: precedence_sym, lineno: lineno) + @rules << Rule.new(id: @rules.count, lhs: list_token, rhs: [], token_code: code, precedence_sym: precedence_sym, lineno: lineno) + @rules << Rule.new(id: @rules.count, lhs: list_token, rhs: [list_token, token], token_code: code, precedence_sym: precedence_sym, lineno: lineno) end end @@ -604,8 +603,8 @@ def replace_token_with_symbol token_to_symbol(t) end - if rule.code - rule.code.references.each do |ref| + if rule.token_code + rule.token_code.references.each do |ref| next if ref.type == :at if !ref.referring_symbol.is_a?(Lrama::Lexer::Token::UserCode) @@ -708,9 +707,9 @@ def validate_no_declared_type_reference! errors = [] rules.each do |rule| - next unless rule.code + next unless rule.token_code - rule.code.references.select do |ref| + rule.token_code.references.select do |ref| ref.type == :dollar && !ref.tag end.each do |ref| errors << "$#{ref.value} of '#{rule.lhs.id.s_value}' has no declared type" diff --git a/lib/lrama/grammar/code/printer_code.rb b/lib/lrama/grammar/code/printer_code.rb index 5c4f1d06..f7be042d 100644 --- a/lib/lrama/grammar/code/printer_code.rb +++ b/lib/lrama/grammar/code/printer_code.rb @@ -2,7 +2,10 @@ module Lrama class Grammar class Code class PrinterCode < Code - attr_accessor :tag + def initialize(type: nil, token_code: nil, tag: nil) + super(type: type, token_code: token_code) + @tag = tag + end private diff --git a/lib/lrama/grammar/error_token.rb b/lib/lrama/grammar/error_token.rb index 62e19579..8efde7df 100644 --- a/lib/lrama/grammar/error_token.rb +++ b/lib/lrama/grammar/error_token.rb @@ -1,9 +1,8 @@ module Lrama class Grammar - class ErrorToken < Struct.new(:ident_or_tags, :code, :lineno, keyword_init: true) + class ErrorToken < Struct.new(:ident_or_tags, :token_code, :lineno, keyword_init: true) def translated_code(tag) - code.tag = tag - code.translated_code + Code::PrinterCode.new(type: :error_token, token_code: token_code, tag: tag).translated_code end end end diff --git a/lib/lrama/grammar/printer.rb b/lib/lrama/grammar/printer.rb index 2050aa6c..8984a96e 100644 --- a/lib/lrama/grammar/printer.rb +++ b/lib/lrama/grammar/printer.rb @@ -1,9 +1,8 @@ module Lrama class Grammar - class Printer < Struct.new(:ident_or_tags, :code, :lineno, keyword_init: true) + class Printer < Struct.new(:ident_or_tags, :token_code, :lineno, keyword_init: true) def translated_code(tag) - code.tag = tag - code.translated_code + Code::PrinterCode.new(type: :printer, token_code: token_code, tag: tag).translated_code end end end diff --git a/lib/lrama/grammar/rule.rb b/lib/lrama/grammar/rule.rb index c559388b..f82bab43 100644 --- a/lib/lrama/grammar/rule.rb +++ b/lib/lrama/grammar/rule.rb @@ -1,6 +1,6 @@ module Lrama class Grammar - class Rule < Struct.new(:id, :lhs, :rhs, :code, :nullable, :precedence_sym, :lineno, keyword_init: true) + class Rule < Struct.new(:id, :lhs, :rhs, :token_code, :nullable, :precedence_sym, :lineno, keyword_init: true) # TODO: Change this to display_name def to_s l = lhs.id.s_value @@ -32,7 +32,9 @@ def initial_rule? end def translated_code - code&.translated_code + return nil unless token_code + + Code::RuleAction.new(type: :rule_action, token_code: token_code).translated_code end end end diff --git a/lib/lrama/output.rb b/lib/lrama/output.rb index 3c97ff4b..f6720850 100644 --- a/lib/lrama/output.rb +++ b/lib/lrama/output.rb @@ -186,9 +186,9 @@ def user_actions str = "" @context.states.rules.each do |rule| - next unless rule.code + next unless rule.token_code - code = rule.code + code = rule.token_code spaces = " " * (code.column - 1) str << <<-STR diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index 0dd17707..64932b76 100644 --- a/lib/lrama/parser.rb +++ b/lib/lrama/parser.rb @@ -1345,7 +1345,7 @@ def _reduce_32(val, _values, result) def _reduce_33(val, _values, result) @grammar.add_printer( ident_or_tags: val[6], - code: Grammar::Code::PrinterCode.new(type: :printer, token_code: val[3]), + token_code: val[3], lineno: val[3].line ) @@ -1373,7 +1373,7 @@ def _reduce_35(val, _values, result) def _reduce_36(val, _values, result) @grammar.add_error_token( ident_or_tags: val[6], - code: Grammar::Code::PrinterCode.new(type: :error_token, token_code: val[3]), + token_code: val[3], lineno: val[3].line ) diff --git a/parser.y b/parser.y index 12eec640..0361e0e2 100644 --- a/parser.y +++ b/parser.y @@ -108,7 +108,7 @@ rule { @grammar.add_printer( ident_or_tags: val[6], - code: Grammar::Code::PrinterCode.new(type: :printer, token_code: val[3]), + token_code: val[3], lineno: val[3].line ) } @@ -124,7 +124,7 @@ rule { @grammar.add_error_token( ident_or_tags: val[6], - code: Grammar::Code::PrinterCode.new(type: :error_token, token_code: val[3]), + token_code: val[3], lineno: val[3].line ) } diff --git a/spec/lrama/grammar/code_spec.rb b/spec/lrama/grammar/code_spec.rb index 7310ec1d..0a5ed20e 100644 --- a/spec/lrama/grammar/code_spec.rb +++ b/spec/lrama/grammar/code_spec.rb @@ -60,26 +60,22 @@ let(:tag) { token_class::Tag.new(s_value: '') } it "translats '$$' to '((*yyvaluep).val)'" do - code = described_class.new(type: :printer, token_code: user_code_dollar_dollar) - code.tag = tag + code = described_class.new(type: :printer, token_code: user_code_dollar_dollar, tag: tag) expect(code.translated_code).to eq("print(((*yyvaluep).val));") end it "translats '@$' to '(*yylocationp)'" do - code = described_class.new(type: :printer, token_code: user_code_at_dollar) - code.tag = tag + code = described_class.new(type: :printer, token_code: user_code_at_dollar, tag: tag) expect(code.translated_code).to eq("print((*yylocationp));") end it "raises error for '$n'" do - code = described_class.new(type: :printer, token_code: user_code_dollar_n) - code.tag = tag + code = described_class.new(type: :printer, token_code: user_code_dollar_n, tag: tag) expect { code.translated_code }.to raise_error("$n can not be used in printer.") end it "raises error for '@n'" do - code = described_class.new(type: :printer, token_code: user_code_at_n) - code.tag = tag + code = described_class.new(type: :printer, token_code: user_code_at_n, tag: tag) expect { code.translated_code }.to raise_error("@n can not be used in printer.") end end diff --git a/spec/lrama/parser_spec.rb b/spec/lrama/parser_spec.rb index 0bd4157e..f3bb3c74 100644 --- a/spec/lrama/parser_spec.rb +++ b/spec/lrama/parser_spec.rb @@ -56,12 +56,12 @@ expect(grammar.printers).to eq([ Printer.new( ident_or_tags: [T::Tag.new(s_value: "")], - code: Code::PrinterCode.new(type: :printer, token_code: T::UserCode.new(s_value: "\n print_int();\n")), + token_code: T::UserCode.new(s_value: "\n print_int();\n"), lineno: 15 ), Printer.new( ident_or_tags: [T::Ident.new(s_value: "tNUMBER"), T::Ident.new(s_value: "tSTRING")], - code: Code::PrinterCode.new(type: :printer, token_code: T::UserCode.new(s_value: "\n print_token();\n")), + token_code: T::UserCode.new(s_value: "\n print_token();\n"), lineno: 18 ), ]) @@ -216,7 +216,7 @@ grammar.find_symbol_by_s_value!("program"), grammar.find_symbol_by_s_value!("EOI"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("EOI"), lineno: 57, @@ -227,7 +227,7 @@ rhs: [ grammar.find_symbol_by_s_value!("class"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: nil, lineno: 57, @@ -239,7 +239,7 @@ grammar.find_symbol_by_s_value!("'+'"), grammar.find_symbol_by_s_value!("strings_1"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("'+'"), lineno: 58, @@ -251,7 +251,7 @@ grammar.find_symbol_by_s_value!("'-'"), grammar.find_symbol_by_s_value!("strings_2"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("'-'"), lineno: 59, @@ -264,7 +264,7 @@ grammar.find_symbol_by_s_value!("tSTRING"), grammar.find_symbol_by_s_value!("keyword_end"), ], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " code 1 ")), + token_code: T::UserCode.new(s_value: " code 1 "), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("tPLUS"), lineno: 62, @@ -273,7 +273,7 @@ id: 5, lhs: grammar.find_symbol_by_s_value!("$@1"), rhs: [], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " code 2 ")), + token_code: T::UserCode.new(s_value: " code 2 "), nullable: true, precedence_sym: nil, lineno: 64, @@ -282,7 +282,7 @@ id: 6, lhs: grammar.find_symbol_by_s_value!("$@2"), rhs: [], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " code 3 ")), + token_code: T::UserCode.new(s_value: " code 3 "), nullable: true, precedence_sym: nil, lineno: 64, @@ -298,7 +298,7 @@ grammar.find_symbol_by_s_value!("keyword_end"), grammar.find_symbol_by_s_value!("$@2"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("tEQ"), lineno: 64, @@ -307,7 +307,7 @@ id: 8, lhs: grammar.find_symbol_by_s_value!("$@3"), rhs: [], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " code 4 ")), + token_code: T::UserCode.new(s_value: " code 4 "), nullable: true, precedence_sym: nil, lineno: 65, @@ -316,7 +316,7 @@ id: 9, lhs: grammar.find_symbol_by_s_value!("$@4"), rhs: [], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " code 5 ")), + token_code: T::UserCode.new(s_value: " code 5 "), nullable: true, precedence_sym: nil, lineno: 65, @@ -332,7 +332,7 @@ grammar.find_symbol_by_s_value!("keyword_end"), grammar.find_symbol_by_s_value!("$@4"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("'>'"), lineno: 65, @@ -343,7 +343,7 @@ rhs: [ grammar.find_symbol_by_s_value!("string_1"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: nil, lineno: 68, @@ -354,7 +354,7 @@ rhs: [ grammar.find_symbol_by_s_value!("string_1"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: nil, lineno: 71, @@ -365,7 +365,7 @@ rhs: [ grammar.find_symbol_by_s_value!("string_2"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: nil, lineno: 72, @@ -376,7 +376,7 @@ rhs: [ grammar.find_symbol_by_s_value!("string"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: nil, lineno: 75, @@ -388,7 +388,7 @@ grammar.find_symbol_by_s_value!("string"), grammar.find_symbol_by_s_value!("'+'"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("'+'"), lineno: 78, @@ -399,7 +399,7 @@ rhs: [ grammar.find_symbol_by_s_value!("tSTRING"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("tSTRING"), lineno: 81, @@ -429,7 +429,7 @@ grammar.find_symbol_by_s_value!("program"), grammar.find_symbol_by_s_value!("YYEOF"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"), lineno: 15, @@ -440,7 +440,7 @@ rhs: [ grammar.find_symbol_by_s_value!("stmt"), ], - code: nil, + token_code: nil, nullable: true, precedence_sym: nil, lineno: 15, @@ -452,7 +452,7 @@ grammar.find_symbol_by_s_value!("expr"), grammar.find_symbol_by_s_value!("opt_semicolon"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: nil, lineno: 17, @@ -464,7 +464,7 @@ grammar.find_symbol_by_s_value!("opt_expr"), grammar.find_symbol_by_s_value!("opt_colon"), ], - code: nil, + token_code: nil, nullable: true, precedence_sym: nil, lineno: 18, @@ -473,7 +473,7 @@ id: 4, lhs: grammar.find_symbol_by_s_value!("stmt"), rhs: [], - code: nil, + token_code: nil, nullable: true, precedence_sym: nil, lineno: 19, @@ -484,7 +484,7 @@ rhs: [ grammar.find_symbol_by_s_value!("tNUMBER"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("tNUMBER"), lineno: 22, @@ -493,7 +493,7 @@ id: 6, lhs: grammar.find_symbol_by_s_value!("opt_expr"), rhs: [], - code: nil, + token_code: nil, nullable: true, precedence_sym: nil, lineno: 24, @@ -504,7 +504,7 @@ rhs: [ grammar.find_symbol_by_s_value!("expr"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: nil, lineno: 25, @@ -513,7 +513,7 @@ id: 8, lhs: grammar.find_symbol_by_s_value!("opt_semicolon"), rhs: [], - code: nil, + token_code: nil, nullable: true, precedence_sym: nil, lineno: 28, @@ -524,7 +524,7 @@ rhs: [ grammar.find_symbol_by_s_value!("';'"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("';'"), lineno: 29, @@ -533,7 +533,7 @@ id: 10, lhs: grammar.find_symbol_by_s_value!("opt_colon"), rhs: [], - code: nil, + token_code: nil, nullable: true, precedence_sym: nil, lineno: 32, @@ -544,7 +544,7 @@ rhs: [ grammar.find_symbol_by_s_value!("'.'"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("'.'"), lineno: 33, @@ -571,7 +571,7 @@ grammar.find_symbol_by_s_value!("program"), grammar.find_symbol_by_s_value!("YYEOF"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"), lineno: 20, @@ -582,7 +582,7 @@ rhs: [ grammar.find_symbol_by_s_value!("option_number"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("option_number"), lineno: 20, @@ -591,7 +591,7 @@ id: 2, lhs: grammar.find_symbol_by_s_value!("option_number"), rhs: [], - code: nil, + token_code: nil, nullable: true, precedence_sym: nil, lineno: 20, @@ -602,7 +602,7 @@ rhs: [ grammar.find_symbol_by_s_value!("number"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number"), lineno: 20, @@ -628,7 +628,7 @@ grammar.find_symbol_by_s_value!("program"), grammar.find_symbol_by_s_value!("YYEOF"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"), lineno: 20, @@ -639,7 +639,7 @@ rhs: [ grammar.find_symbol_by_s_value!("nonempty_list_number"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("nonempty_list_number"), lineno: 20, @@ -650,7 +650,7 @@ rhs: [ grammar.find_symbol_by_s_value!("number"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number"), lineno: 20, @@ -662,7 +662,7 @@ grammar.find_symbol_by_s_value!("nonempty_list_number"), grammar.find_symbol_by_s_value!("number"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number"), lineno: 20, @@ -688,7 +688,7 @@ grammar.find_symbol_by_s_value!("program"), grammar.find_symbol_by_s_value!("YYEOF"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"), lineno: 20, @@ -699,7 +699,7 @@ rhs: [ grammar.find_symbol_by_s_value!("list_number"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("list_number"), lineno: 20, @@ -708,7 +708,7 @@ id: 2, lhs: grammar.find_symbol_by_s_value!("list_number"), rhs: [], - code: nil, + token_code: nil, nullable: true, precedence_sym: nil, lineno: 20, @@ -720,7 +720,7 @@ grammar.find_symbol_by_s_value!("list_number"), grammar.find_symbol_by_s_value!("number"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number"), lineno: 20, @@ -857,7 +857,7 @@ class : keyword_class { code 1 } tSTRING { code 2 } keyword_end { code 3 } grammar.find_symbol_by_s_value!("program"), grammar.find_symbol_by_s_value!("EOI"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("EOI"), lineno: 29, @@ -868,7 +868,7 @@ class : keyword_class { code 1 } tSTRING { code 2 } keyword_end { code 3 } rhs: [ grammar.find_symbol_by_s_value!("class"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: nil, lineno: 29, @@ -877,7 +877,7 @@ class : keyword_class { code 1 } tSTRING { code 2 } keyword_end { code 3 } id: 2, lhs: grammar.find_symbol_by_s_value!("$@1"), rhs: [], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " code 1 ")), + token_code: T::UserCode.new(s_value: " code 1 "), nullable: true, precedence_sym: nil, lineno: 31, @@ -886,7 +886,7 @@ class : keyword_class { code 1 } tSTRING { code 2 } keyword_end { code 3 } id: 3, lhs: grammar.find_symbol_by_s_value!("$@2"), rhs: [], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " code 2 ")), + token_code: T::UserCode.new(s_value: " code 2 "), nullable: true, precedence_sym: nil, lineno: 31, @@ -901,7 +901,7 @@ class : keyword_class { code 1 } tSTRING { code 2 } keyword_end { code 3 } grammar.find_symbol_by_s_value!("$@2"), grammar.find_symbol_by_s_value!("keyword_end"), ], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " code 3 ")), + token_code: T::UserCode.new(s_value: " code 3 "), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("keyword_end"), lineno: 31, @@ -914,7 +914,7 @@ class : keyword_class { code 1 } tSTRING { code 2 } keyword_end { code 3 } grammar.find_symbol_by_s_value!("tSTRING"), grammar.find_symbol_by_s_value!("keyword_end"), ], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " code 4 ")), + token_code: T::UserCode.new(s_value: " code 4 "), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("keyword_end"), lineno: 32, @@ -991,7 +991,7 @@ class : keyword_class %% INPUT grammar = Lrama::Parser.new(y, "parse.y").parse - codes = grammar.rules.map(&:code).compact + codes = grammar.rules.map(&:token_code).compact expect(codes.count).to eq(1) expect(codes[0].s_value).to eq(<<-STR.chomp) @@ -1018,7 +1018,7 @@ class : keyword_class %% INPUT grammar = Lrama::Parser.new(y, "parse.y").parse - codes = grammar.rules.map(&:code).compact + codes = grammar.rules.map(&:token_code).compact expect(codes.count).to eq(1) expect(codes[0].s_value).to eq(<<-STR.chomp) @@ -1167,7 +1167,7 @@ class : keyword_class tSTRING keyword_end { code 1 } grammar.find_symbol_by_s_value!("program"), grammar.find_symbol_by_s_value!("EOI"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("EOI"), lineno: 14, @@ -1178,7 +1178,7 @@ class : keyword_class tSTRING keyword_end { code 1 } rhs: [ grammar.find_symbol_by_s_value!("lambda"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: nil, lineno: 14, @@ -1187,7 +1187,7 @@ class : keyword_class tSTRING keyword_end { code 1 } id: 2, lhs: grammar.find_symbol_by_s_value!("@1"), rhs: [], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " $1 = 1; $$ = 2; ")), + token_code: T::UserCode.new(s_value: " $1 = 1; $$ = 2; "), nullable: true, precedence_sym: nil, lineno: 17, @@ -1196,7 +1196,7 @@ class : keyword_class tSTRING keyword_end { code 1 } id: 3, lhs: grammar.find_symbol_by_s_value!("@2"), rhs: [], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " $$ = 3; ")), + token_code: T::UserCode.new(s_value: " $$ = 3; "), nullable: true, precedence_sym: nil, lineno: 18, @@ -1205,7 +1205,7 @@ class : keyword_class tSTRING keyword_end { code 1 } id: 4, lhs: grammar.find_symbol_by_s_value!("$@3"), rhs: [], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " $$ = 4; ")), + token_code: T::UserCode.new(s_value: " $$ = 4; "), nullable: true, precedence_sym: nil, lineno: 19, @@ -1214,7 +1214,7 @@ class : keyword_class tSTRING keyword_end { code 1 } id: 5, lhs: grammar.find_symbol_by_s_value!("$@4"), rhs: [], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " 5; ")), + token_code: T::UserCode.new(s_value: " 5; "), nullable: true, precedence_sym: nil, lineno: 21, @@ -1231,7 +1231,7 @@ class : keyword_class tSTRING keyword_end { code 1 } grammar.find_symbol_by_s_value!("$@4"), grammar.find_symbol_by_s_value!("tBODY"), ], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " $2; $3; $5; $7; $$ = 1; ")), + token_code: T::UserCode.new(s_value: " $2; $3; $5; $7; $$ = 1; "), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("tBODY"), lineno: 16, @@ -1275,7 +1275,7 @@ class : keyword_class tSTRING keyword_end { code 1 } grammar.find_symbol_by_s_value!("program"), grammar.find_symbol_by_s_value!("EOI"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("EOI"), lineno: 14, @@ -1286,7 +1286,7 @@ class : keyword_class tSTRING keyword_end { code 1 } rhs: [ grammar.find_symbol_by_s_value!("emp"), ], - code: nil, + token_code: nil, nullable: true, precedence_sym: nil, lineno: 14, @@ -1296,7 +1296,7 @@ class : keyword_class tSTRING keyword_end { code 1 } lhs: grammar.find_symbol_by_s_value!("emp"), rhs: [ ], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " $$; ")), + token_code: T::UserCode.new(s_value: " $$; "), nullable: true, precedence_sym: nil, lineno: 17, @@ -1306,7 +1306,7 @@ class : keyword_class tSTRING keyword_end { code 1 } lhs: grammar.find_symbol_by_s_value!("emp"), rhs: [ ], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " @$; ")), + token_code: T::UserCode.new(s_value: " @$; "), nullable: true, precedence_sym: nil, lineno: 19, @@ -1316,7 +1316,7 @@ class : keyword_class tSTRING keyword_end { code 1 } lhs: grammar.find_symbol_by_s_value!("emp"), rhs: [ ], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " @0; ")), + token_code: T::UserCode.new(s_value: " @0; "), nullable: true, precedence_sym: nil, lineno: 21, @@ -1366,7 +1366,7 @@ class : keyword_class tSTRING keyword_end { code 1 } grammar.find_symbol_by_s_value!("input"), grammar.find_symbol_by_s_value!("YYEOF"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"), lineno: 14, @@ -1376,7 +1376,7 @@ class : keyword_class tSTRING keyword_end { code 1 } lhs: grammar.find_symbol_by_s_value!("input"), rhs: [ ], - code: nil, + token_code: nil, nullable: true, precedence_sym: nil, lineno: 14, @@ -1388,7 +1388,7 @@ class : keyword_class tSTRING keyword_end { code 1 } grammar.find_symbol_by_s_value!("input"), grammar.find_symbol_by_s_value!("line"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: nil, lineno: 15, @@ -1399,7 +1399,7 @@ class : keyword_class tSTRING keyword_end { code 1 } rhs: [ grammar.find_symbol_by_s_value!("'\\n'"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("'\\n'"), lineno: 18, @@ -1411,7 +1411,7 @@ class : keyword_class tSTRING keyword_end { code 1 } grammar.find_symbol_by_s_value!("expr"), grammar.find_symbol_by_s_value!("'\\n'"), ], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " printf(\"\\t%.10g\\n\", $expr); ")), + token_code: T::UserCode.new(s_value: " printf(\"\\t%.10g\\n\", $expr); "), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("'\\n'"), lineno: 19, @@ -1422,7 +1422,7 @@ class : keyword_class tSTRING keyword_end { code 1 } rhs: [ grammar.find_symbol_by_s_value!("NUM"), ], - code: nil, + token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("NUM"), lineno: 23, @@ -1435,7 +1435,7 @@ class : keyword_class tSTRING keyword_end { code 1 } grammar.find_symbol_by_s_value!("expr"), grammar.find_symbol_by_s_value!("'+'"), ], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " $result = $left + $right; ")), + token_code: T::UserCode.new(s_value: " $result = $left + $right; "), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("'+'"), lineno: 24, @@ -1448,7 +1448,7 @@ class : keyword_class tSTRING keyword_end { code 1 } grammar.find_symbol_by_s_value!("expr"), grammar.find_symbol_by_s_value!("'-'"), ], - code: Code::RuleAction.new(type: :rule_action, token_code: T::UserCode.new(s_value: " $$ = $1 - $2; ")), + token_code: T::UserCode.new(s_value: " $$ = $1 - $2; "), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("'-'"), lineno: 26, @@ -1623,7 +1623,7 @@ class : keyword_class tSTRING keyword_end %% INPUT grammar = Lrama::Parser.new(y, "parse.y").parse - codes = grammar.rules.map(&:code) + codes = grammar.rules.map(&:token_code) expect(codes.count).to eq(3) expect(codes[0]).to be nil