Implement Query Predicate Enforcement (#eq?, #match?, #any-of?)#128
Merged
bonede merged 16 commits intobonede:mainfrom Feb 26, 2026
Merged
Implement Query Predicate Enforcement (#eq?, #match?, #any-of?)#128bonede merged 16 commits intobonede:mainfrom
bonede merged 16 commits intobonede:mainfrom
Conversation
98c5161 to
7f90a8a
Compare
Owner
|
Hi @DavidBakerEffendi , this PR has merge conflicts with the base branch. Could you please rebase or merge the latest changes and resolve the conflicts?. Thanks! |
Contributor
Author
Will do! Thanks for the merge on the other one :D |
# Conflicts: # tree-sitter/src/main/java/org/treesitter/TSQuery.java
- Replace manual language loading with `TreeSitterJson` in tests. - Expand `TSQueryCursorTest` with a larger JSON document for better coverage of `execWithOptions`. - Clean up redundant `assumeTrue` checks in predicate tests.
- Rename `isPatternNonLocal` to `isPatterNonLocal` in `TSQuery` - Add capture ID validation in `getCaptureNameForId` - Update `TSQueryCursorTest` to use queries with predicates
7f90a8a to
22a525f
Compare
Contributor
Author
|
Adding another test case in a second, will say when this is ready |
- Check for NULL pointer after `ts_query_new` to handle syntax errors. - Prevent `ts_query_delete` calls on null pointers in the cleaner. - Add `TSQueryErrorTest` to verify exception handling for invalid queries.
Contributor
Author
|
Added TSQueryErrorTest to ensure exceptions are thrown for invalid queries in the right place. PR is ready |
Contributor
Author
Weird, maybe some stale cache or Gradle build error causing this? |
Owner
|
Tests are failing randomly in GitHub CI. Still figuring it out. |
5 tasks
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.
This PR implements Java-side evaluation for Tree-sitter query predicates, ensuring that matches are strictly filtered based on source text comparisons (e.g.,
#eq?,#match?) rather than returning all native candidates. The logic relies on thejtreesitterdependency as a reference implementation to ensure standard behavior.Key changes
TSQueryPredicateclass hierarchy to evaluate#eq?,#match?, and#any-of?against captured nodes.TSQueryto parse raw predicate steps into executable objects and cache them per pattern.TSQueryCursorto iterate native matches and filter them using the parsed predicates and provided source text.TSQueryPredicateTestto validate predicate logic, dynamically loading the JSON language for testing.Future work
Metadata directives like
#is?and#set!are currently handled as generic pass-throughs and need full implementation.Resolves #105
Resolves #84
Note: Set as draft for now, will do another round of reviews on Monday or so (maybe adding more tests), but if you get to it before then and are happy, feel free to merge :)