ruby / racc

Racc is an LALR(1) parser generator. It is written in Ruby itself, and generates ruby programs.
Other
535 stars 88 forks source link

Fix file path and line number errors when using `+`, `*` and `()` #273

Closed ydah closed 1 month ago

ydah commented 1 month ago

This PR fix file path and line number errors when using +, * or ().

I discovered this when using the above new grammar in Lrama. Refs: https://github.com/ruby/lrama/pull/460/commits/df39a6f36535ac65e08a0a49eb84d6b944622e22 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

yui-knk commented 1 month ago

Thanks for the PR. I think it's better to add test cases for this pattern. In this case, it's difficult to get line number and file name from actions, so I suggest to add test case in TestRaccCommand with assert_compile, assert_debugfile and assert_output_unchanged to check the output file difference. What do you think about it?

ydah commented 1 month ago

@yui-knk Thank you for your reviewing! I add test case for TestRaccCommand. How about this?

yui-knk commented 1 month ago

Thank you!