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 an error for using parameterizing rules with own stack in semantic action #399

Merged
merged 1 commit into from
Apr 26, 2024
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/grammar/rule_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def process_rhs(parameterizing_rule_resolver)
@replaced_rhs << lhs_token
parameterizing_rule_resolver.created_lhs_list << lhs_token
parameterizing_rule.rhs_list.each do |r|
rule_builder = RuleBuilder.new(@rule_counter, @midrule_action_counter, lhs_tag: token.lhs_tag, skip_preprocess_references: true)
rule_builder = RuleBuilder.new(@rule_counter, @midrule_action_counter, lhs_tag: token.lhs_tag)
rule_builder.lhs = lhs_token
r.symbols.each { |sym| rule_builder.add_rhs(bindings.resolve_symbol(sym)) }
rule_builder.line = line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static int yyerror(YYLTYPE *loc, const char *str);
{
$$ = $1 + $2;
printf("(%d, %d)\n", $1, $2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note] $n could be used with skip_preprocess_references: true because Reference#index is set by #scan_reference then no need to fill index by #numberize_references (#preprocess_references)

return Lrama::Grammar::Reference.new(type: :dollar, number: Integer(scanner[2]), index: Integer(scanner[2]), ex_tag: tag, first_column: start, last_column: scanner.pos)

printf("(%d, %d)\n", $:1, $:2);
}
;

Expand Down
2 changes: 2 additions & 0 deletions spec/lrama/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ def generate_object(grammar_file_path, c_path, obj_path, command_args: [])
it "prints messages corresponding to rules" do
expected = <<~STR
(2, 3)
(-2, -1)
pair even odd: 5
(1, 0)
(-2, -1)
pair odd even: 1
STR
test_parser("user_defined_parameterizing_rules", "2 3 ; 1 0", expected)
Expand Down