Skip to content

Implement Query Predicate Enforcement (#eq?, #match?, #any-of?)#128

Merged
bonede merged 16 commits intobonede:mainfrom
DavidBakerEffendi:main
Feb 26, 2026
Merged

Implement Query Predicate Enforcement (#eq?, #match?, #any-of?)#128
bonede merged 16 commits intobonede:mainfrom
DavidBakerEffendi:main

Conversation

@DavidBakerEffendi
Copy link
Contributor

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 the jtreesitter dependency as a reference implementation to ensure standard behavior.

Key changes

  • Implemented a TSQueryPredicate class hierarchy to evaluate #eq?, #match?, and #any-of? against captured nodes.
  • Updated TSQuery to parse raw predicate steps into executable objects and cache them per pattern.
  • Modified TSQueryCursor to iterate native matches and filter them using the parsed predicates and provided source text.
  • Added TSQueryPredicateTest to 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 :)

@bonede
Copy link
Owner

bonede commented Feb 25, 2026

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!

@DavidBakerEffendi
Copy link
Contributor Author

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!

Will do! Thanks for the merge on the other one :D

@DavidBakerEffendi
Copy link
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.
@DavidBakerEffendi
Copy link
Contributor Author

Added TSQueryErrorTest to ensure exceptions are thrown for invalid queries in the right place. PR is ready

@DavidBakerEffendi
Copy link
Contributor Author

Caused by: java.lang.NoClassDefFoundError at TSAutoCloseableTest.java:40

Weird, maybe some stale cache or Gradle build error causing this?

@bonede bonede merged commit 23446e0 into bonede:main Feb 26, 2026
6 of 8 checks passed
@bonede
Copy link
Owner

bonede commented Feb 26, 2026

Tests are failing randomly in GitHub CI. Still figuring it out.

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.

Query ignoring predicates #match? condition in S-expression queries not having any effect

2 participants