Skip to content

Commit

Permalink
Use <<~ in heredoc
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Jan 31, 2024
1 parent 4401d26 commit 786330f
Show file tree
Hide file tree
Showing 8 changed files with 1,515 additions and 1,515 deletions.
48 changes: 24 additions & 24 deletions lib/lrama/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ def symbol_actions_for_printer
@grammar.symbols.each do |sym|
next unless sym.printer

str << <<-STR
case #{sym.enum_name}: /* #{sym.comment} */
#line #{sym.printer.lineno} "#{@grammar_file_path}"
{#{sym.printer.translated_code(sym.tag)}}
#line [@oline@] [@ofile@]
break;
str << <<~STR
case #{sym.enum_name}: /* #{sym.comment} */
#line #{sym.printer.lineno} "#{@grammar_file_path}"
{#{sym.printer.translated_code(sym.tag)}}
#line [@oline@] [@ofile@]
break;
STR
end
Expand All @@ -155,10 +155,10 @@ def symbol_actions_for_printer
def user_initial_action(comment = "")
return "" unless @grammar.initial_action

<<-STR
#{comment}
#line #{@grammar.initial_action.line} "#{@grammar_file_path}"
{#{@grammar.initial_action.translated_code}}
<<~STR
#{comment}
#line #{@grammar.initial_action.line} "#{@grammar_file_path}"
{#{@grammar.initial_action.translated_code}}
STR
end

Expand All @@ -168,12 +168,12 @@ def symbol_actions_for_error_token
@grammar.symbols.each do |sym|
next unless sym.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)}}
#line [@oline@] [@ofile@]
break;
str << <<~STR
case #{sym.enum_name}: /* #{sym.comment} */
#line #{sym.error_token.lineno} "#{@grammar_file_path}"
{#{sym.error_token.translated_code(sym.tag)}}
#line [@oline@] [@ofile@]
break;
STR
end
Expand All @@ -191,19 +191,19 @@ def user_actions
code = rule.token_code
spaces = " " * (code.column - 1)

str << <<-STR
case #{rule.id + 1}: /* #{rule.as_comment} */
#line #{code.line} "#{@grammar_file_path}"
#{spaces}{#{rule.translated_code}}
#line [@oline@] [@ofile@]
break;
str << <<~STR
case #{rule.id + 1}: /* #{rule.as_comment} */
#line #{code.line} "#{@grammar_file_path}"
#{spaces}{#{rule.translated_code}}
#line [@oline@] [@ofile@]
break;
STR
end

str << <<-STR
str << <<~STR
#line [@oline@] [@ofile@]
#line [@oline@] [@ofile@]
STR

str
Expand Down
68 changes: 34 additions & 34 deletions spec/lrama/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,33 +155,33 @@
describe "S/R conflicts are resolved to reduce" do
it "does not include shift into actions" do
y = <<~INPUT
%{
// Prologue
%}
%{
// Prologue
%}
%union {
int i;
}
%union {
int i;
}
%token unary "+@"
%token tNUMBER
%token unary "+@"
%token tNUMBER
%left '+' '-'
%right unary
%left '+' '-'
%right unary
%%
%%
program: expr ;
program: expr ;
expr: unary expr
| expr '+' expr
| expr '-' expr
| arg
;
expr: unary expr
| expr '+' expr
| expr '-' expr
| arg
;
arg: tNUMBER ;
arg: tNUMBER ;
%%
%%
INPUT

grammar = Lrama::Parser.new(y, "parse.y").parse
Expand Down Expand Up @@ -210,29 +210,29 @@
describe "R/R conflicts are resolved by look ahead tokens" do
it "includes reduce into actions" do
y = <<~INPUT
%{
// Prologue
%}
%{
// Prologue
%}
%union {
int i;
}
%union {
int i;
}
%token tNUMBER
%token tNUMBER
%%
%%
program: stmt ;
program: stmt ;
stmt: expr1 ';'
| expr2 '.'
;
stmt: expr1 ';'
| expr2 '.'
;
expr1: tNUMBER ;
expr1: tNUMBER ;
expr2: tNUMBER ;
expr2: tNUMBER ;
%%
%%
INPUT

grammar = Lrama::Parser.new(y, "parse.y").parse
Expand Down
Loading

0 comments on commit 786330f

Please sign in to comment.