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

Add Ripper-based parser and ast printer script for comparison against tree-sitter-ruby output. #210

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aibaars
Copy link
Contributor

@aibaars aibaars commented Apr 21, 2022

This pull request adds a script named script/print-ast.rb which uses the Ruby::Ripper parser
to parse a Ruby file and prints its AST in the same form as tree-sitter. It can be used to
generate expected output for inclusion in test cases.

The PR also adds the script script/compare-ast.sh which can be used to compare the AST's produced
by script/print-ast.rb against the ones produced by tree-sitter parse. These "back-to-back" comparison
of tree-sitter-ruby against Ruby::Ripper can help find cases where the two parsers diverge, likely indicating
bugs in the tree-sitter-ruby grammar.

The PR also integrates the "back-to-back" tests to the CI job to test for regressions. This makes the CI job quite a bit slower . It now takes 7 minutes to complete instead of 1 minute. However, I think the improved regression testing is worth it.

@maxbrunsfeld @nickrolfe

Checklist:

  • All tests pass in CI.
  • There are sufficient tests for the new fix/feature.
  • Grammar rules have not been renamed unless absolutely necessary.
  • The conflicts section hasn't grown too much.
  • The parser size hasn't grown too much (check the value of STATE_COUNT in src/parser.c).

@aibaars aibaars changed the title Ripper parser Add Ripper-based parser and ast printer script for comparison against tree-sitter-ruby output. Apr 21, 2022
@aibaars aibaars force-pushed the ripper-parser branch 5 times, most recently from fd50419 to b95296a Compare April 21, 2022 13:35
@aibaars aibaars marked this pull request as ready for review April 21, 2022 13:43
@mbj
Copy link

mbj commented Apr 21, 2022

BTW: I consider the https://github.com/whitequark/parser AST as the supreme ruby tooling AST compared to the ripper one, especially as its more stable and better documented.

It may make sense to investigate it as an addition/replacement for ripper based tests in the future.

@aibaars
Copy link
Contributor Author

aibaars commented Apr 21, 2022

BTW: I consider the https://github.com/whitequark/parser AST as the supreme ruby tooling AST compared to the ripper one, especially as its more stable and better documented.

It may make sense to investigate it as an addition/replacement for ripper based tests in the future.

That's a good point. The reason I picked Ripper is because it is just an external interface to the actual MRI parser. The API and documentation of Ripper are indeed rather terse. I would definitely prefer using whitequark/parser for anything more complex than printing an AST ;-)

@aibaars aibaars force-pushed the ripper-parser branch 2 times, most recently from c314853 to c3cc057 Compare July 28, 2022 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants