emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/relint ae7b790461: Better regexp position accuracy for


From: ELPA Syncer
Subject: [elpa] externals/relint ae7b790461: Better regexp position accuracy for treesit queries
Date: Fri, 16 Jun 2023 06:59:05 -0400 (EDT)

branch: externals/relint
commit ae7b790461f244cf5c74dea601d543e483c36150
Author: Mattias EngdegÄrd <mattiase@acm.org>
Commit: Mattias EngdegÄrd <mattiase@acm.org>

    Better regexp position accuracy for treesit queries
---
 relint.el        | 59 ++++++++++++++++++++++++++++++++------------------------
 test/1.expected  |  4 ++--
 test/14.expected | 20 +++++++++----------
 3 files changed, 46 insertions(+), 37 deletions(-)

diff --git a/relint.el b/relint.el
index 0bf6cb969c..0555930c3c 100644
--- a/relint.el
+++ b/relint.el
@@ -1232,22 +1232,34 @@ or in the car of an element."
         (relint--check-re-string (car elem) ident pos p)))))
    form path))
 
-(defun relint--check-treesit-query (form name pos path)
-  "Recursively check tree-sitter :match regexps in EXPR.
-FORM is assumed a non-literal in the source."
+(defun relint--check-treesit-query (form name pos path literal)
+  "Recursively check tree-sitter :match regexps in the value FORM.
+If LITERAL, then PATH is exact."
   (pcase form
-    (`(,_ . ,(or `((:match ,(and (pred stringp) re) . ,_))
-                 ;; Optional capture name.
-                 `(,(pred symbolp)
-                   (:match ,(and (pred stringp) re) . ,_))))
-     (relint--check-re-string re name pos path))
+    (`(,_ (:match ,(and (pred stringp) re) . ,_))
+     (relint--check-re-string re name
+                              pos (if literal (cons 1 (cons 1 path)) path)))
+    (`(,_ ,(pred symbolp) (:match ,(and (pred stringp) re) . ,_))
+     (relint--check-re-string re name
+                              pos (if literal (cons 1 (cons 2 path)) path)))
     ((pred consp)
-     (while (consp form)
-       (relint--check-treesit-query (car form) name pos path)
-       (setq form (cdr form))))
+     (let ((i 0))
+       (while (consp form)
+         (relint--check-treesit-query
+          (car form) name pos (if literal (cons i path) path) literal)
+         (setq form (cdr form))
+         (setq i (1+ i)))))
     ((pred vectorp)
      (dotimes (i (length form))
-       (relint--check-treesit-query (aref form i) name pos path)))))
+       (relint--check-treesit-query (aref form i) name pos path nil)))))
+
+(defun relint--check-treesit-queries (form name pos path)
+  "Evaluate and validate FORM as a list of tree-sitter queries."
+  (relint--eval-list-iter
+   (lambda (elem elem-path literal)
+     (relint--check-treesit-query
+      elem name pos elem-path literal))
+   form path))
 
 (defun relint--check-treesit-font-lock-rules (form name pos path)
   "Check tree-sitter font lock queries.
@@ -1255,12 +1267,12 @@ Evaluate and validate FORM as an arglist for
 `treesit-font-lock-rules'."
   (relint--eval-list-iter
    (let (skip-next)
-     (lambda (elem elem-path _literal)
+     (lambda (elem elem-path literal)
        (let ((skip skip-next))
          ;; Skip leading plists.
          (setq skip-next (keywordp elem))
          (unless (or skip skip-next)
-           (relint--check-treesit-query elem name pos elem-path)))))
+           (relint--check-treesit-query elem name pos elem-path literal)))))
    form path))
 
 (defun relint--check-treesit-indent-rule (form name pos path literal)
@@ -1287,8 +1299,7 @@ Evaluate and validate FORM as an arglist for
 
 (defun relint--check-treesit-indent-rules (form name pos path)
   "Check tree-sitter indentation rules.
-Evaluate and validate FORM as a value for
-`treesit-simple-indent-rules'."
+Evaluate and validate FORM as a value for `treesit-simple-indent-rules'."
   (relint--eval-list-iter
    (lambda (lang lang-path literal)
      (let ((lang-name (if (consp lang) (format "%s (%s)" name (car lang)) 
name))
@@ -2245,25 +2256,23 @@ directly."
           (while (consp items)
             (if (not (and (keywordp (car items))
                           (consp (cdr items))))
-                (relint--check-treesit-query (relint--eval-list (car items))
-                                             (format "call to %s" (car form))
-                                             pos (cons i path))
+                (relint--check-treesit-queries
+                 (car items) (format "call to %s" (car form))
+                 pos (cons i path))
               ;; Skip leading plists.
               (setq items (cdr items))
               (setq i (1+ i)))
             (setq items (cdr items))
             (setq i (1+ i)))))
        (`(treesit-query-expand ,query . ,_)
-        (relint--check-treesit-query (relint--eval-list query)
-                                     (format "call to %s" (car form))
-                                     pos (cons 1 path)))
+        (relint--check-treesit-queries query (format "call to %s" (car form))
+                                       pos (cons 1 path)))
        (`(,(or 'treesit-node-top-level 'treesit-query-capture
                'treesit-query-compile 'treesit-query-range
                'treesit-query-string)
           ,_ ,query . ,_)
-        (relint--check-treesit-query (relint--eval-list query)
-                                     (format "call to %s" (car form))
-                                     pos (cons 2 path)))
+        (relint--check-treesit-queries query (format "call to %s" (car form))
+                                       pos (cons 2 path)))
        (`(set (make-local-variable ',(and (pred symbolp) name)) ,expr)
         (cond ((memq name relint--known-regexp-variables)
                (relint--check-re expr name pos (cons 2 path)))
diff --git a/test/1.expected b/test/1.expected
index 3cd9441654..c816c57208 100644
--- a/test/1.expected
+++ b/test/1.expected
@@ -177,9 +177,9 @@
 1.elisp:114:8: In call to syntax-propertize-precompile-rules: Unescaped 
literal `^' (pos 2)
   "^4^"
    ..^
-1.elisp:116:34: In my-ts--font-lock-rules: Duplicated `5' inside character 
alternative (pos 2)
+1.elisp:116:50: In my-ts--font-lock-rules: Duplicated `5' inside character 
alternative (pos 2)
   "[55]"
    ..^
-1.elisp:117:38: In my-ts-mode-font-lock-rules: Duplicated `6' inside character 
alternative (pos 2)
+1.elisp:117:54: In my-ts-mode-font-lock-rules: Duplicated `6' inside character 
alternative (pos 2)
   "[66]"
    ..^
diff --git a/test/14.expected b/test/14.expected
index 4e3ae8a1c0..583def148d 100644
--- a/test/14.expected
+++ b/test/14.expected
@@ -1,30 +1,30 @@
-14.elisp:13:4: In call to treesit-font-lock-rules: Unescaped literal `+' (pos 
0)
+14.elisp:13:23: In call to treesit-font-lock-rules: Unescaped literal `+' (pos 
0)
   "+f+"
    ^
-14.elisp:13:4: In call to treesit-font-lock-rules: Unescaped literal `+' (pos 
0)
+14.elisp:14:6: In call to treesit-font-lock-rules: Unescaped literal `+' (pos 
0)
   "+g+"
    ^
-14.elisp:29:4: In call to treesit-range-rules: Unescaped literal `+' (pos 0)
+14.elisp:29:32: In call to treesit-range-rules: Unescaped literal `+' (pos 0)
   "+o+"
    ^
-14.elisp:29:4: In call to treesit-range-rules: Unescaped literal `+' (pos 0)
+14.elisp:30:6: In call to treesit-range-rules: Unescaped literal `+' (pos 0)
   "+p+"
    ^
-14.elisp:33:23: In call to treesit-query-expand: Unescaped literal `+' (pos 0)
+14.elisp:33:39: In call to treesit-query-expand: Unescaped literal `+' (pos 0)
   "+r+"
    ^
-14.elisp:36:2: In call to treesit-query-compile: Unescaped literal `+' (pos 0)
+14.elisp:37:4: In call to treesit-query-compile: Unescaped literal `+' (pos 0)
   "+t+"
    ^
-14.elisp:39:29: In call to treesit-node-top-level: Unescaped literal `+' (pos 
0)
+14.elisp:39:45: In call to treesit-node-top-level: Unescaped literal `+' (pos 
0)
   "+u+"
    ^
-14.elisp:40:28: In call to treesit-query-capture: Unescaped literal `+' (pos 0)
+14.elisp:40:44: In call to treesit-query-capture: Unescaped literal `+' (pos 0)
   "+v+"
    ^
-14.elisp:41:26: In call to treesit-query-range: Unescaped literal `+' (pos 0)
+14.elisp:41:42: In call to treesit-query-range: Unescaped literal `+' (pos 0)
   "+w+"
    ^
-14.elisp:42:27: In call to treesit-query-string: Unescaped literal `+' (pos 0)
+14.elisp:42:43: In call to treesit-query-string: Unescaped literal `+' (pos 0)
   "+x+"
    ^



reply via email to

[Prev in Thread] Current Thread [Next in Thread]