Skip to content

Commit a6e840d

Browse files
committed
Fix file path and line number errors when using +, * and ()
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://github.com/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://github.com/ydah/racc/blob/ea43e57012355c726b914c52fdcb32708d1091c6/lib/racc/grammarfileparser.rb#L373
1 parent d27b781 commit a6e840d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/racc/grammarfileparser.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def _add_many_rule(prev)
295295
return target if target
296296
target = _gen_target_name("many", prev)
297297
@many_rule_registry[prev.to_s] = target
298-
src = SourceText.new("result = val[1] ? val[1].unshift(val[0]) : val", __FILE__, __LINE__)
298+
src = SourceText.new("result = val[1] ? val[1].unshift(val[0]) : val", @filename, @scanner.lineno + 1)
299299
act = UserAction.source_text(src)
300300
@grammar.add Rule.new(target, [], act)
301301
@grammar.add Rule.new(target, [prev, target], act)
@@ -308,7 +308,7 @@ def _add_many1_rule(prev)
308308
return target if target
309309
target = _gen_target_name("many1", prev)
310310
@many1_rule_registry[prev.to_s] = target
311-
src = SourceText.new("result = val[1] ? val[1].unshift(val[0]) : val", __FILE__, __LINE__)
311+
src = SourceText.new("result = val[1] ? val[1].unshift(val[0]) : val", @filename, @scanner.lineno + 1)
312312
act = UserAction.source_text(src)
313313
@grammar.add Rule.new(target, [prev], act)
314314
@grammar.add Rule.new(target, [prev, target], act)
@@ -323,7 +323,7 @@ def _add_group_rule(enum)
323323
unless target = @group_rule_registry[target_name]
324324
target = @grammar.intern("-group@#{target_name}", true)
325325
@group_rule_registry[target_name] = target
326-
src = SourceText.new("result = val", __FILE__, __LINE__)
326+
src = SourceText.new("result = val", @filename, @scanner.lineno + 1)
327327
act = UserAction.source_text(src)
328328
rules.each do |syms, sprec|
329329
rule = Rule.new(target, syms, act)

0 commit comments

Comments
 (0)