QueryPredicate

QueryPredicate#

class tree_sitter.QueryPredicate#

Bases: Protocol

A custom query predicate that runs on a pattern.

Special Methods#

__call__(predicate, args, pattern_index, captures)#
Parameters:
  • predicate (str) – The name of the predicate.

  • args (list[tuple[str, Literal['capture', 'string']]]) – The arguments to the predicate.

  • pattern_index (int) – The index of the pattern within the query.

  • captures (dict[str, list[Node]]) – The captures contained in the pattern.

Returns:

True if the predicate matches, False otherwise.

Tip

You don’t need to create an actual class, just a function with this signature.