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

Fix extract_param_name #72

Merged
merged 1 commit into from
Aug 6, 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
2 changes: 1 addition & 1 deletion lib/lrama/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def user_args
end

def extract_param_name(param)
/\A(.)+([a-zA-Z0-9_]+)\z/.match(param)[2]
/\A(\W*)([a-zA-Z0-9_]+)\z/.match(param.split.last)[2]
end

def parse_param_name
Expand Down
70 changes: 70 additions & 0 deletions spec/lrama/output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@

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}")
expect(output.parse_param).to eq("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}")
expect(output.parse_param).to eq("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

Expand All @@ -36,6 +50,20 @@

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}")
expect(output.user_formals).to eq(", 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}")
expect(output.user_formals).to eq(", 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

Expand All @@ -55,6 +83,20 @@

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}")
expect(output.user_args).to eq(", 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}")
expect(output.user_args).to eq(", parse_param")

allow(grammar).to receive(:parse_param).and_return("{ int parse_param }")
expect(output.user_args).to eq(", parse_param")
end
end

Expand All @@ -73,6 +115,20 @@

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}")
expect(output.parse_param_name).to eq("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}")
expect(output.parse_param_name).to eq("parse_param")

allow(grammar).to receive(:parse_param).and_return("{ int parse_param }")
expect(output.parse_param_name).to eq("parse_param")
end
end

Expand All @@ -83,6 +139,20 @@

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}")
expect(output.lex_param_name).to eq("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}")
expect(output.lex_param_name).to eq("lex_param")

allow(grammar).to receive(:lex_param).and_return("{ int lex_param }")
expect(output.lex_param_name).to eq("lex_param")
end
end
end