From 838fc77254286de318b65602b31c6d3915594a8e Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Wed, 9 Nov 2022 12:29:50 -0800 Subject: [PATCH] Make tree-sitter node type match case-sensitive * doc/lispref/parsing.texi (Retrieving Node): Update manual. * src/treesit.c (treesit_traverse_match_predicate): Change to fast_c_string_match. (Ftreesit_search_subtree) (Ftreesit_search_forward) (Ftreesit_induce_sparse_tree): Update docstring. --- doc/lispref/parsing.texi | 17 ++++++++--------- src/treesit.c | 12 +++++------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi index 0a0104b4be0..bc2f0dda91c 100644 --- a/doc/lispref/parsing.texi +++ b/doc/lispref/parsing.texi @@ -650,10 +650,9 @@ is non-@code{nil}, it looks for smallest named child. This function traverses the subtree of @var{node} (including @var{node} itself), looking for a node for which @var{predicate} returns non-@code{nil}. @var{predicate} is a regexp that is matched -(case-insensitively) against each node's type, or a predicate function -that takes a node and returns non-@code{nil} if the node matches. The -function returns the first node that matches, or @code{nil} if none -does. +against each node's type, or a predicate function that takes a node +and returns non-@code{nil} if the node matches. The function returns +the first node that matches, or @code{nil} if none does. By default, this function only traverses named nodes, but if @var{all} is non-@code{nil}, it traverses all the nodes. If @var{backward} is @@ -666,9 +665,9 @@ down the tree. @defun treesit-search-forward start predicate &optional backward all Like @code{treesit-search-subtree}, this function also traverses the parse tree and matches each node with @var{predicate} (except for -@var{start}), where @var{predicate} can be a (case-insensitive) regexp -or a function. For a tree like the below where @var{start} is marked -S, this function traverses as numbered from 1 to 12: +@var{start}), where @var{predicate} can be a regexp or a function. +For a tree like the below where @var{start} is marked S, this function +traverses as numbered from 1 to 12: @example @group @@ -723,8 +722,8 @@ This function creates a sparse tree from @var{root}'s subtree. It takes the subtree under @var{root}, and combs it so only the nodes that match @var{predicate} are left. Like previous functions, the @var{predicate} can be a regexp string that matches against each -node's type case-insensitively, or a function that takes a node and -return non-@code{nil} if it matches. +node's type, or a function that takes a node and return non-@code{nil} +if it matches. For example, for a subtree on the left that consist of both numbers and letters, if @var{predicate} is ``letter only'', the returned tree diff --git a/src/treesit.c b/src/treesit.c index 48d650f1fc9..63785b2122c 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -2476,7 +2476,7 @@ treesit_traverse_match_predicate (TSNode node, Lisp_Object pred, if (STRINGP (pred)) { const char *type = ts_node_type (node); - return fast_c_string_match_ignore_case (pred, type, strlen (type)) >= 0; + return fast_c_string_match (pred, type, strlen (type)) >= 0; } else { @@ -2594,8 +2594,7 @@ DEFUN ("treesit-search-subtree", Traverse the subtree of NODE, and match PREDICATE with each node along the way. PREDICATE is a regexp string that matches against each -node's type case-insensitively, or a function that takes a node and -returns nil/non-nil. +node's type, or a function that takes a node and returns nil/non-nil. By default, only traverse named nodes, but if ALL is non-nil, traverse all nodes. If BACKWARD is non-nil, traverse backwards. If LIMIT is @@ -2639,8 +2638,8 @@ DEFUN ("treesit-search-forward", Start traversing the tree from node START, and match PREDICATE with each node (except START itself) along the way. PREDICATE is a regexp -string that matches against each node's type case-insensitively, or a -function that takes a node and returns non-nil if it matches. +string that matches against each node's type, or a function that takes +a node and returns non-nil if it matches. By default, only search for named nodes, but if ALL is non-nil, search for all nodes. If BACKWARD is non-nil, search backwards. @@ -2737,8 +2736,7 @@ DEFUN ("treesit-induce-sparse-tree", This takes the subtree under ROOT, and combs it so only the nodes that match PREDICATE are left, like picking out grapes on the vine. -PREDICATE is a regexp string that matches against each node's type -case-insensitively. +PREDICATE is a regexp string that matches against each node's type. For a subtree on the left that consist of both numbers and letters, if PREDICATE is "is letter", the returned tree is the one on the right. -- 2.39.5