Skip to content

Commit c70d44f

Browse files
feat(query)!: improve implementation
- Implement more methods - Support custom predicates - Add custom QueryError exception
1 parent 722862b commit c70d44f

21 files changed

+1436
-937
lines changed

.clang-format

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ PointerAlignment: Right
55
IndentWidth: 4
66
ColumnLimit: 100
77
IncludeBlocks: Preserve
8-
StatementMacros: [PyObject_HEAD, PyObject_VAR_HEAD, _PyObject_HEAD_EXTRA]
8+
StatementMacros: [PyObject_HEAD]
99
BinPackArguments: true
10+
IndentCaseLabels: true

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ indent_size = 2
1212
[*.rst]
1313
indent_size = 3
1414

15-
[*.{c,h,py}]
15+
[*.{c,h,py,pyi}]
1616
indent_size = 4
1717
max_line_length = 100

docs/classes/tree_sitter.Language.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Language
77

88
The argument can now be a `capsule <https://docs.python.org/3/c-api/capsule.html>`_.
99

10-
1110
Methods
1211
-------
1312

@@ -33,7 +32,6 @@ Language
3332
.. automethod:: __ne__
3433
.. automethod:: __repr__
3534

36-
3735
Attributes
3836
----------
3937

docs/classes/tree_sitter.LookaheadIterator.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ LookaheadIterator
22
=================
33

44
.. autoclass:: tree_sitter.LookaheadIterator
5+
:show-inheritance:
56

67
Methods
78
-------
89

910
.. automethod:: iter_names
1011
.. automethod:: reset_state
1112

12-
Special methods
13+
Special Methods
1314
---------------
1415

1516
.. automethod:: __iter__

docs/classes/tree_sitter.Parser.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Parser
66
Methods
77
-------
88

9-
109
.. automethod:: parse
1110

1211
.. versionchanged:: 0.23.0

docs/classes/tree_sitter.Point.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Point
22
=====
33

44
.. autoclass:: tree_sitter.Point
5+
:show-inheritance:
56

67
Attributes
78
----------

docs/classes/tree_sitter.Query.rst

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,95 @@ Query
33

44
.. autoclass:: tree_sitter.Query
55

6+
.. seealso:: `Query Syntax`_
7+
8+
.. _Query Syntax: https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax
9+
10+
.. note::
11+
12+
The following predicates are supported by default:
13+
14+
* ``#eq?``, ``#not-eq?``, ``#any-eq?``, ``#any-not-eq?``
15+
* ``#match?``, ``#not-match?``, ``#any-match?``, ``#any-not-match?``
16+
* ``#any-of?``, ``#not-any-of?``
17+
* ``#is?``, ``#is-not?``
18+
* ``#set!``
19+
620
Methods
721
-------
822

923
.. automethod:: captures
24+
25+
.. important::
26+
27+
Predicates cannot be used if the tree was parsed from a callback.
28+
29+
.. versionchanged:: 0.23.0
30+
31+
Range arguments removed, :class:`predicate <QueryPredicate>` argument added,
32+
return type changed to ``dict[str, list[Node]]``.
33+
.. automethod:: disable_capture
34+
35+
.. versionadded:: 0.23.0
36+
.. automethod:: disable_pattern
37+
38+
.. versionadded:: 0.23.0
39+
.. automethod:: end_byte_for_pattern
40+
41+
.. versionadded:: 0.23.0
42+
.. automethod:: is_pattern_guaranteed_at_step
43+
44+
.. versionadded:: 0.23.0
45+
.. automethod:: is_pattern_non_local
46+
47+
.. versionadded:: 0.23.0
48+
.. automethod:: is_pattern_rooted
49+
50+
.. versionadded:: 0.23.0
1051
.. automethod:: matches
52+
53+
.. important::
54+
55+
Predicates cannot be used if the tree was parsed from a callback.
56+
57+
.. versionchanged:: 0.23.0
58+
59+
Range arguments removed, :class:`predicate <QueryPredicate>` argument added,
60+
return type changed to ``list[tuple[int, dict[str, list[Node]]]]``.
61+
.. automethod:: pattern_assertions
62+
63+
.. versionadded:: 0.23.0
64+
.. automethod:: pattern_settings
65+
66+
.. versionadded:: 0.23.0
67+
.. automethod:: set_byte_range
68+
69+
.. versionadded:: 0.23.0
70+
.. automethod:: set_point_range
71+
72+
.. versionadded:: 0.23.0
73+
.. automethod:: start_byte_for_pattern
74+
75+
.. versionadded:: 0.23.0
76+
.. automethod:: set_match_limit
77+
78+
.. versionadded:: 0.23.0
79+
.. automethod:: set_max_start_depth
80+
81+
.. versionadded:: 0.23.0
82+
83+
Attributes
84+
----------
85+
86+
.. autoattribute:: capture_count
87+
88+
.. versionadded:: 0.23.0
89+
.. autoattribute:: did_exceed_match_limit
90+
91+
.. versionadded:: 0.23.0
92+
.. autoattribute:: match_limit
93+
94+
.. versionadded:: 0.23.0
95+
.. autoattribute:: pattern_count
96+
97+
.. versionadded:: 0.23.0
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
QueryError
2+
==========
3+
4+
.. autoclass:: tree_sitter.QueryError
5+
:show-inheritance:
6+
7+
.. versionadded:: 0.23.0
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
QueryPredicate
2+
==============
3+
4+
.. autoclass:: tree_sitter.QueryPredicate
5+
:show-inheritance:
6+
7+
.. versionadded:: 0.23.0
8+
9+
Special Methods
10+
---------------
11+
12+
.. automethod:: __call__

docs/classes/tree_sitter.TreeCursor.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
TreeCursor
1+
TreeCursor
22
----------
33

44
.. autoclass:: tree_sitter.TreeCursor
@@ -10,19 +10,27 @@
1010
.. automethod:: goto_descendant
1111
.. automethod:: goto_first_child
1212
.. automethod:: goto_first_child_for_byte
13+
14+
.. versionchanged:: 0.23.0
15+
16+
Returns the child index instead of a `bool`.
1317
.. automethod:: goto_first_child_for_point
18+
19+
.. versionchanged:: 0.23.0
20+
21+
Returns the child index instead of a `bool`.
1422
.. automethod:: goto_last_child
1523
.. automethod:: goto_next_sibling
1624
.. automethod:: goto_parent
1725
.. automethod:: goto_previous_sibling
1826
.. automethod:: reset
1927
.. automethod:: reset_to
2028

21-
Special methods
29+
Special Methods
2230
---------------
2331

2432
.. automethod:: __copy__
25-
33+
2634
Attributes
2735
----------
2836

0 commit comments

Comments
 (0)