[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/relint e1b1ef9 22/44: Run in two phases on each file
From: |
Mattias Engdeg�rd |
Subject: |
[elpa] externals/relint e1b1ef9 22/44: Run in two phases on each file |
Date: |
Tue, 26 Mar 2019 12:57:28 -0400 (EDT) |
branch: externals/relint
commit e1b1ef92b4427dcb964de93b6b7334ad1e30b7de
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Run in two phases on each file
In the first phase, only scan function signatures for regexp arguments.
In the second, do everything else.
This way, the order of function definitions in a file don't matter.
---
trawl.el | 132 ++++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 75 insertions(+), 57 deletions(-)
diff --git a/trawl.el b/trawl.el
index 809ca72..a5d84da 100644
--- a/trawl.el
+++ b/trawl.el
@@ -532,7 +532,43 @@
re (format "%s (%s)" name rule-name) file pos path)))))
(trawl--get-list form file pos path)))
-(defun trawl--check-form-recursively (form file pos path)
+(defun trawl--check-form-recursively-1 (form file pos path)
+ (pcase form
+ (`(,(or `defun `defmacro `defsubst)
+ ,name ,args . ,_)
+ ;; If any argument looks like a regexp, remember it so that it can be
+ ;; checked in calls.
+ (when (consp args)
+ (let ((indices nil)
+ (index 0))
+ (while args
+ (let ((arg (car args)))
+ (when (symbolp arg)
+ (cond
+ ((eq arg '&optional)) ; Treat optional args as regular.
+ ((eq arg '&rest)
+ (setq args nil)) ; Ignore &rest args.
+ (t
+ (when (string-match-p (rx (or (or "regexp" "regex" "-re"
+ "pattern")
+ (seq bos "re"))
+ eos)
+ (symbol-name arg))
+ (push index indices))
+ (setq index (1+ index)))))
+ (setq args (cdr args))))
+ (when indices
+ (push (cons name (reverse indices)) trawl--regexp-functions)))))
+ (_
+ (let ((index 0))
+ (while (consp form)
+ (when (consp (car form))
+ (trawl--check-form-recursively-1
+ (car form) file pos (cons index path)))
+ (setq form (cdr form))
+ (setq index (1+ index)))))))
+
+(defun trawl--check-form-recursively-2 (form file pos path)
(pcase form
(`(,(or `looking-at `re-search-forward `re-search-backward
`string-match `string-match-p `looking-back `looking-at-p
@@ -613,30 +649,6 @@
(trawl--check-font-lock-keywords font-lock-list origin
file pos (cons 4 path))
(trawl--check-list auto-mode-list origin file pos (cons 5 path))))
- (`(,(or `defun `defmacro `defsubst)
- ,name ,args . ,_)
- ;; If any argument looks like a regexp, remember it so that it can be
- ;; checked in calls.
- (when (consp args)
- (let ((indices nil)
- (index 0))
- (while args
- (let ((arg (car args)))
- (when (symbolp arg)
- (cond
- ((eq arg '&optional))
- ((eq arg '&rest)
- (setq args nil))
- (t
- (when (or (string-suffix-p "regexp" (symbol-name arg))
- (string-suffix-p "regex" (symbol-name arg))
- (eq arg 're)
- (string-suffix-p "-re" (symbol-name arg)))
- (push index indices))
- (setq index (1+ index)))))
- (setq args (cdr args))))
- (when indices
- (push (cons name (reverse indices)) trawl--regexp-functions)))))
)
;; Check calls to remembered functions with regexp arguments.
@@ -658,55 +670,61 @@
(let ((index 0))
(while (consp form)
(when (consp (car form))
- (trawl--check-form-recursively (car form) file pos (cons index path)))
+ (trawl--check-form-recursively-2 (car form) file pos (cons index
path)))
(setq form (cdr form))
(setq index (1+ index)))))
-(defun trawl--check-toplevel-form (form file pos)
- (when (consp form)
- (trawl--check-form-recursively form file pos nil)))
-
(defun trawl--show-errors ()
(unless noninteractive
(let ((pop-up-windows t))
(display-buffer (trawl--error-buffer))
(sit-for 0))))
+(defun trawl--check-buffer (file forms function)
+ (dolist (form forms)
+ (funcall function (car form) file (cdr form) nil)))
+
+;; Read top-level forms from the current buffer.
+;; Return a list of (FORM . STARTING-POSITION).
+(defun trawl--read-buffer (file)
+ (goto-char (point-min))
+ (let ((pos nil)
+ (keep-going t)
+ (read-circle nil)
+ (forms nil))
+ (while keep-going
+ (setq pos (point))
+ (let ((form nil))
+ (condition-case err
+ (setq form (read (current-buffer)))
+ (end-of-file
+ (setq keep-going nil))
+ (invalid-read-syntax
+ (cond
+ ((equal (cadr err) "#")
+ (goto-char pos)
+ (forward-sexp 1))
+ (t
+ (trawl--report file (point) nil (prin1-to-string err))
+ (setq keep-going nil))))
+ (error
+ (trawl--report file (point) nil (prin1-to-string err))
+ (setq keep-going nil)))
+ (when (consp form)
+ (push (cons form pos) forms))))
+ (nreverse forms)))
+
(defun trawl--single-file (file)
(let ((errors-before trawl--error-count))
(with-temp-buffer
(emacs-lisp-mode)
(insert-file-contents file)
- (goto-char (point-min))
- (let ((pos nil)
- (keep-going t)
- (read-circle nil)
+ (let ((forms (trawl--read-buffer file))
(trawl--variables nil)
(trawl--checked-variables nil)
(trawl--regexp-functions nil))
- (while keep-going
- (setq pos (point))
- ;;(trawl--report file (point) nil "reading")
- (let ((form nil))
- (condition-case err
- (setq form (read (current-buffer)))
- (end-of-file
- (setq keep-going nil))
- (invalid-read-syntax
- (cond
- ((equal (cadr err) "#")
- (goto-char pos)
- (forward-sexp 1))
- (t
- (trawl--report file (point) nil
- (prin1-to-string err))
- (setq keep-going nil))))
- (error
- (trawl--report file (point) nil
- (prin1-to-string err))
- (setq keep-going nil)))
- (when form
- (trawl--check-toplevel-form form file pos))))))
+ (trawl--check-buffer file forms #'trawl--check-form-recursively-1)
+ (trawl--check-buffer file forms #'trawl--check-form-recursively-2)))
(when (> trawl--error-count errors-before)
(trawl--show-errors))))
- [elpa] externals/relint d4a6d46 37/44: Evaluate some more functions, macros and special forms, (continued)
- [elpa] externals/relint d4a6d46 37/44: Evaluate some more functions, macros and special forms, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint 019f4cf 10/44: Rewrite the partial evaluator and extend coverage, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint 365dc91 41/44: Check bad skip-set provenance, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint a1829d7 39/44: Refactor the file scanning and linting code, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint 0f76132 40/44: Add README.org, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint e824db0 38/44: Expand locally defined macros, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint c215d54 34/44: More careful evaluation of if, when, unless, and, or, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint 15c799e 35/44: Evaluate calls to functions defined in the same file., Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint 2d1f488 32/44: mapcar on non-list sequence, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint af745bb 30/44: Update the package description. Increment version to 1.4, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint e1b1ef9 22/44: Run in two phases on each file,
Mattias Engdeg�rd <=
- [elpa] externals/relint 7a1b632 33/44: Add wildcard-to-regexp as 'pure' function, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint f6fb8e6 31/44: Sundry cosmetic fixes, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint 151dbb8 23/44: Handle some destructive list functions, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint 187d586 27/44: Scan arguments to `skip-chars-{forward, backward}', Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint 5af5466 26/44: Scan string-trim arguments, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint 4dbcad9 24/44: Increment version to 1.2, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint 104e66c 15/44: Fix bugs in evaluation of `rx' and `rx-to-strings', Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint 3f8509a 13/44: Add more functions to check for regexp arguments, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint f8878ca 16/44: Report rx errors in the result buffer, Mattias Engdeg�rd, 2019/03/26
- [elpa] externals/relint 8e37762 18/44: Protect against improper lists in function calls, Mattias Engdeg�rd, 2019/03/26