Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove leading/trailing blanks of parse/lex param #2

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/lrama/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,22 @@ 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
end

def lex_param
if @grammar.lex_param
omit_braces(@grammar.lex_param)
omit_braces_and_blanks(@grammar.lex_param)
else
""
end
Expand Down
21 changes: 18 additions & 3 deletions spec/lrama/output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -61,13 +70,19 @@
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

describe "#lex_param_name" do
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