From c4b4ae33d441e608d83818171e5dc85be3af6b94 Mon Sep 17 00:00:00 2001 From: yui-knk Date: Fri, 6 Oct 2023 07:55:36 +0900 Subject: [PATCH] Remove surrounding braces from user code --- .github/workflows/test.yaml | 2 +- lib/lrama/grammar/union.rb | 4 +- lib/lrama/lexer.rb | 3 +- lib/lrama/output.rb | 16 +++---- spec/lrama/lexer_spec.rb | 70 ++++++++++++++--------------- spec/lrama/output_spec.rb | 66 ++++++++++++++-------------- spec/lrama/parser_spec.rb | 88 ++++++++++++++++++------------------- 7 files changed, 124 insertions(+), 125 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e8700cbe..7e5f5193 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -43,7 +43,7 @@ jobs: # Copy from https://github.com/ruby/ruby/blob/089227e94823542acfdafa68541d330eee42ffea/.github/workflows/check_misc.yml#L27 - name: Check for trailing spaces run: | - git grep -I -n '[ ]$' -- '*.rb' '*.[chy]' '*.rs' && exit 1 || : + git grep -I -n '[ ]$' -- '*.rb' '*.[chy]' '*.rs' ':!spec/' && exit 1 || : git grep -n '^[ ][ ]*$' -- '*.md' && exit 1 || : steep-check: runs-on: ubuntu-20.04 diff --git a/lib/lrama/grammar/union.rb b/lib/lrama/grammar/union.rb index 978cebf2..854bffb5 100644 --- a/lib/lrama/grammar/union.rb +++ b/lib/lrama/grammar/union.rb @@ -2,8 +2,8 @@ module Lrama class Grammar class Union < Struct.new(:code, :lineno, keyword_init: true) def braces_less_code - # Remove braces - code.s_value[1..-2] + # Braces is already removed by lexer + code.s_value end end end diff --git a/lib/lrama/lexer.rb b/lib/lrama/lexer.rb index 72ce9019..9bbe0440 100644 --- a/lib/lrama/lexer.rb +++ b/lib/lrama/lexer.rb @@ -196,7 +196,7 @@ def lex_user_code(ss, line, column, lines) first_column = column debug("Enter lex_user_code: #{line}") brace_count = 1 - str = "{" + str = "" # Array of [type, $n, tag, first column, last column] # TODO: Is it better to keep string, like "$$", and use gsub? references = [] @@ -247,7 +247,6 @@ def lex_user_code(ss, line, column, lines) debug("Return lex_user_code: #{line}") if brace_count == 0 - str << ss[0] user_code = Token.new(type: Token::User_code, s_value: str.freeze) user_code.line = first_line user_code.column = first_column diff --git a/lib/lrama/output.rb b/lib/lrama/output.rb index 2dcdae7b..916a4b1f 100644 --- a/lib/lrama/output.rb +++ b/lib/lrama/output.rb @@ -143,7 +143,7 @@ def symbol_actions_for_printer str << <<-STR case #{sym.enum_name}: /* #{sym.comment} */ #line #{sym.printer.lineno} "#{@grammar_file_path}" - #{sym.printer.translated_code(sym.tag)} + {#{sym.printer.translated_code(sym.tag)}} #line [@oline@] [@ofile@] break; @@ -160,7 +160,7 @@ def user_initial_action(comment = "") <<-STR #{comment} #line #{@grammar.initial_action.line} "#{@grammar_file_path}" - #{@grammar.initial_action.translated_code} + {#{@grammar.initial_action.translated_code}} STR end @@ -173,7 +173,7 @@ def symbol_actions_for_error_token str << <<-STR case #{sym.enum_name}: /* #{sym.comment} */ #line #{sym.error_token.lineno} "#{@grammar_file_path}" - #{sym.error_token.translated_code(sym.tag)} + {#{sym.error_token.translated_code(sym.tag)}} #line [@oline@] [@ofile@] break; @@ -197,7 +197,7 @@ def user_actions str << <<-STR case #{rule.id + 1}: /* #{rule.as_comment} */ #line #{code.line} "#{@grammar_file_path}" -#{spaces}#{rule.translated_code} +#{spaces}{#{rule.translated_code}} #line [@oline@] [@ofile@] break; @@ -212,14 +212,14 @@ def user_actions str end - def omit_braces_and_blanks(param) - param[1..-2].strip + def omit_blanks(param) + param.strip end # b4_parse_param def parse_param if @grammar.parse_param - omit_braces_and_blanks(@grammar.parse_param) + omit_blanks(@grammar.parse_param) else "" end @@ -227,7 +227,7 @@ def parse_param def lex_param if @grammar.lex_param - omit_braces_and_blanks(@grammar.lex_param) + omit_blanks(@grammar.lex_param) else "" end diff --git a/spec/lrama/lexer_spec.rb b/spec/lrama/lexer_spec.rb index 735a0493..5bdc2a04 100644 --- a/spec/lrama/lexer_spec.rb +++ b/spec/lrama/lexer_spec.rb @@ -110,26 +110,26 @@ class : keyword_class tSTRING keyword_end %prec tPLUS T.new(type: T::Ident, s_value: "verbose"), T.new(type: T::P_printer, s_value: "%printer"), - T.new(type: T::User_code, s_value: "{\n print_int();\n}"), + T.new(type: T::User_code, s_value: "\n print_int();\n"), T.new(type: T::Tag, s_value: ""), T.new(type: T::P_printer, s_value: "%printer"), - T.new(type: T::User_code, s_value: "{\n print_token();\n}"), + T.new(type: T::User_code, s_value: "\n print_token();\n"), T.new(type: T::Ident, s_value: "tNUMBER"), T.new(type: T::Ident, s_value: "tSTRING"), T.new(type: T::P_lex_param, s_value: "%lex-param"), - T.new(type: T::User_code, s_value: "{struct lex_params *p}"), + T.new(type: T::User_code, s_value: "struct lex_params *p"), T.new(type: T::P_parse_param, s_value: "%parse-param"), - T.new(type: T::User_code, s_value: "{struct parse_params *p}"), + T.new(type: T::User_code, s_value: "struct parse_params *p"), T.new(type: T::P_initial_action, s_value: "%initial-action"), - T.new(type: T::User_code, s_value: "{\n initial_action_func(@$);\n}"), + T.new(type: T::User_code, s_value: "\n initial_action_func(@$);\n"), T.new(type: T::Semicolon, s_value: ";"), T.new(type: T::P_union, s_value: "%union"), - T.new(type: T::User_code, s_value: "{\n int i;\n long l;\n char *str;\n}"), + T.new(type: T::User_code, s_value: "\n int i;\n long l;\n char *str;\n"), T.new(type: T::P_token, s_value: "%token"), T.new(type: T::Ident, s_value: "EOI"), @@ -218,25 +218,25 @@ class : keyword_class tSTRING keyword_end %prec tPLUS T.new(type: T::Ident, s_value: "keyword_end"), T.new(type: T::P_prec, s_value: "%prec"), T.new(type: T::Ident, s_value: "tPLUS"), - T.new(type: T::User_code, s_value: "{ code 1 }"), + T.new(type: T::User_code, s_value: " code 1 "), T.new(type: T::Bar, s_value: "|"), T.new(type: T::Ident, s_value: "keyword_class"), - T.new(type: T::User_code, s_value: "{ code 2 }"), + T.new(type: T::User_code, s_value: " code 2 "), T.new(type: T::Ident, s_value: "tSTRING"), T.new(type: T::Char, s_value: "'!'"), T.new(type: T::Ident, s_value: "keyword_end"), - T.new(type: T::User_code, s_value: "{ code 3 }"), + T.new(type: T::User_code, s_value: " code 3 "), T.new(type: T::P_prec, s_value: "%prec"), T.new(type: T::String, s_value: "\"=\""), T.new(type: T::Bar, s_value: "|"), T.new(type: T::Ident, s_value: "keyword_class"), - T.new(type: T::User_code, s_value: "{ code 4 }"), + T.new(type: T::User_code, s_value: " code 4 "), T.new(type: T::Ident, s_value: "tSTRING"), T.new(type: T::Char, s_value: "'?'"), T.new(type: T::Ident, s_value: "keyword_end"), - T.new(type: T::User_code, s_value: "{ code 5 }"), + T.new(type: T::User_code, s_value: " code 5 "), T.new(type: T::P_prec, s_value: "%prec"), T.new(type: T::Char, s_value: "'>'"), T.new(type: T::Semicolon, s_value: ";"), @@ -342,29 +342,29 @@ class : keyword_class tSTRING keyword_end %prec tPLUS expect(user_codes.map(&:references)).to eq([ [ - [:dollar, 1, T.new(type: T::Tag, s_value: ""), 2, 8], - [:dollar, "$", T.new(type: T::Tag, s_value: ""), 15, 21] + [:dollar, 1, T.new(type: T::Tag, s_value: ""), 1, 7], + [:dollar, "$", T.new(type: T::Tag, s_value: ""), 14, 20] ], [ - [:dollar, "$", T.new(type: T::Tag, s_value: ""), 2, 8] + [:dollar, "$", T.new(type: T::Tag, s_value: ""), 1, 7] ], [ - [:dollar, "$", T.new(type: T::Tag, s_value: ""), 2, 8] + [:dollar, "$", T.new(type: T::Tag, s_value: ""), 1, 7] ], [], [ - [:dollar, 2, nil, 2, 3], - [:dollar, 3, nil, 6, 7], - [:dollar, 5, nil, 10, 11], - [:dollar, 7, nil, 14, 15], - [:dollar, 10, nil, 18, 20], - [:dollar, "$", nil, 23, 24], - [:at, 2, nil, 43, 44], - [:at, 3, nil, 47, 48], - [:at, 5, nil, 51, 52], - [:at, 7, nil, 55, 56], - [:at, 10, nil, 59, 61], - [:at, "$", nil, 64, 65], + [:dollar, 2, nil, 1, 2], + [:dollar, 3, nil, 5, 6], + [:dollar, 5, nil, 9, 10], + [:dollar, 7, nil, 13, 14], + [:dollar, 10, nil, 17, 19], + [:dollar, "$", nil, 22, 23], + [:at, 2, nil, 42, 43], + [:at, 3, nil, 46, 47], + [:at, 5, nil, 50, 51], + [:at, 7, nil, 54, 55], + [:at, 10, nil, 58, 60], + [:at, "$", nil, 63, 64], ], ]) end @@ -394,7 +394,7 @@ class : keyword_class tSTRING keyword_end %prec tPLUS expect(lexer.grammar_rules_tokens).to eq([ T.new(type: T::Ident_Colon, s_value: "line"), T.new(type: T::Ident, s_value: "expr"), - T.new(type: T::User_code, s_value: %Q({ printf("\t%.10g\n", $expr); })), + T.new(type: T::User_code, s_value: %Q( printf("\t%.10g\n", $expr); )), T.new(type: T::Semicolon, s_value: ";"), T.new(type: T::Ident_Colon, s_value: "expr"), @@ -408,7 +408,7 @@ class : keyword_class tSTRING keyword_end %prec tPLUS T.new(type: T::Ident, s_value: "expr"), T.new(type: T::Named_Ref, s_value: "right"), T.new(type: T::Char, s_value: "'+'"), - T.new(type: T::User_code, s_value: "{ $result = $left + $right; }"), + T.new(type: T::User_code, s_value: " $result = $left + $right; "), T.new(type: T::Semicolon, s_value: ";"), ]) @@ -418,12 +418,12 @@ class : keyword_class tSTRING keyword_end %prec tPLUS expect(user_codes.map(&:references)).to eq([ [ - [:dollar, "expr", nil, 20, 24], + [:dollar, "expr", nil, 19, 23], ], [ - [:dollar, "result", nil, 2, 8], - [:dollar, "left", nil, 12, 16], - [:dollar, "right", nil, 20, 25], + [:dollar, "result", nil, 1, 7], + [:dollar, "left", nil, 11, 15], + [:dollar, "right", nil, 19, 24], ] ]) end @@ -463,13 +463,13 @@ class : keyword_class tSTRING keyword_end %prec tPLUS end expected = <<-CODE.chomp -{ + int i = 1; /* @ */ // @ int j = 1; /* $ */ // $ int k = 1; /* @1 */ // @1 int l = 1; /* $$ */ // $$ int m = 1; /* $2 */ // $2 - } + CODE expect(user_codes.map(&:s_value)).to eq([expected]) diff --git a/spec/lrama/output_spec.rb b/spec/lrama/output_spec.rb index 51263c60..7a143244 100644 --- a/spec/lrama/output_spec.rb +++ b/spec/lrama/output_spec.rb @@ -19,46 +19,46 @@ let(:grammar) { double("grammar") } describe "#parse_param" do - it "returns declaration of parse param without braces/blanks" do - allow(grammar).to receive(:parse_param).and_return("{struct parser_params *p}") + it "returns declaration of parse param without blanks" do + allow(grammar).to receive(:parse_param).and_return("struct parser_params *p") expect(output.parse_param).to eq("struct parser_params *p") - allow(grammar).to receive(:parse_param).and_return("{ struct parser_params *p }") + allow(grammar).to receive(:parse_param).and_return(" struct parser_params *p ") expect(output.parse_param).to eq("struct parser_params *p") - allow(grammar).to receive(:parse_param).and_return("{int i}") + allow(grammar).to receive(:parse_param).and_return("int i") expect(output.parse_param).to eq("int i") - allow(grammar).to receive(:parse_param).and_return("{ int i }") + allow(grammar).to receive(:parse_param).and_return(" int i ") expect(output.parse_param).to eq("int i") - allow(grammar).to receive(:parse_param).and_return("{int parse_param}") + allow(grammar).to receive(:parse_param).and_return("int parse_param") expect(output.parse_param).to eq("int parse_param") - allow(grammar).to receive(:parse_param).and_return("{ int parse_param }") + allow(grammar).to receive(:parse_param).and_return(" int parse_param ") expect(output.parse_param).to eq("int parse_param") end end describe "#user_formals" do context "when parse_param exists" do - it "returns declaration of parse param without braces/blanks with a leading comma" do - allow(grammar).to receive(:parse_param).and_return("{struct parser_params *p}") + it "returns declaration of parse param without blanks with a leading comma" do + allow(grammar).to receive(:parse_param).and_return("struct parser_params *p") expect(output.user_formals).to eq(", struct parser_params *p") - allow(grammar).to receive(:parse_param).and_return("{ struct parser_params *p }") + allow(grammar).to receive(:parse_param).and_return(" struct parser_params *p ") expect(output.user_formals).to eq(", struct parser_params *p") - allow(grammar).to receive(:parse_param).and_return("{int i}") + allow(grammar).to receive(:parse_param).and_return("int i") expect(output.user_formals).to eq(", int i") - allow(grammar).to receive(:parse_param).and_return("{ int i }") + allow(grammar).to receive(:parse_param).and_return(" int i ") expect(output.user_formals).to eq(", int i") - allow(grammar).to receive(:parse_param).and_return("{int parse_param}") + allow(grammar).to receive(:parse_param).and_return("int parse_param") expect(output.user_formals).to eq(", int parse_param") - allow(grammar).to receive(:parse_param).and_return("{ int parse_param }") + allow(grammar).to receive(:parse_param).and_return(" int parse_param ") expect(output.user_formals).to eq(", int parse_param") end end @@ -73,23 +73,23 @@ describe "#user_args" do context "when parse_param exists" do - it "returns name of parse param without braces/blanks with a leading comma" do - allow(grammar).to receive(:parse_param).and_return("{struct parser_params *p}") + it "returns name of parse param without blanks with a leading comma" do + allow(grammar).to receive(:parse_param).and_return("struct parser_params *p") expect(output.user_args).to eq(", p") - allow(grammar).to receive(:parse_param).and_return("{ struct parser_params *p }") + allow(grammar).to receive(:parse_param).and_return(" struct parser_params *p ") expect(output.user_args).to eq(", p") - allow(grammar).to receive(:parse_param).and_return("{int i}") + allow(grammar).to receive(:parse_param).and_return("int i") expect(output.user_args).to eq(", i") - allow(grammar).to receive(:parse_param).and_return("{ int i }") + allow(grammar).to receive(:parse_param).and_return(" int i ") expect(output.user_args).to eq(", i") - allow(grammar).to receive(:parse_param).and_return("{int parse_param}") + allow(grammar).to receive(:parse_param).and_return("int parse_param") expect(output.user_args).to eq(", parse_param") - allow(grammar).to receive(:parse_param).and_return("{ int parse_param }") + allow(grammar).to receive(:parse_param).and_return(" int parse_param ") expect(output.user_args).to eq(", parse_param") end end @@ -104,44 +104,44 @@ describe "#parse_param_name" do it "returns name of parse param" do - allow(grammar).to receive(:parse_param).and_return("{struct parser_params *p}") + allow(grammar).to receive(:parse_param).and_return("struct parser_params *p") expect(output.parse_param_name).to eq("p") - allow(grammar).to receive(:parse_param).and_return("{ struct parser_params *p }") + allow(grammar).to receive(:parse_param).and_return(" struct parser_params *p ") expect(output.parse_param_name).to eq("p") - allow(grammar).to receive(:parse_param).and_return("{int i}") + allow(grammar).to receive(:parse_param).and_return("int i") expect(output.parse_param_name).to eq("i") - allow(grammar).to receive(:parse_param).and_return("{ int i }") + allow(grammar).to receive(:parse_param).and_return(" int i ") expect(output.parse_param_name).to eq("i") - allow(grammar).to receive(:parse_param).and_return("{int parse_param}") + allow(grammar).to receive(:parse_param).and_return("int parse_param") expect(output.parse_param_name).to eq("parse_param") - allow(grammar).to receive(:parse_param).and_return("{ int parse_param }") + allow(grammar).to receive(:parse_param).and_return(" int parse_param ") expect(output.parse_param_name).to eq("parse_param") end end describe "#lex_param_name" do it "returns name of lex param" do - allow(grammar).to receive(:lex_param).and_return("{struct parser_params *p}") + allow(grammar).to receive(:lex_param).and_return("struct parser_params *p") expect(output.lex_param_name).to eq("p") - allow(grammar).to receive(:lex_param).and_return("{ struct parser_params *p }") + allow(grammar).to receive(:lex_param).and_return(" struct parser_params *p ") expect(output.lex_param_name).to eq("p") - allow(grammar).to receive(:lex_param).and_return("{int i}") + allow(grammar).to receive(:lex_param).and_return("int i") expect(output.lex_param_name).to eq("i") - allow(grammar).to receive(:lex_param).and_return("{ int i }") + allow(grammar).to receive(:lex_param).and_return(" int i ") expect(output.lex_param_name).to eq("i") - allow(grammar).to receive(:lex_param).and_return("{int lex_param}") + allow(grammar).to receive(:lex_param).and_return("int lex_param") expect(output.lex_param_name).to eq("lex_param") - allow(grammar).to receive(:lex_param).and_return("{ int lex_param }") + allow(grammar).to receive(:lex_param).and_return(" int lex_param ") expect(output.lex_param_name).to eq("lex_param") end end diff --git a/spec/lrama/parser_spec.rb b/spec/lrama/parser_spec.rb index 32fe0fe8..6bae8ace 100644 --- a/spec/lrama/parser_spec.rb +++ b/spec/lrama/parser_spec.rb @@ -43,30 +43,30 @@ y = File.read(fixture_path("common/basic.y")) grammar = Lrama::Parser.new(y).parse - expect(grammar.union.code.s_value).to eq(<<~CODE.chomp) - { - int i; - long l; - char *str; - } + expect(grammar.union.code.s_value).to eq(<<-CODE.chomp) + + int i; + long l; + char *str; + CODE expect(grammar.expect).to eq(0) expect(grammar.printers).to eq([ Printer.new( ident_or_tags: [T.new(type: T::Tag, s_value: "")], - code: Code.new(type: :printer, token_code: T.new(type: T::User_code, s_value: "{\n print_int();\n}")), + code: Code.new(type: :printer, token_code: T.new(type: T::User_code, s_value: "\n print_int();\n")), lineno: 15 ), Printer.new( ident_or_tags: [T.new(type: T::Ident, s_value: "tNUMBER"), T.new(type: T::Ident, s_value: "tSTRING")], - code: Code.new(type: :printer, token_code: T.new(type: T::User_code, s_value: "{\n print_token();\n}")), + code: Code.new(type: :printer, token_code: T.new(type: T::User_code, s_value: "\n print_token();\n")), lineno: 18 ), ]) - expect(grammar.lex_param).to eq("{struct lex_params *p}") - expect(grammar.parse_param).to eq("{struct parse_params *p}") - expect(grammar.initial_action).to eq(Code.new(type: :initial_action, token_code: T.new(type: T::User_code, s_value: "{\n initial_action_func(@$);\n}"))) + expect(grammar.lex_param).to eq("struct lex_params *p") + expect(grammar.parse_param).to eq("struct parse_params *p") + expect(grammar.initial_action).to eq(Code.new(type: :initial_action, token_code: T.new(type: T::User_code, s_value: "\n initial_action_func(@$);\n"))) expect(grammar.symbols.sort_by(&:number)).to eq([ Sym.new(id: T.new(type: T::Ident, s_value: "EOI"), alias_name: "\"EOI\"", number: 0, tag: nil, term: true, token_id: 0, nullable: false, precedence: nil, printer: nil), Sym.new(id: T.new(type: T::Ident, s_value: "YYerror"), alias_name: "error", number: 1, tag: nil, term: true, token_id: 256, nullable: false, precedence: nil, printer: nil), @@ -133,7 +133,7 @@ T.new(type: T::Ident, s_value: "tSTRING"), T.new(type: T::Ident, s_value: "keyword_end"), grammar.find_symbol_by_s_value!("tPLUS"), - T.new(type: T::User_code, s_value: "{ code 1 }"), + T.new(type: T::User_code, s_value: " code 1 "), ], 62, ], @@ -141,11 +141,11 @@ T.new(type: T::Ident, s_value: "class"), [ T.new(type: T::Ident, s_value: "keyword_class"), - T.new(type: T::User_code, s_value: "{ code 2 }"), + T.new(type: T::User_code, s_value: " code 2 "), T.new(type: T::Ident, s_value: "tSTRING"), T.new(type: T::Char, s_value: "'!'"), T.new(type: T::Ident, s_value: "keyword_end"), - T.new(type: T::User_code, s_value: "{ code 3 }"), + T.new(type: T::User_code, s_value: " code 3 "), grammar.find_symbol_by_s_value!("tEQ"), ], 64, @@ -154,11 +154,11 @@ T.new(type: T::Ident, s_value: "class"), [ T.new(type: T::Ident, s_value: "keyword_class"), - T.new(type: T::User_code, s_value: "{ code 4 }"), + T.new(type: T::User_code, s_value: " code 4 "), T.new(type: T::Ident, s_value: "tSTRING"), T.new(type: T::Char, s_value: "'?'"), T.new(type: T::Ident, s_value: "keyword_end"), - T.new(type: T::User_code, s_value: "{ code 5 }"), + T.new(type: T::User_code, s_value: " code 5 "), grammar.find_symbol_by_s_value!("'>'"), ], 65, @@ -263,7 +263,7 @@ grammar.find_symbol_by_s_value!("tSTRING"), grammar.find_symbol_by_s_value!("keyword_end"), ], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ code 1 }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " code 1 ")), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("tPLUS"), lineno: 62, @@ -272,7 +272,7 @@ id: 5, lhs: grammar.find_symbol_by_s_value!("$@1"), rhs: [], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ code 2 }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " code 2 ")), nullable: true, precedence_sym: nil, lineno: 64, @@ -281,7 +281,7 @@ id: 6, lhs: grammar.find_symbol_by_s_value!("$@2"), rhs: [], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ code 3 }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " code 3 ")), nullable: true, precedence_sym: nil, lineno: 64, @@ -306,7 +306,7 @@ id: 8, lhs: grammar.find_symbol_by_s_value!("$@3"), rhs: [], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ code 4 }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " code 4 ")), nullable: true, precedence_sym: nil, lineno: 65, @@ -315,7 +315,7 @@ id: 9, lhs: grammar.find_symbol_by_s_value!("$@4"), rhs: [], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ code 5 }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " code 5 ")), nullable: true, precedence_sym: nil, lineno: 65, @@ -578,7 +578,7 @@ class : keyword_class tSTRING keyword_end { code 1 } T.new(type: T::Ident, s_value: "keyword_class"), T.new(type: T::Ident, s_value: "tSTRING"), T.new(type: T::Ident, s_value: "keyword_end"), - T.new(type: T::User_code, s_value: "{ code 1 }"), + T.new(type: T::User_code, s_value: " code 1 "), ], 31, ], @@ -634,7 +634,7 @@ class : keyword_class tSTRING keyword_end { code 1 } T.new(type: T::Ident, s_value: "keyword_class"), T.new(type: T::Ident, s_value: "tSTRING"), T.new(type: T::Ident, s_value: "keyword_end"), - T.new(type: T::User_code, s_value: "{ code 1 }"), + T.new(type: T::User_code, s_value: " code 1 "), ], 31, ], @@ -698,7 +698,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.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ code 1 }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " code 1 ")), nullable: true, precedence_sym: nil, lineno: 31, @@ -707,7 +707,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.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ code 2 }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " code 2 ")), nullable: true, precedence_sym: nil, lineno: 31, @@ -722,7 +722,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.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ code 3 }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " code 3 ")), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("keyword_end"), lineno: 31, @@ -735,7 +735,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.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ code 4 }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " code 4 ")), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("keyword_end"), lineno: 32, @@ -815,10 +815,10 @@ class : keyword_class codes = grammar.rules.map(&:code).compact expect(codes.count).to eq(1) - expect(codes[0].s_value).to eq(<<~STR.chomp) -{ + expect(codes[0].s_value).to eq(<<-STR.chomp) + func("}"); - } + STR end end @@ -842,10 +842,10 @@ class : keyword_class codes = grammar.rules.map(&:code).compact expect(codes.count).to eq(1) - expect(codes[0].s_value).to eq(<<~STR.chomp) -{ + expect(codes[0].s_value).to eq(<<-STR.chomp) + func('}'); - } + STR end end @@ -1008,7 +1008,7 @@ class : keyword_class tSTRING keyword_end { code 1 } id: 2, lhs: grammar.find_symbol_by_s_value!("@1"), rhs: [], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ $1 = 1; $$ = 2; }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " $1 = 1; $$ = 2; ")), nullable: true, precedence_sym: nil, lineno: 17, @@ -1017,7 +1017,7 @@ class : keyword_class tSTRING keyword_end { code 1 } id: 3, lhs: grammar.find_symbol_by_s_value!("@2"), rhs: [], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ $$ = 3; }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " $$ = 3; ")), nullable: true, precedence_sym: nil, lineno: 18, @@ -1026,7 +1026,7 @@ class : keyword_class tSTRING keyword_end { code 1 } id: 4, lhs: grammar.find_symbol_by_s_value!("$@3"), rhs: [], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ $$ = 4; }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " $$ = 4; ")), nullable: true, precedence_sym: nil, lineno: 19, @@ -1035,7 +1035,7 @@ class : keyword_class tSTRING keyword_end { code 1 } id: 5, lhs: grammar.find_symbol_by_s_value!("$@4"), rhs: [], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ 5; }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " 5; ")), nullable: true, precedence_sym: nil, lineno: 21, @@ -1052,7 +1052,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.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ $2; $3; $5; $7; $$ = 1; }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " $2; $3; $5; $7; $$ = 1; ")), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("tBODY"), lineno: 16, @@ -1117,7 +1117,7 @@ class : keyword_class tSTRING keyword_end { code 1 } lhs: grammar.find_symbol_by_s_value!("emp"), rhs: [ ], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ $$; }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " $$; ")), nullable: true, precedence_sym: nil, lineno: 17, @@ -1127,7 +1127,7 @@ class : keyword_class tSTRING keyword_end { code 1 } lhs: grammar.find_symbol_by_s_value!("emp"), rhs: [ ], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ @$; }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " @$; ")), nullable: true, precedence_sym: nil, lineno: 19, @@ -1137,7 +1137,7 @@ class : keyword_class tSTRING keyword_end { code 1 } lhs: grammar.find_symbol_by_s_value!("emp"), rhs: [ ], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ @0; }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " @0; ")), nullable: true, precedence_sym: nil, lineno: 21, @@ -1232,7 +1232,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.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ printf(\"\\t%.10g\\n\", $expr); }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " printf(\"\\t%.10g\\n\", $expr); ")), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("'\\n'"), lineno: 19, @@ -1256,7 +1256,7 @@ class : keyword_class tSTRING keyword_end { code 1 } grammar.find_symbol_by_s_value!("expr"), grammar.find_symbol_by_s_value!("'+'"), ], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ $result = $left + $right; }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " $result = $left + $right; ")), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("'+'"), lineno: 24, @@ -1269,7 +1269,7 @@ class : keyword_class tSTRING keyword_end { code 1 } grammar.find_symbol_by_s_value!("expr"), grammar.find_symbol_by_s_value!("'-'"), ], - code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: "{ $$ = $1 - $2; }")), + code: Code.new(type: :user_code, token_code: T.new(type: T::User_code, s_value: " $$ = $1 - $2; ")), nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("'-'"), lineno: 26,