aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorYuan Fu2025-01-12 23:41:47 -0800
committerYuan Fu2025-01-12 23:41:47 -0800
commitf0e63558bd3dfd9e57cacfba8690f9dd29774947 (patch)
tree6dc0c6eeab5a926050eb1ced319909b11fb26b8f /doc
parent4687fff4f0a473fd887bf0800976c356eecd7eb2 (diff)
downloademacs-f0e63558bd3dfd9e57cacfba8690f9dd29774947.tar.gz
emacs-f0e63558bd3dfd9e57cacfba8690f9dd29774947.zip
Add 'and', 'named', and 'anonymous' predicate for tree-sitter
* doc/lispref/parsing.texi (User-defined Things): Mention the new predicate. * src/treesit.c (treesit_traverse_validate_predicate): Recognize named, anonymous, and and predicates. (treesit_traverse_match_predicate): Handle named, anonymous, and and predicates.
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/parsing.texi9
1 files changed, 6 insertions, 3 deletions
diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi
index e16aea6a38d..3e44f31c12c 100644
--- a/doc/lispref/parsing.texi
+++ b/doc/lispref/parsing.texi
@@ -1596,6 +1596,8 @@ the thing.
1596 1596
1597@var{pred} can also be recursively defined. It can be @w{@code{(or 1597@var{pred} can also be recursively defined. It can be @w{@code{(or
1598@var{pred}@dots{})}}, meaning that satisfying any one of the @var{pred}s 1598@var{pred}@dots{})}}, meaning that satisfying any one of the @var{pred}s
1599qualifies the node as the thing. It can be @w{@code{(and
1600@var{pred}@dots{})}}, meaning that satisfying all of the @var{pred}s
1599qualifies the node as the thing. It can be @w{@code{(not @var{pred})}}, 1601qualifies the node as the thing. It can be @w{@code{(not @var{pred})}},
1600meaning that not satisfying @var{pred} qualifies the node. 1602meaning that not satisfying @var{pred} qualifies the node.
1601 1603
@@ -1604,6 +1606,10 @@ list. For example, @w{@code{(or sexp sentence)}} defines something
1604that's either a @code{sexp} thing or a @code{sentence} thing, as defined 1606that's either a @code{sexp} thing or a @code{sentence} thing, as defined
1605by some other rule in the alist. 1607by some other rule in the alist.
1606 1608
1609There are two pre-defined predicates: @code{named} and @code{anonymous},
1610that qualifies named and anonymous nodes, respectively. They can be
1611combined with @code{and} to narrow down the match.
1612
1607Here's an example @code{treesit-thing-settings} for C and C++: 1613Here's an example @code{treesit-thing-settings} for C and C++:
1608 1614
1609@example 1615@example
@@ -1662,7 +1668,6 @@ signals @code{treesit-invalid-predicate} error. If @var{ignore-missing}
1662is @code{t}, this function doesn't signal the error when @var{thing} is 1668is @code{t}, this function doesn't signal the error when @var{thing} is
1663undefined and just returns @code{nil}; but it still signals the error if 1669undefined and just returns @code{nil}; but it still signals the error if
1664@var{thing} is a malformed predicate. 1670@var{thing} is a malformed predicate.
1665
1666@end defun 1671@end defun
1667 1672
1668@defun treesit-thing-prev position thing 1673@defun treesit-thing-prev position thing
@@ -2179,8 +2184,6 @@ navigation commands that move, respectively, by sexps and sentences by
2179defining variables such as @code{forward-sexp-function} and 2184defining variables such as @code{forward-sexp-function} and
2180@code{forward-sentence-function}. 2185@code{forward-sentence-function}.
2181@end itemize 2186@end itemize
2182
2183@c TODO: Add treesit-thing-settings stuff once we finalize it.
2184@end defun 2187@end defun
2185 2188
2186For more information on these built-in tree-sitter features, 2189For more information on these built-in tree-sitter features,