From: Yuan Fu Date: Fri, 14 Apr 2023 01:45:07 +0000 (-0700) Subject: Fix previous commit on tree-sitter X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=de34de3b35cbe1da6fb035b93081e0564b3c7b3f;p=emacs.git 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. --- 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, { if (STRINGP (pred)) return true; - /* We want to allow cl-labels-defined functions, so we allow - symbols. */ - else if (FUNCTIONP (pred) || SYMBOLP (pred)) + else if (FUNCTIONP (pred)) return true; else if (CONSP (pred)) { @@ -3194,8 +3192,7 @@ treesit_traverse_validate_predicate (Lisp_Object pred, } return true; } - /* We allow the function to be a symbol to support cl-label. */ - else if (STRINGP (car) && (FUNCTIONP (cdr) || SYMBOLP (cdr))) + else if (STRINGP (car) && FUNCTIONP (cdr)) return true; } *signal_data = list2 (build_string ("Invalid predicate, see TODO for " @@ -3230,9 +3227,7 @@ treesit_traverse_match_predicate (TSTreeCursor *cursor, Lisp_Object pred, const char *type = ts_node_type (node); return fast_c_string_match (pred, type, strlen (type)) >= 0; } - /* We want to allow cl-labels-defined functions, so we allow - symbols. */ - else if (FUNCTIONP (pred) || SYMBOLP (pred)) + else if (FUNCTIONP (pred)) { Lisp_Object lisp_node = make_treesit_node (parser, node); return !NILP (CALLN (Ffuncall, pred, lisp_node)); @@ -3255,17 +3250,15 @@ treesit_traverse_match_predicate (TSTreeCursor *cursor, Lisp_Object pred, } return false; } - /* We want to allow cl-labels-defined functions, so we allow - symbols. */ - else if (STRINGP (car) && (FUNCTIONP (cdr) || SYMBOLP (cdr))) + else if (STRINGP (car) && FUNCTIONP (cdr)) { /* A bit of code duplication here, but should be fine. */ const char *type = ts_node_type (node); - if (!(fast_c_string_match (pred, type, strlen (type)) >= 0)) + if (!(fast_c_string_match (car, type, strlen (type)) >= 0)) return false; Lisp_Object lisp_node = make_treesit_node (parser, node); - if (NILP (CALLN (Ffuncall, pred, lisp_node))) + if (NILP (CALLN (Ffuncall, cdr, lisp_node))) return false; return true; diff --git a/test/src/treesit-tests.el b/test/src/treesit-tests.el index 26a21c34152..34f9f15beaa 100644 --- a/test/src/treesit-tests.el +++ b/test/src/treesit-tests.el @@ -363,11 +363,12 @@ BODY is the test body." while cursor do (should (equal (treesit-node-text cursor) text))) ;; Test (regexp . function) - (cl-labels ((is-odd (string) - (and (eq 1 (length string)) - (cl-oddp (string-to-number string))))) + (let ((is-odd (lambda (node) + (let ((string (treesit-node-text node))) + (and (eq 1 (length string)) + (cl-oddp (string-to-number string))))))) (cl-loop for cursor = (treesit-node-child array 0) - then (treesit-search-forward cursor '("number" . is-odd) + then (treesit-search-forward cursor `("number" . ,is-odd) nil t) for text in '("[" "1" "3" "5" "7" "9") while cursor