Skip to content

Commit

Permalink
Fix incorrect test cases
Browse files Browse the repository at this point in the history
It is correct to specify a Named Reference for the parameter.
  • Loading branch information
ydah committed May 26, 2024
1 parent 6024b2b commit db76b63
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ static int yyerror(YYLTYPE *loc, const char *str);
}

%token <i> number
%token <i> summand

%rule plus(X): X '+' number[addend] { $$ = $X + $addend; }
%rule sum(X, Y) <i>: X[summand] '+' Y[addend] { $$ = $summand + $addend; }
;

%%

program : plus(summand) { printf("plus number\n"); }
program : sum(number, number) { printf("sum number\n"); }
;

%%
Expand Down
24 changes: 12 additions & 12 deletions spec/lrama/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1692,9 +1692,9 @@

it "expands parameterizing rules" do
expect(grammar.nterms.sort_by(&:number)).to match_symbols([
Sym.new(id: T::Ident.new(s_value: "$accept"), alias_name: nil, number: 6, tag: nil, term: false, token_id: 0, nullable: false),
Sym.new(id: T::Ident.new(s_value: "plus_summand"), alias_name: nil, number: 7, tag: nil, term: false, token_id: 1, nullable: false),
Sym.new(id: T::Ident.new(s_value: "program"), alias_name: nil, number: 8, tag: nil, term: false, token_id: 2, nullable: false),
Sym.new(id: T::Ident.new(s_value: "$accept"), alias_name: nil, number: 5, tag: nil, term: false, token_id: 0, nullable: false),
Sym.new(id: T::Ident.new(s_value: "sum_number_number"), alias_name: nil, number: 6, tag: T::Tag.new(s_value: "<i>"), term: false, token_id: 1, nullable: false),
Sym.new(id: T::Ident.new(s_value: "program"), alias_name: nil, number: 7, tag: nil, term: false, token_id: 2, nullable: false),
])

expect(grammar.rules).to eq([
Expand All @@ -1708,33 +1708,33 @@
token_code: nil,
nullable: false,
precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"),
lineno: 23,
lineno: 22,
),
Rule.new(
id: 1,
lhs: grammar.find_symbol_by_s_value!("plus_summand"),
lhs: grammar.find_symbol_by_s_value!("sum_number_number"),
rhs: [
grammar.find_symbol_by_s_value!("summand"),
grammar.find_symbol_by_s_value!("number"),
grammar.find_symbol_by_s_value!("'+'"),
grammar.find_symbol_by_s_value!("number")
],
lhs_tag: nil,
token_code: T::UserCode.new(s_value: " $$ = $X + $addend; "),
lhs_tag: T::Tag.new(s_value: "<i>"),
token_code: T::UserCode.new(s_value: " $$ = $summand + $addend; "),
nullable: false,
precedence_sym: grammar.find_symbol_by_s_value!("number"),
lineno: 23,
lineno: 22,
),
Rule.new(
id: 2,
lhs: grammar.find_symbol_by_s_value!("program"),
rhs: [
grammar.find_symbol_by_s_value!("plus_summand"),
grammar.find_symbol_by_s_value!("sum_number_number"),
],
lhs_tag: nil,
token_code: T::UserCode.new(s_value: " printf(\"plus number\\n\"); "),
token_code: T::UserCode.new(s_value: " printf(\"sum number\\n\"); "),
nullable: false,
precedence_sym: nil,
lineno: 23,
lineno: 22,
),
])
end
Expand Down

0 comments on commit db76b63

Please sign in to comment.