helixbass / tree-sitter-grep

The Unlicense
10 stars 1 forks source link

Filter dynamic library: simple C FFI #9

Closed helixbass closed 1 year ago

helixbass commented 1 year ago

In this PR:

To test: I included an example filter in this branch again (temporarily) so you should be able to run cargo build --release --all and then run eg ./target/release/tree-sitter-grep -l rust --filter ./target/release/libtree_sitter_grep_filter_before_line_number.dylib --filter-arg 30 ./reference-parameters.scm and see matches printed that only have line numbers < 30 If you run that without --filter-arg passed then it should fail on expecting to be passed a filter argument If you run that with eg --filter-arg abc passed then it should fail on expecting to be passed a usize filter argument If in the example filter you comment out the initialize() function (and the static atomic) and just put a hardcoded line number inside the filterer() callback eg 20 and re-build and re-run the above (without necessarily including the --filter-arg 30) then you should see matches printed that only have line numbers < 20 Running without a --filter argument should still work as expected If you're feeling bold, try writing a filter plugin in a different language and seeing if it works?

Based on match-predicate (Maybe looking at the diff of this branch vs current master would be preferable since this branch tears out a lot of what was on match-predicate, feel free to change the base branch of this PR)