Skip to content

Commit

Permalink
Change the test case to be a good example
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed May 4, 2024
1 parent fcd84c7 commit 2acfc92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ static int yyerror(YYLTYPE *loc, const char *str);

%union {
int i;
char *s;
}

%token <i> number
%token <s> string
%token <i> summand

%rule pair(X, Y): X ',' Y[alias] { printf("(%d, %d)\n", $X, $alias); }
;
%rule plus(X): X '+' number[addend] { $$ = $X + $addend; }
;

%%

program : pair(number, string) { printf("pair odd even\n"); }
program : plus(summand) { printf("plus 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 @@ -1693,7 +1693,7 @@
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: "pair_number_string"), alias_name: nil, number: 7, tag: nil, term: false, token_id: 1, 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),
])

Expand All @@ -1708,33 +1708,33 @@
token_code: nil,
nullable: false,
precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"),
lineno: 24,
lineno: 23,
),
Rule.new(
id: 1,
lhs: grammar.find_symbol_by_s_value!("pair_number_string"),
lhs: grammar.find_symbol_by_s_value!("plus_summand"),
rhs: [
grammar.find_symbol_by_s_value!("number"),
grammar.find_symbol_by_number!(5),
grammar.find_symbol_by_s_value!("string")
grammar.find_symbol_by_s_value!("summand"),
grammar.find_symbol_by_s_value!("'+'"),
grammar.find_symbol_by_s_value!("number")
],
lhs_tag: nil,
token_code: T::UserCode.new(s_value: " printf(\"(%d, %d)\\n\", $X, $alias); "),
token_code: T::UserCode.new(s_value: " $$ = $X + $addend; "),
nullable: false,
precedence_sym: grammar.find_symbol_by_s_value!("string"),
lineno: 24,
precedence_sym: grammar.find_symbol_by_s_value!("number"),
lineno: 23,
),
Rule.new(
id: 2,
lhs: grammar.find_symbol_by_s_value!("program"),
rhs: [
grammar.find_symbol_by_s_value!("pair_number_string"),
grammar.find_symbol_by_s_value!("plus_summand"),
],
lhs_tag: nil,
token_code: T::UserCode.new(s_value: " printf(\"pair odd even\\n\"); "),
token_code: T::UserCode.new(s_value: " printf(\"plus number\\n\"); "),
nullable: false,
precedence_sym: nil,
lineno: 24,
lineno: 23,
),
])
end
Expand Down

0 comments on commit 2acfc92

Please sign in to comment.