diff options
| author | Yuan Fu | 2025-01-12 23:41:47 -0800 |
|---|---|---|
| committer | Yuan Fu | 2025-01-12 23:41:47 -0800 |
| commit | f0e63558bd3dfd9e57cacfba8690f9dd29774947 (patch) | |
| tree | 6dc0c6eeab5a926050eb1ced319909b11fb26b8f /doc | |
| parent | 4687fff4f0a473fd887bf0800976c356eecd7eb2 (diff) | |
| download | emacs-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.texi | 9 |
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 |
| 1599 | qualifies the node as the thing. It can be @w{@code{(and | ||
| 1600 | @var{pred}@dots{})}}, meaning that satisfying all of the @var{pred}s | ||
| 1599 | qualifies the node as the thing. It can be @w{@code{(not @var{pred})}}, | 1601 | qualifies the node as the thing. It can be @w{@code{(not @var{pred})}}, |
| 1600 | meaning that not satisfying @var{pred} qualifies the node. | 1602 | meaning that not satisfying @var{pred} qualifies the node. |
| 1601 | 1603 | ||
| @@ -1604,6 +1606,10 @@ list. For example, @w{@code{(or sexp sentence)}} defines something | |||
| 1604 | that's either a @code{sexp} thing or a @code{sentence} thing, as defined | 1606 | that's either a @code{sexp} thing or a @code{sentence} thing, as defined |
| 1605 | by some other rule in the alist. | 1607 | by some other rule in the alist. |
| 1606 | 1608 | ||
| 1609 | There are two pre-defined predicates: @code{named} and @code{anonymous}, | ||
| 1610 | that qualifies named and anonymous nodes, respectively. They can be | ||
| 1611 | combined with @code{and} to narrow down the match. | ||
| 1612 | |||
| 1607 | Here's an example @code{treesit-thing-settings} for C and C++: | 1613 | Here'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} | |||
| 1662 | is @code{t}, this function doesn't signal the error when @var{thing} is | 1668 | is @code{t}, this function doesn't signal the error when @var{thing} is |
| 1663 | undefined and just returns @code{nil}; but it still signals the error if | 1669 | undefined 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 | |||
| 2179 | defining variables such as @code{forward-sexp-function} and | 2184 | defining 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 | ||
| 2186 | For more information on these built-in tree-sitter features, | 2189 | For more information on these built-in tree-sitter features, |