@@ -268,36 +268,30 @@ query = PY_LANGUAGE.query(
268268
269269``` python
270270captures = query.captures(tree.root_node)
271- assert len (captures) == 2
272- assert captures[0 ][0 ] == function_name_node
273- assert captures[0 ][1 ] == " function.def"
271+ assert len (captures) == 4
272+ assert captures[" function.def" ][0 ] == function_name_node
273+ assert captures[" function.block" ][0 ] == function_body_node
274+ assert captures[" function.call" ][0 ] == function_call_name_node
275+ assert captures[" function.args" ][0 ] == function_call_args_node
274276```
275277
276- The ` Query.captures() ` method takes optional ` start_point ` , ` end_point ` ,
277- ` start_byte ` and ` end_byte ` keyword arguments, which can be used to restrict the
278- query's range. Only one of the ` ..._byte ` or ` ..._point ` pairs need to be given
279- to restrict the range. If all are omitted, the entire range of the passed node
280- is used.
281-
282278#### Matches
283279
284280``` python
285281matches = query.matches(tree.root_node)
286282assert len (matches) == 2
287283
288284# first match
289- assert matches[0 ][1 ][" function.def" ] == function_name_node
290- assert matches[0 ][1 ][" function.block" ] == function_body_node
285+ assert matches[0 ][1 ][" function.def" ] == [ function_name_node]
286+ assert matches[0 ][1 ][" function.block" ] == [ function_body_node]
291287
292288# second match
293- assert matches[1 ][1 ][" function.call" ] == function_call_name_node
294- assert matches[1 ][1 ][" function.args" ] == function_call_args_node
289+ assert matches[1 ][1 ][" function.call" ] == [ function_call_name_node]
290+ assert matches[1 ][1 ][" function.args" ] == [ function_call_args_node]
295291```
296292
297- The ` Query.matches() ` method takes the same optional arguments as ` Query.captures() ` .
298293The difference between the two methods is that ` Query.matches() ` groups captures into matches,
299- which is much more useful when your captures within a query relate to each other. It maps the
300- capture's name to the node that was captured via a dictionary.
294+ which is much more useful when your captures within a query relate to each other.
301295
302296To try out and explore the code referenced in this README, check out [ examples/usage.py] .
303297
0 commit comments