@@ -251,7 +251,8 @@ for changed_range in tree.changed_ranges(new_tree):
251251You can search for patterns in a syntax tree using a [ tree query] :
252252
253253``` python
254- query = PY_LANGUAGE .query(
254+ query = Query(
255+ PY_LANGUAGE ,
255256 """
256257(function_definition
257258 name: (identifier) @function.def
@@ -260,14 +261,15 @@ query = PY_LANGUAGE.query(
260261(call
261262 function: (identifier) @function.call
262263 arguments: (argument_list) @function.args)
263- """
264+ """ ,
264265)
265266```
266267
267268#### Captures
268269
269270``` python
270- captures = query.captures(tree.root_node)
271+ query_cursor = QueryCursor(query)
272+ captures = query_cursor.captures(tree.root_node)
271273assert len (captures) == 4
272274assert captures[" function.def" ][0 ] == function_name_node
273275assert captures[" function.block" ][0 ] == function_body_node
@@ -278,7 +280,7 @@ assert captures["function.args"][0] == function_call_args_node
278280#### Matches
279281
280282``` python
281- matches = query .matches(tree.root_node)
283+ matches = query_cursor .matches(tree.root_node)
282284assert len (matches) == 2
283285
284286# first match
@@ -290,7 +292,7 @@ assert matches[1][1]["function.call"] == [function_call_name_node]
290292assert matches[1 ][1 ][" function.args" ] == [function_call_args_node]
291293```
292294
293- The difference between the two methods is that ` Query .matches()` groups captures into matches,
295+ The difference between the two methods is that ` QueryCursor .matches()` groups captures into matches,
294296which is much more useful when your captures within a query relate to each other.
295297
296298To try out and explore the code referenced in this README, check out [ examples/usage.py] .
0 commit comments