Commit graph

152 commits

Author SHA1 Message Date
Hendrik van Antwerpen
c76d8ee076 Represent quantifiers using bytes instead of ints 2022-01-11 18:41:33 +01:00
Hendrik van Antwerpen
70aee901ac Reduce error handling logic 2022-01-11 18:33:36 +01:00
Hendrik van Antwerpen
99e74fa0f5 Move quantifier addition out of loop and drop conditional 2022-01-11 18:33:36 +01:00
Hendrik van Antwerpen
93db863729 Remove obsolete FIXMEs 2022-01-11 18:33:36 +01:00
Hendrik van Antwerpen
ec9b00e5c6 Handle multiple top-level alternations correctly 2022-01-11 18:33:36 +01:00
Hendrik van Antwerpen
8b28f3a8c4 Shorten quantifier operations by using early returns 2022-01-11 18:33:36 +01:00
Hendrik van Antwerpen
e338726cde Prefix globally visible TSquantifier values 2022-01-11 18:33:36 +01:00
Hendrik van Antwerpen
ae2ac3c0db Initialize variable to silence compiler warnings 2022-01-11 18:33:36 +01:00
Hendrik van Antwerpen
a1a241b013 Expose quantifiers per pattern, instead of merging for all patterns in a query 2022-01-11 18:33:36 +01:00
Hendrik van Antwerpen
1d513bcf67 Rewrite quantifier oeprations
- Simplify control flow by having a single return at the end of the function.
- Follow enum order for case order.
2022-01-11 18:33:36 +01:00
Hendrik van Antwerpen
1f1a449c76 Improve capture quantifier computation
Compute quantifiers in a bottom-up manner, which allows more precise
results for alternations, where the quantifiers are now precisly joined.
2022-01-11 18:33:36 +01:00
Hendrik van Antwerpen
9bac066330 Deal with quantifiers appearing on capture's enclosing patterns
- Use a proper enum type for quantifiers.
- Drop quantifiers from `TSQueryStep`, which was not used.
- Keep track of the captures introduced during a pattern parse, and
  apply the quantifier for the pattern to the captures that were
  introduced by the pattern or any sub patterns.
- Use 'quantifier' instead of 'suffix'.
2022-01-11 18:33:36 +01:00
Hendrik van Antwerpen
ae7869d1a6 Expose capture suffixes in queries 2022-01-11 18:33:36 +01:00
Max Brunsfeld
25f64e1eb6 Place tighter limits on the work done during query analysis 2021-12-09 22:18:21 -08:00
Max Brunsfeld
26dac9b2dd Fix query bugs revealed by randomized tests
* Fix bugs related to named wildcard patterns vs regular wildcard patterns.
* Fix handling of extra nodes during query analysis. Previously, the
expected child_index was updated incorrectly after an extra node,
leading to false "impossible pattern" errors.
* Refine logic for avoiding unnecessary state-splitting due to fallible steps.
Compute *two* different analysis results related to step fallibility:
  * `root_pattern_guaranteed` which, like before, summarizes whether the
    entire pattern is guaranteed to match once this step is reached.
  * `parent_pattern_guaranteed` - which just indicates whether the
    immediate parent pattern is guaranteed. This is now used when
    deciding whether it's necessary to split a match state.
2021-11-21 12:02:58 -08:00
Max Brunsfeld
fea3eca312 Improve query execution logging 2021-11-21 11:39:29 -08:00
Max Brunsfeld
142f4b6438 Rename Query::step_is_definite -> is_pattern_guaranteed_at_step 2021-11-21 11:37:52 -08:00
Max Brunsfeld
1fe0420f0f Avoid unnecessary stack entries in query analysis
When descending into a hidden child rule, the current stack entry
can be reused if it is currently at the end of its rule.

This fixes a test failure when analyzing a Ruby query. The
failure was introduced due to some changes to the Ruby grammar.
This optimization allows us to impose a _smaller_ limit on
the stack size, which should make query analysis faster and
more memory-efficient.
2021-11-19 11:04:36 -08:00
Max Brunsfeld
ddb12dc0c6 query: Return error on unclosed tree pattern in alternation
Fixes #1436
2021-10-12 09:20:43 -07:00
Max Brunsfeld
22a5cfbe10 Assign ids to query matches only when the matches are returned
Refs #1372
2021-09-13 12:39:48 -07:00
Andrew Hlynskyi
52e6c900c3 fix(lib): fix segfault on ts_query_new with incompatible grammar version, close #1318 2021-09-03 14:24:18 +03:00
Max Brunsfeld
f3ea60e23f Merge branch 'master' into query-cursor-api 2021-06-02 11:51:26 -07:00
Douglas Creager
cc20708a33 query: Minor cleanups 2021-06-02 14:16:04 -04:00
Douglas Creager
47f1af818a query: Remove bits.h 2021-06-02 14:14:57 -04:00
Douglas Creager
1f6eac555c query: Use uint32_t for capture list IDs 2021-06-02 13:19:52 -04:00
Douglas Creager
cd96552448 query: Allow configurable match limit
The default is now a whopping 64K matches, which "should be enough for
everyone".  You can use the new `ts_query_cursor_set_match_limit`
function to set this to a lower limit, such as the previous default of
32.
2021-06-02 11:30:55 -04:00
Max Brunsfeld
851f55afce Report non-rooted matches that intersect cursor's range restriction
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
2021-05-28 11:58:38 -07:00
Max Brunsfeld
fda35894d4 Stop matching new patterns past the end of QueryCursor's range
This restores the original signatures of the `set_byte_range` and
`set_point_range` functions. Now, the QueryCursor will properly report
matches that intersect, but are not fully contained by its range.

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
2021-05-25 18:02:35 -07:00
Max Brunsfeld
f597cc6a75 Preserve matches that contain the QueryCursor's start byte
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
2021-05-25 13:06:24 -07:00
Max Brunsfeld
a61f25bc58 Add APIs for advancing a QueryCursor to an arbitrary position 2021-05-24 21:07:59 -07:00
Douglas Creager
78010722a4 query: Allow unlimited pending matches
Well, not completely unlimited — we're still using a 16-bit counter to
keep track of them.  But we longer have a static maximum of 32 pending
matches when executing a query.
2021-05-24 11:02:58 -04:00
Max Brunsfeld
72143b17ff Fix handling of queries with field names at the roots of patterns
Fixes #1018
2021-03-27 09:36:13 -07:00
Max Brunsfeld
89e1157a29 Fix handling of repetitions in query analysis
Fixes #1007
2021-03-19 11:00:31 -07:00
Andrew Hlynskyi
1769d1459d fix: don't zeroing provided start position by the end zero position 2021-03-17 19:06:52 +02:00
Max Brunsfeld
a7ae7767b4 Add docs for negated field patterns 2021-03-12 15:12:24 -08:00
Max Brunsfeld
bc0ef5f373 Add negated field patterns to queries 2021-03-12 14:38:02 -08:00
Max Brunsfeld
62a61c3540 Fix some doc comments in query.c 2021-03-12 12:45:18 -08:00
Max Brunsfeld
9dc88061d5 query: Fix last child operator with multiple children
Fixes #806
2021-03-09 13:40:15 -08:00
Max Brunsfeld
6ba11d7778 Fix query analysis with top-level non-terminal extras
Fixes https://github.com/tree-sitter/tree-sitter/issues/968#issuecomment-792314281
2021-03-08 09:33:35 -08:00
Max Brunsfeld
5a2534ac4a Fix crash on unterminated alternation in query
Fixes #968
2021-03-07 08:48:03 -08:00
Max Brunsfeld
f18c36ca62 Fix handling of extra nodes in query analysis
Fixes #967
2021-03-06 14:35:41 -08:00
Max Brunsfeld
db6e1d9bdc Add ts_query_cursor_did_exceed_match_limit API 2021-03-05 15:02:49 -08:00
Max Brunsfeld
c25fa9910e Fix query match failure when indefinite steps have no captures
Fixes #937
2021-02-25 21:41:49 -08:00
Max Brunsfeld
774ae5e3d5 In parse tables, store production ids as 16 bits
Also remove the use of bitfields from the parse table format.
In all cases, bitfields were not necessary to achieve the
current binary sizes. Avoiding them makes the binaries more
portable.

There was no way to make this change backward-compatible,
so we have finally dropped support for parsers generated
with an earlier version of Tree-sitter.

At some point, when Atom adopts this version of Tree-sitter,
this change will affect Atom users who have installed packages
using third-party Tree-sitter parsers. The packages will need
to be updated to use a regenerated version of the parsers.
2021-02-25 16:12:31 -08:00
Max Brunsfeld
c2c63baf5b query: Fix escape sequence parsing in anonymous node patterns
Fixes #776
Fixes #760
2020-10-28 13:55:13 -07:00
Max Brunsfeld
84433494a5 Fix query analysis error for rules w/ required hidden tokens
Refs tree-sitter/node-tree-sitter#69
2020-10-12 09:46:18 -07:00
Max Brunsfeld
857a9ed07b query: Handle captured wildcard nodes at the root of patterns 2020-10-08 12:34:08 -07:00
Max Brunsfeld
d1c95193c1 query: Fix invalid use of slice::from_raw_parts 2020-10-05 12:08:53 -07:00
Max Brunsfeld
297e2bcb28 static query analysis: Fix handling of fields in hidden nodes 2020-09-23 16:55:48 -07:00
Max Brunsfeld
a544200a6c Simplify query code for matching supertypes 2020-09-23 11:55:03 -07:00