diff --git a/lib/lrama/output.rb b/lib/lrama/output.rb index 20ffebbc..06d821c4 100644 --- a/lib/lrama/output.rb +++ b/lib/lrama/output.rb @@ -175,14 +175,14 @@ def user_actions str end - def omit_braces(param) - param[1..-2] + def omit_braces_and_blanks(param) + param[1..-2].strip end # b4_parse_param def parse_param if @grammar.parse_param - omit_braces(@grammar.parse_param) + omit_braces_and_blanks(@grammar.parse_param) else "" end @@ -190,7 +190,7 @@ def parse_param def lex_param if @grammar.lex_param - omit_braces(@grammar.lex_param) + omit_braces_and_blanks(@grammar.lex_param) else "" end diff --git a/spec/lrama/output_spec.rb b/spec/lrama/output_spec.rb index 18ae7050..90b84506 100644 --- a/spec/lrama/output_spec.rb +++ b/spec/lrama/output_spec.rb @@ -19,17 +19,23 @@ let(:grammar) { double("grammar") } describe "#parse_param" do - it "returns declaration of parse param without braces" do + it "returns declaration of parse param without braces/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 }") + expect(output.parse_param).to eq("struct parser_params *p") end end describe "#user_formals" do context "when parse_param exists" do - it "returns declaration of parse param without braces with a leading comma" 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}") expect(output.user_formals).to eq(", 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") end end @@ -43,9 +49,12 @@ describe "#user_args" do context "when parse_param exists" do - it "returns name of parse param without braces with a leading comma" 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}") expect(output.user_args).to eq(", p") + + allow(grammar).to receive(:parse_param).and_return("{ struct parser_params *p }") + expect(output.user_args).to eq(", p") end end @@ -61,6 +70,9 @@ it "returns name of parse param" do 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 }") + expect(output.parse_param_name).to eq("p") end end @@ -68,6 +80,9 @@ it "returns name of lex param" do 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 }") + expect(output.lex_param_name).to eq("p") end end end