Perl: switch to the more accurate ts-parser-perl grammar (~92% fewer parse failures)#126
Open
rabbiveesh wants to merge 1 commit into
Open
Perl: switch to the more accurate ts-parser-perl grammar (~92% fewer parse failures)#126rabbiveesh wants to merge 1 commit into
rabbiveesh wants to merge 1 commit into
Conversation
The crates.io `tree-sitter-perl` is an independent, older Perl grammar by a different author; `ts-parser-perl` is the crate for github.com/tree-sitter-perl/tree-sitter-perl, which parses real-world Perl substantially more accurately (95.4% vs 40.2% clean parse across 8,342 real-world files; ~92% fewer ERROR/MISSING failures). For a symbol/import/call indexer, an ERROR node makes that subtree untraversable, so the more accurate grammar recovers symbols that are silently missed today. The two grammars use different node names, so this is not a drop-in dependency bump. Changes: - Cargo: package-rename so the `tree_sitter_perl` path is unchanged. - parser.rs PERL_QUERY: package_statement/subroutine_declaration_statement/ method_declaration_statement; `use constant` constants captured and gated on pragma text in Rust (the binding does not evaluate #eq? predicates); variable capture keeps the sigil ($counter). - perl_package_name: read the `package` name node. - imports/perl.rs: every use/no pragma is one `use_statement` (use/no keyword + `module` field); require is an `expression_statement` wrapping `require_expression`. Extend the statement range through the trailing `;` sibling so organize/remove leave no stray semicolon. - calls.rs: function_call_expression/method_call_expression; method-call callee resolves via the `method` field. All Perl tests pass (imports, outline, round-trip, organize golden corpus). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Author
|
let me know if you'd like the comments cleaned up - you know how claude can be sometimes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
aft's Perl support depends on the crates.io
tree-sitter-perlcrate, which is an independent, older Perl grammar by a different author. This PR switches tots-parser-perl— the crate fortree-sitter-perl/tree-sitter-perl— which parses real-world Perl far more accurately.Benchmark on 8,342 real-world Perl files (perl5 core + CPAN: DBIx-Class, Mojolicious, SpamAssassin, Bugzilla, …), files parsing with no ERROR/MISSING nodes:
ts-parser-perl(this PR)tree-sitter-perl(current dep)(Curated 3,386-module gold corpus: 99.6% vs 73.9%.) For aft this is coverage, not just quality: an
ERRORnode makes that whole subtree untraversable, so on the ~60% of files the current grammar can't parse cleanly, the symbol/import/call extractors silently walk past everything underneath.Not a drop-in — the two grammars use different node names
The dependency itself is a Cargo package-rename, so the
tree_sitter_perl::LANGUAGEpath is unchanged:But aft matches Perl node kinds directly, and those differ, so the extractors needed updating:
parser.rsPERL_QUERY→package_statement/subroutine_declaration_statement/method_declaration_statement.use constantconstants are captured and gated on the pragma text in Rust (thetree-sitterbinding doesn't evaluate#eq?predicates, anduse parent -norequire, …shares the same shape). The variable capture now keeps the sigil so the symbol is$counter, notcounter.perl_package_namereads thepackagename node (waspackage_name) so subs inside apackage Foo;are still classified as methods.imports/perl.rs— this grammar represents everyuse/nopragma (includinguse parent/use constant) as a singleuse_statementwith ause/nokeyword token and amodulefield, and runtimerequireas anexpression_statementwrapping arequire_expression. The parser was restructured accordingly. One subtlety handled: ause_statementspans its own;but anexpression_statementdoes not (the;is a sibling), so the statement range is extended through a trailing;so organize/remove leave no stray semicolon.calls.rs→function_call_expression/method_call_expression; the method-call callee resolves via themethodfield.Testing
Built and ran the full
agent-file-toolstest suite locally:imports::perl::*unit tests (including the rewritten grammar-node-kind stability fixture andparse_perl_supported_forms/ round-trip),outline_perl_symbols_include_packages_subroutines_constants_and_variables, and theimport_golden_corpusPerl scenarios (organize/add/remove) — the golden snapshots match unchanged, confirming behavior parity.watcher_filter_tests::gitignore_write_rebuilds_before_filtering_same_batch_paths, fails identically on a clean checkout ofmainin my environment — it's an inotify/gitignore timing test unrelated to this change.)(Disclosure: I maintain
tree-sitter-perl/tree-sitter-perl. The benchmark is reproducible — compile each grammar to a separate.soand parse the same corpus.)Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Switch Perl parsing to
ts-parser-perlfor much higher accuracy (95.4% vs 40.2% clean parses across 8,342 files), recovering symbols/imports/calls previously lost to parse errors. This improves coverage on real-world Perl and reduces untraversable subtrees.tree-sitter-perlwithts-parser-perlvia Cargo package-rename;tree_sitter_perlpath remains unchanged.package_statement(package),subroutine_declaration_statement, andmethod_declaration_statement; capture variables with the sigil; detect constants fromuse constant NAME => ...gated by pragma text.use/noas a singleuse_statementwith amodulefield; parserequire Foo;as anexpression_statementwrappingrequire_expression; extend the statement range through a trailing;to avoid stray semicolons.function_call_expressionandmethod_call_expression; resolve method callees via themethodfield.Written for commit 684dff3. Summary will update on new commits.