From 2acfc927c61e7db2e45bafe112d6a7b25b01d515 Mon Sep 17 00:00:00 2001 From: ydah Date: Sat, 4 May 2024 19:30:38 +0900 Subject: [PATCH] Change the test case to be a good example --- .../with_action_and_named_references.y | 9 ++++--- spec/lrama/parser_spec.rb | 24 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/spec/fixtures/parameterizing_rules/user_defined/with_action_and_named_references.y b/spec/fixtures/parameterizing_rules/user_defined/with_action_and_named_references.y index 9bb96b66..e68da1fe 100644 --- a/spec/fixtures/parameterizing_rules/user_defined/with_action_and_named_references.y +++ b/spec/fixtures/parameterizing_rules/user_defined/with_action_and_named_references.y @@ -10,18 +10,17 @@ static int yyerror(YYLTYPE *loc, const char *str); %union { int i; - char *s; } %token number -%token string +%token 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"); } ; %% diff --git a/spec/lrama/parser_spec.rb b/spec/lrama/parser_spec.rb index 85627a57..1b8e0f1b 100644 --- a/spec/lrama/parser_spec.rb +++ b/spec/lrama/parser_spec.rb @@ -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), ]) @@ -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