aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYuan Fu2023-04-13 18:45:07 -0700
committerYuan Fu2023-04-13 18:47:41 -0700
commitde34de3b35cbe1da6fb035b93081e0564b3c7b3f (patch)
tree58da547b9fcfd362eb252c35c024cc6298a4db7e /src
parent3ef54c64fa8e7236458228db09fe7192350cbeb6 (diff)
downloademacs-de34de3b35cbe1da6fb035b93081e0564b3c7b3f.tar.gz
emacs-de34de3b35cbe1da6fb035b93081e0564b3c7b3f.zip
Fix previous commit on tree-sitter
* src/treesit.c: (treesit_traverse_validate_predicate): Don't accept symbols. (treesit_traverse_match_predicate): Don't accept symbols, and use correct variable for the regexp and pred check. * test/src/treesit-tests.el: (treesit-search-forward-predicate): Fix the test.
Diffstat (limited to 'src')
-rw-r--r--src/treesit.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/treesit.c b/src/treesit.c
index 45b5ab15390..d0d9c50c14f 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -3148,9 +3148,7 @@ treesit_traverse_validate_predicate (Lisp_Object pred,
3148{ 3148{
3149 if (STRINGP (pred)) 3149 if (STRINGP (pred))
3150 return true; 3150 return true;
3151 /* We want to allow cl-labels-defined functions, so we allow 3151 else if (FUNCTIONP (pred))
3152 symbols. */
3153 else if (FUNCTIONP (pred) || SYMBOLP (pred))
3154 return true; 3152 return true;
3155 else if (CONSP (pred)) 3153 else if (CONSP (pred))
3156 { 3154 {
@@ -3194,8 +3192,7 @@ treesit_traverse_validate_predicate (Lisp_Object pred,
3194 } 3192 }
3195 return true; 3193 return true;
3196 } 3194 }
3197 /* We allow the function to be a symbol to support cl-label. */ 3195 else if (STRINGP (car) && FUNCTIONP (cdr))
3198 else if (STRINGP (car) && (FUNCTIONP (cdr) || SYMBOLP (cdr)))
3199 return true; 3196 return true;
3200 } 3197 }
3201 *signal_data = list2 (build_string ("Invalid predicate, see TODO for " 3198 *signal_data = list2 (build_string ("Invalid predicate, see TODO for "
@@ -3230,9 +3227,7 @@ treesit_traverse_match_predicate (TSTreeCursor *cursor, Lisp_Object pred,
3230 const char *type = ts_node_type (node); 3227 const char *type = ts_node_type (node);
3231 return fast_c_string_match (pred, type, strlen (type)) >= 0; 3228 return fast_c_string_match (pred, type, strlen (type)) >= 0;
3232 } 3229 }
3233 /* We want to allow cl-labels-defined functions, so we allow 3230 else if (FUNCTIONP (pred))
3234 symbols. */
3235 else if (FUNCTIONP (pred) || SYMBOLP (pred))
3236 { 3231 {
3237 Lisp_Object lisp_node = make_treesit_node (parser, node); 3232 Lisp_Object lisp_node = make_treesit_node (parser, node);
3238 return !NILP (CALLN (Ffuncall, pred, lisp_node)); 3233 return !NILP (CALLN (Ffuncall, pred, lisp_node));
@@ -3255,17 +3250,15 @@ treesit_traverse_match_predicate (TSTreeCursor *cursor, Lisp_Object pred,
3255 } 3250 }
3256 return false; 3251 return false;
3257 } 3252 }
3258 /* We want to allow cl-labels-defined functions, so we allow 3253 else if (STRINGP (car) && FUNCTIONP (cdr))
3259 symbols. */
3260 else if (STRINGP (car) && (FUNCTIONP (cdr) || SYMBOLP (cdr)))
3261 { 3254 {
3262 /* A bit of code duplication here, but should be fine. */ 3255 /* A bit of code duplication here, but should be fine. */
3263 const char *type = ts_node_type (node); 3256 const char *type = ts_node_type (node);
3264 if (!(fast_c_string_match (pred, type, strlen (type)) >= 0)) 3257 if (!(fast_c_string_match (car, type, strlen (type)) >= 0))
3265 return false; 3258 return false;
3266 3259
3267 Lisp_Object lisp_node = make_treesit_node (parser, node); 3260 Lisp_Object lisp_node = make_treesit_node (parser, node);
3268 if (NILP (CALLN (Ffuncall, pred, lisp_node))) 3261 if (NILP (CALLN (Ffuncall, cdr, lisp_node)))
3269 return false; 3262 return false;
3270 3263
3271 return true; 3264 return true;