Commit graph

200 commits

Author SHA1 Message Date
Max Brunsfeld
060e00463d Implement include-children directive in injection queries 2019-10-14 17:38:42 -07:00
Max Brunsfeld
324c259cbb rust: Create readable messages for query syntax errors 2019-10-14 12:30:22 -07:00
Max Brunsfeld
a45dc67390 Loosen unnecessary lifetime restriction in rust QueryCursor APIs 2019-10-14 12:30:22 -07:00
Max Brunsfeld
f490befcde Add ts_query_disable_capture API 2019-10-14 12:30:22 -07:00
Max Brunsfeld
4c17af3ecd Allow queries with no patterns 2019-10-14 12:30:22 -07:00
Max Brunsfeld
c153711539 query: Avoid splitting states on nodes that don't contain captures 2019-10-14 12:30:22 -07:00
Matthew Krupcale
ee9a3c0ebb lib: remove utf8proc dependency (#436)
* Remove dependency on utf8proc

This removes the only external dependency on utf8proc for UTF-8 decoding. It does so by implementing its own UTF-8 decoder. This decoder is both faster and has a simpler API.

 * .gitmodules: remove utf8proc submodule
 * docs/section-2-using-parsers.md: remove requirement for utf8proc submodule
 * docs/section-6-contributing.md: likewise
 * lib/Cargo.toml: remove utf8proc subdirectory package include
 * lib/README.md: remove utf8proc subdirectory description
 * lib/binding_rust/build.rs: remove utf8proc compiler include directory
 * lib/src/lexer.c: remove utf8proc dependencies and types
 * lib/src/lib.c: remove utf8proc dependency
 * lib/src/unicode.h: define types for Unicode decoders
 * lib/src/utf16.{c,h}: implement more readable UTF-16 decoder
 * lib/src/utf8.{c,h}: implement fast UTF-8 decoder
 * lib/utf8proc: remove utf8proc submodule directory
 * script/build-lib: remove utf8proc compiler include directory
 * script/build-wasm: likewise

* Optimize ts_lexer__get_lookahead.

Try to favor non-failure code path and assign lookahead values directly to lexer

 * lib/src/lexer.c: optimize for non-failure code path

* Fix some compiler errors

 * lib/src/lexer.c: cast from signed to unsigned for decode_next result
 * lib/src/utf16.c: fix non-constant initializers for older compilers

* Remove some missed remnants of utf8proc

 * docs/section-2-using-parsers.md: only two include paths necessary now
 * lib/src/lib.c: no need to define UTF8PROC_STATIC

* Use ICU's utf8 and utf16 decoding routines

* Remove unnecessary casts when calling icu macros

* Check buffer length before attempting to decode a unicode character

* Use new unicode function when parsing Queries

Co-Authored-By: Matthew Krupcale <mkrupcale@matthewkrupcale.com>

* Mark libicu files as vendored for GitHub's stats
2019-10-14 11:18:39 -07:00
Ika
979b46e297 fix(web-tree-sitter): add missing types 2019-10-04 20:16:13 +08:00
Max Brunsfeld
015be68c94 rust: Generalize text_callback type for query methods 2019-10-03 12:53:14 -07:00
Max Brunsfeld
9872a083b7 rust: Change QueryCursor::captures to expose the full match 2019-10-03 12:45:58 -07:00
Max Brunsfeld
cb87b7b76e Fix invalid read by query cursor on error nodes
🎩 @bfredl

Refs https://github.com/tree-sitter/tree-sitter/pull/448#issuecomment-536337749
2019-10-01 11:28:51 -07:00
Björn Linse
1d2d043390 fix compiler warning with comparing char with `TSSymbolType' 2019-09-30 19:24:40 +02:00
Max Brunsfeld
27149902f8 Handle is?, is-not?, and set! predicate functions in queries 2019-09-25 10:21:20 -07:00
Max Brunsfeld
b15e90bd26 Handle set! predicate function in queries 2019-09-24 11:54:24 -07:00
Max Brunsfeld
ff9a2c1f53 Make queries work in languages with simple aliases 2019-09-24 11:54:24 -07:00
Max Brunsfeld
070f11b8bf Use ptr::NonNull in Rust bindings 2019-09-23 17:00:52 -07:00
Björn Linse
15e3bc7fd2 Fix some compiler warnings regarding function prototypes 2019-09-22 11:49:44 +02:00
Max Brunsfeld
a6b6a681ec Fix a bug that prevented early termination of query matches 2019-09-18 16:13:10 -07:00
Max Brunsfeld
d9b8bae629 rust: Include pattern indices when iterating query captures 2019-09-18 14:22:55 -07:00
Max Brunsfeld
186b08381c Terminate failed query matches before descending whenever possible
When iterating over captures, this prevents reasonable queries from 
forcing the tree cursor to buffer matches unnecessarily.
2019-09-18 11:37:49 -07:00
Max Brunsfeld
374a7ac81e Ensure that duplicate captures are ordered by pattern index 2019-09-17 16:27:16 -07:00
Max Brunsfeld
82955759c0 Add an API for getting a pattern's start offset in the source code 2019-09-17 16:19:58 -07:00
Max Brunsfeld
fdd3a34e70 Fix some comments 2019-09-17 15:05:12 -07:00
Max Brunsfeld
2d1ca8bc9f Fix match return order fom ts_query_cursor_next_match 2019-09-17 14:52:27 -07:00
Max Brunsfeld
1af85dc3f7 Remove unused APIs, expand docs for predicate API 2019-09-16 15:00:32 -07:00
Max Brunsfeld
b79839b599 Use a more realistic example in one JS query unit test 2019-09-16 12:48:01 -07:00
Max Brunsfeld
7793bf2a5a Clean up query code 2019-09-16 11:33:22 -07:00
Max Brunsfeld
d4d554b2ae Add wasm bindings for predicates 2019-09-16 10:25:44 -07:00
Max Brunsfeld
096126d039 Allow predicates in queries, to match on nodes' text 2019-09-15 22:06:51 -07:00
Max Brunsfeld
307a1a6c11 Avoid wasm calls in Node.startIndex and Node.startPosition 2019-09-13 15:38:30 -07:00
Max Brunsfeld
86205b9e6d Fix infinite loop on unterminated string in query 2019-09-13 15:19:21 -07:00
Max Brunsfeld
a1fec71b19 Tweak QueryCursor to allow iterating either matches or captures
For syntax highlighting, we want to iterate over all of the captures in 
order, and don't care about grouping the captures by pattern.
2019-09-13 15:19:04 -07:00
Max Brunsfeld
33587c924a Remove an unused field, clean up some comments 2019-09-12 17:00:01 -07:00
Max Brunsfeld
e52f1a26b3 Fix windows bitwise stuff for tree queries 2019-09-12 16:38:02 -07:00
Max Brunsfeld
36427614d3 Fix typo in windows impl of count_leading_zeros 2019-09-12 15:53:04 -07:00
Max Brunsfeld
49ce2fddb9 Add wasm binding for running tree queries in a limited range 2019-09-12 12:14:04 -07:00
Max Brunsfeld
67dcbc3e73 Detect error when a prefix of a valid node name is used in a query 2019-09-11 21:23:46 -07:00
Max Brunsfeld
c71de5bd81 Tweak query interface
* Rename TSQueryContext -> TSQueryCursor
* Remove the permanent association between the cursor and its query. The 
cursor can now be used again for a different query.
2019-09-11 17:33:48 -07:00
Max Brunsfeld
c8c75782e3 Allow tree queries to execute within a limited range 2019-09-11 16:49:29 -07:00
Max Brunsfeld
beb5eec7d9 Fix handling of single-node patterns in tree queries 2019-09-11 15:22:32 -07:00
Max Brunsfeld
d674bc139a Fix more bugs in binary search used in tree queries
This binary search implementation differs from Rust's
`slice::binary_search_by` method in how they deal with ties.

In Rust's implementation:

> If there are multiple matches, then any one of the matches
> could be returned.

This implementation needs to return the index of the *first* match.
2019-09-11 14:45:14 -07:00
Max Brunsfeld
33f89522f6 Allow lisp-style comments in tree queries 2019-09-11 12:16:05 -07:00
Max Brunsfeld
4fa0b02d67 Fix management of capture lists in query execution 2019-09-11 12:06:38 -07:00
Max Brunsfeld
60467ae701 Fix bugs in binary search used in tree queries 2019-09-10 22:30:27 -07:00
Max Brunsfeld
52cda5f541 Start work on wasm binding to query API 2019-09-10 20:54:21 -07:00
Max Brunsfeld
fe7c74e7aa Start work on an API for querying trees 2019-09-10 20:53:57 -07:00
Max Brunsfeld
82fab90c0b web: Add bindings for remaining field APIs 2019-09-04 09:30:36 -07:00
Max Brunsfeld
30e73505e1 Fix handling of extra tokens in ts_tree_cursor_current_field_id 2019-09-04 09:04:31 -07:00
Max Brunsfeld
69ab405325 In next ABI, group symbols by action in small parse state table
This is a more compact representation because in most states, many 
symbols share the same actions.
2019-08-30 20:29:55 -07:00
Max Brunsfeld
09a2755399 Store parse states with few lookahead symbols in a more compact way 2019-08-29 15:52:23 -07:00