diff --git a/lib/lrama/output.rb b/lib/lrama/output.rb index dd71814a..757d16e2 100644 --- a/lib/lrama/output.rb +++ b/lib/lrama/output.rb @@ -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 diff --git a/spec/lrama/output_spec.rb b/spec/lrama/output_spec.rb index 4afae322..4b5a9049 100644 --- a/spec/lrama/output_spec.rb +++ b/spec/lrama/output_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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