Skip to content

Commit

Permalink
Fix file path and line number errors when using +, * and ()
Browse files Browse the repository at this point in the history
This PR fix file path and line number errors when using `+`, `*` or `()`.
I discovered this when using the above new grammar in Lrama.
Refs: ruby/lrama@df39a6f
Refs: https:/ruby/lrama/blob/df39a6f36535ac65e08a0a49eb84d6b944622e22/lib/lrama/parser.rb#L1270-L1282

As it stands, the second argument to `module_eval` is the absolute path to racc/grammarfileparser.rb and the line number. Perhaps specifying `@filename` and` @scanner.lineno + 1` is correct?

https:/ydah/racc/blob/ea43e57012355c726b914c52fdcb32708d1091c6/lib/racc/grammarfileparser.rb#L373
  • Loading branch information
ydah committed Jul 29, 2024
1 parent d27b781 commit a6e840d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/racc/grammarfileparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def _add_many_rule(prev)
return target if target
target = _gen_target_name("many", prev)
@many_rule_registry[prev.to_s] = target
src = SourceText.new("result = val[1] ? val[1].unshift(val[0]) : val", __FILE__, __LINE__)
src = SourceText.new("result = val[1] ? val[1].unshift(val[0]) : val", @filename, @scanner.lineno + 1)
act = UserAction.source_text(src)
@grammar.add Rule.new(target, [], act)
@grammar.add Rule.new(target, [prev, target], act)
Expand All @@ -308,7 +308,7 @@ def _add_many1_rule(prev)
return target if target
target = _gen_target_name("many1", prev)
@many1_rule_registry[prev.to_s] = target
src = SourceText.new("result = val[1] ? val[1].unshift(val[0]) : val", __FILE__, __LINE__)
src = SourceText.new("result = val[1] ? val[1].unshift(val[0]) : val", @filename, @scanner.lineno + 1)
act = UserAction.source_text(src)
@grammar.add Rule.new(target, [prev], act)
@grammar.add Rule.new(target, [prev, target], act)
Expand All @@ -323,7 +323,7 @@ def _add_group_rule(enum)
unless target = @group_rule_registry[target_name]
target = @grammar.intern("-group@#{target_name}", true)
@group_rule_registry[target_name] = target
src = SourceText.new("result = val", __FILE__, __LINE__)
src = SourceText.new("result = val", @filename, @scanner.lineno + 1)
act = UserAction.source_text(src)
rules.each do |syms, sprec|
rule = Rule.new(target, syms, act)
Expand Down

0 comments on commit a6e840d

Please sign in to comment.