Commit graph

218 commits

Author SHA1 Message Date
Will Lillis
b0a6bde2fb fix(lib): return early for empty predicate step slice
(cherry picked from commit 31b9717ca3)
2025-05-11 15:23:39 +02:00
Will Lillis
69723ca40e fix(query): correct last_child_step_index in cases where a new step
wasn't created.

This fixes an OOB access to `self.steps` when a last child anchor
immediately follows a predicate.

(cherry picked from commit b1d2b7cfb8)
2025-05-04 00:08:10 +02:00
tree-sitter-ci-bot[bot]
6f2dbaab5f
build: do not define _POSIX_C_SOURCE on NetBSD (#4196)
It leads to missing symbols, see #4180.

(cherry picked from commit 2bf04d1f04)

---------

Co-authored-by: Thomas Klausner <wiz@gatalith.at>
2025-03-02 23:46:23 +01:00
Amaan Qureshi
8bb1448a6f feat: add the semantic version to TSLanguage, and expose an API for retrieving it 2025-01-25 01:14:30 -05:00
Amaan Qureshi
5de314833f feat(query): structurally verify supertype queries 2025-01-12 13:04:10 -05:00
Amaan Qureshi
0195bbf1b4 fix(lib): avoid OOB access when updating alternative steps 2025-01-10 19:41:43 -05:00
Amaan Qureshi
efc51a596c fix(lib): don't consider unfinished captures definite when the following step is immediate
When collecting captures, we were treating unfinished ones as definite
even if they had pending immediate steps that weren't yet satisfied. Now
we only mark a capture as definite if the pattern is guaranteed and
there are no pending immediate steps to check.
2025-01-04 02:03:41 -05:00
Amaan Qureshi
5f379da544 fix(lib): prevent wildcards from incorrectly marking child patterns as infallible
When a pattern appears under a wildcard parent (like "(_ (expr))"), we
were incorrectly marking it as infallible. The parent_pattern_guaranteed
flag only means the pattern will match after finding the right wildcard
parent, not that any wildcard parent will work.
2025-01-03 23:09:49 -05:00
Amaan Qureshi
a7e6d01144 fix(lib): propagate last_child status to pattern alternatives in queries
Previously, when a pattern was marked as the last child in a query, its
alternatives weren't marked similarly, causing incorrect matching
behavior. Now, the `last_child` status is properly propagated through
all alternatives.
2025-01-03 21:13:29 -05:00
Amaan Qureshi
22f67e2b67 fix(query): ensure immediate matches for any node when an anchor follows a wildcard node 2024-12-29 00:54:16 -05:00
Will Lillis
2a63077cac
style: correct typos 2024-12-23 02:11:09 -05:00
Riley Bruins
495fe2a6c5
feat: support querying missing nodes
Co-authored-by: Amaan Qureshi <amaanq12@gmail.com>
2024-12-14 14:57:36 -05:00
WillLillis
5b5cf5a5e5 fix(lib): check point, byte ranges in ts_query_cursor_set
range functions
2024-11-02 03:06:07 -04:00
Amaan Qureshi
8d68980aa8 feat(lib): add ts_query_cursor_exec_with_options
Currently, this allows users to pass in a callback that should be
invoked to check whether or not to halt query execution
2024-10-31 21:58:35 -04:00
Amaan Qureshi
91df16bdc8 fix(lib): ensure an unfinished state was found before removing it 2024-10-03 21:33:36 -04:00
Amaan Qureshi
28972f916a fix(lib): silence warnings with -Wpedantic 2024-09-27 12:58:26 -04:00
Amaan Qureshi
3f424c0121 feat: add an API to time out query executions
Currently, if a predicate is hard to match on the Rust side, a sizable
query against a very large file can take forever, and ends up hanging.
This commit adds an API function `ts_query_cursor_set_timeout_micros` to
limit how long query execution is allowed to take, thereby negating the
chance of a hang to occur.
2024-08-31 14:33:28 -04:00
Amaan Qureshi
6dd459b4ab fix(lib): an empty root node should not precede an empty range
The problem is, given an empty file, the root node of this file spans 0
bytes. As such, the logic for determining whether or not the node
precedes the range fails, and is true when it should be false.
2024-08-17 17:05:26 -04:00
Amaan Qureshi
25c7189180 feat(lib): add ts_query_end_byte_for_pattern 2024-07-07 20:29:09 -04:00
Quentin LE DILAVREC
9610a84600
fix(lib): restrict pattern_map optimization when a wildcard step has an immediate first child
Co-authored-by: Amaan Qureshi <amaanq12@gmail.com>
2024-07-05 03:35:24 -04:00
Amaan Qureshi
037c71c7bd fix: apply some scan-build suggestions (unused assignment/garbage access) 2024-02-21 15:38:13 -05:00
Amaan Qureshi
fd91404ab0 style: tidying 2024-02-19 16:00:50 -05:00
Amaan Qureshi
da0596ba38 chore: remove deprecated query parsing mechanism 2024-02-13 13:35:32 -05:00
dundargoc
ff367ebf4c build: enable -pedantic
Co-authored-by: Patrick Thomson <patrickt@github.com>
2024-02-08 16:12:54 +01:00
dundargoc
df1fe842eb docs: various fixes
Closes https://github.com/tree-sitter/tree-sitter/issues/1317.
Closes https://github.com/tree-sitter/tree-sitter/issues/1752.
Closes https://github.com/tree-sitter/tree-sitter/issues/2439.

Co-authored-by: Simon Hengel <sol@typeful.net>
Co-authored-by: Akash Yadav <itsaky01@gmail.com>
Co-authored-by: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com>
Co-authored-by: Laytan Laats <laytanlaats@hotmail.com>
2024-02-08 00:08:59 +01:00
Max Brunsfeld
3c66dd2d6c Add missing language return in ts_query_new
Co-authored-by: Antonio <antonio@zed.dev>
Co-authored-by: Mikayla <mikayla@zed.dev>
Co-authored-by: Joseph <joseph@zed.dev>
2024-01-25 11:06:54 -08:00
Max Brunsfeld
4a8e4b1963 Allow wasm languages to be deleted 2023-12-27 15:00:16 -08:00
Andrew Hlynskyi
0d26309c41
Revert "chore(lib): fix fields naming in QueryPattern to singular" 2023-11-28 02:30:01 +02:00
MrPrezident
3c4957e940 fix "test_point_range_captures not working"
Fix for https://github.com/tree-sitter/py-tree-sitter/issues/105
2023-11-12 20:58:51 -06:00
Andrew Hlynskyi
055c329a69 chore(lib): fix fields naming in QueryPattern to singular 2023-09-02 21:08:54 +03:00
Amaan Qureshi
5c7098dd56
fix(query): debug print uses wrong variable 2023-08-22 19:22:31 -04:00
Andrew Hlynskyi
26c3ae7b98 Rename: ts_lookahead_iterator_advance -> ts_lookahead_iterator_next 2023-08-09 14:40:29 +03:00
Samuel Moelius
41ec8b4166 Partially revert d4d5e29 2023-08-03 11:41:50 +03:00
Amaan Qureshi
13f6ec2b0c
fix: rename shadowed variables from -Wshadow warnings and apply some useful clang-tidy warnings 2023-07-19 18:12:26 -04:00
Amaan Qureshi
8f73fb502f
Merge pull request #2408 from amaanq/codeql-bugs
fix(lib): explicitly cast numbers to the same size in potential spots for infinite loops
2023-07-19 16:11:43 -04:00
Amaan Qureshi
753fa1c3ff
fix(lib): explicitly cast numbers to the same size in potential spots for infinite loops 2023-07-19 03:49:14 -04:00
Samuel Moelius
a07cdb59f3
Handle edge cases involving consecutive "zero or" modifiers 2023-07-19 03:27:43 -04:00
Max Brunsfeld
40f7b2ec97 Fix parsing of queries that start with repetitions followed by alternatives 2023-07-18 17:57:52 -07:00
Amaan Qureshi
c16a8c71ce
fix: pass a value_id the same size of predicate_capture_ids's elements to avoid big-endian integer narrowing
This solves a bug on big-endian architectures where the value would be later passed by reference as an elements "view" before being inserted. The issue is it is casted as a void pointer, and when writing uint16_t's of size 1, only 2 of the 4 bytes are written. This is okay for little-endian systems, but not big-endian
2023-07-18 05:40:38 -04:00
Max Brunsfeld
356f68293a Fix false positive query match bug, introduced in #2085 2023-07-10 16:12:59 -04:00
Philipp Mildenberger
55a8db10cc fix: bug with first child group anchor (anchor had no effect) 2023-05-13 19:40:49 +03:00
Andrew Hlynskyi
4f4b86a40b lib: make query step init depend from MAX_STEP_CAPTURE_COUNT decl 2023-04-19 09:37:46 +03:00
Andrew Hlynskyi
d4d5e29c91 feat(lib): ts_query_cursor_set_max_start_depth - use 0 to reset 2023-04-17 11:16:04 +03:00
Lewis Russell
1e81a1b67f feat(lib): add ts_query_cursor_set_max_start_depth query API
This allows configuring cursors from traversing too deep into a tree.
2023-04-17 11:15:13 +03:00
Andrew Hlynskyi
4c2a36302b lib: fix OOB in query engine reported in #2162 2023-04-06 03:59:55 +03:00
Matt
65c16bfb17 query casts 2023-04-04 17:43:27 +03:00
Max Brunsfeld
837899e456 Add API for checking if a pattern in a query is non-local 2023-02-16 11:59:34 -08:00
Max Brunsfeld
40703f110c Fix bug in maintenance of query cursor's tree depth 2023-02-16 11:59:34 -08:00
Max Brunsfeld
fa869cf3ed Restructure query_cursor_advance to explicitly control which hidden nodes it descends into 2023-02-16 11:59:34 -08:00
Max Brunsfeld
189cf6d59d Group analysis state sets into QueryAnalysis struct 2023-02-16 11:59:34 -08:00