[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/relint f8878ca 16/44: Report rx errors in the result bu
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/relint f8878ca 16/44: Report rx errors in the result buffer |
Date: |
Tue, 26 Mar 2019 12:57:26 -0400 (EDT) |
branch: externals/relint
commit f8878ca325cd093374c176f8dc671df8cdd07dbe
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Report rx errors in the result buffer
Previously, rx errors aborted the entire run; now they are reported
like any other.
---
trawl.el | 60 +++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 37 insertions(+), 23 deletions(-)
diff --git a/trawl.el b/trawl.el
index 0ae230c..51dbb55 100644
--- a/trawl.el
+++ b/trawl.el
@@ -200,6 +200,16 @@
((memq (car form) '(any in char not-char)) t)
(t (not (memq nil (mapcar #'trawl--rx-safe (cdr form)))))))
+(define-error 'trawl--eval-error "trawl expression evaluation error")
+
+;; Evaluate an `rx-to-string' expression if safe.
+(defun trawl--eval-rx (args)
+ (if (trawl--rx-safe (car args))
+ (condition-case err
+ (apply #'rx-to-string args)
+ (error (signal 'trawl--eval-error (format "rx error: %s" (cadr err)))))
+ 'no-value))
+
;; Evaluate a form as far as possible. Substructures that cannot be evaluated
;; become `no-value'.
(defun trawl--eval (form)
@@ -227,10 +237,11 @@
;; Common functions that aren't marked as side-effect-free.
(memq (car form) '(caar cadr cdar cddr
regexp-opt regexp-opt-charset
+ ;; alters last-coding-system-used
decode-coding-string
format-message format-spec
purecopy remove remq
- ;; We don't mind them changing the match state.
+ ;; alters match state
string-match string-match-p)))
(let ((args (mapcar #'trawl--eval (cdr form))))
(if (memq 'no-value args)
@@ -311,17 +322,13 @@
;; rx, rx-to-string: check for (eval ...) constructs first, then apply.
((eq (car form) 'rx)
- (if (trawl--rx-safe (cons 'seq (cdr form)))
- (trawl--eval (macroexpand form))
- 'no-value))
+ (trawl--eval-rx (list (cons 'seq (cdr form)) t)))
((eq (car form) 'rx-to-string)
- (let ((arg (trawl--eval (cadr form))))
- (if (trawl--rx-safe arg)
- (if (eq arg 'no-value)
- 'no-value
- (apply 'rx-to-string (list arg))))
- 'no-value))
+ (let ((args (mapcar #'trawl--eval (cdr form))))
+ (if (memq 'no-value args)
+ 'no-value
+ (trawl--eval-rx args))))
;; setq: Ignore its side-effect and just pass on the value.
((eq (car form) 'setq)
@@ -405,24 +412,31 @@
(if (eq val 'no-value) nil val)))))
;; Convert something to a list, or nil.
-(defun trawl--get-list (form)
- (let ((val (trawl--eval-list form)))
- (and (consp val) val)))
+(defun trawl--get-list (form file pos path)
+ (condition-case err
+ (let ((val (trawl--eval-list form)))
+ (and (consp val) val))
+ (trawl--eval-error (trawl--report file pos path (cdr err))
+ nil)))
+
;; Convert something to a string, or nil.
-(defun trawl--get-string (form)
- (let ((val (trawl--eval form)))
- (and (stringp val) val)))
+(defun trawl--get-string (form file pos path)
+ (condition-case err
+ (let ((val (trawl--eval form)))
+ (and (stringp val) val))
+ (trawl--eval-error (trawl--report file pos path (cdr err))
+ nil)))
(defun trawl--check-re (form name file pos path)
- (let ((re (trawl--get-string form)))
+ (let ((re (trawl--get-string form file pos path)))
(when re
(trawl--check-re-string re name file pos path))))
;; Check a list of regexps.
(defun trawl--check-list (form name file pos path)
;; Don't use mapc -- mustn't crash on improper lists.
- (let ((l (trawl--get-list form)))
+ (let ((l (trawl--get-list form file pos path)))
(while (consp l)
(when (stringp (car l))
(trawl--check-re-string (car l) name file pos path))
@@ -437,7 +451,7 @@
((and (consp elem)
(stringp (car elem)))
(trawl--check-re-string (car elem) name file pos path))))
- (trawl--get-list form)))
+ (trawl--get-list form file pos path)))
(defun trawl--check-font-lock-keywords (form name file pos path)
(trawl--check-list-any form name file pos path))
@@ -447,11 +461,11 @@
(form name file pos path)
(mapc (lambda (elem)
(if (cadr elem)
- (trawl--check-re-string
+ (trawl--check-re-string
(cadr elem)
(format "%s (%s)" name (car elem))
file pos path)))
- (trawl--get-list form)))
+ (trawl--get-list form file pos path)))
;; Check a variable on `align-mode-rules-list' format
(defun trawl--check-rules-list (form name file pos path)
@@ -460,11 +474,11 @@
(symbolp (car rule)))
(let* ((rule-name (car rule))
(re-form (cdr (assq 'regexp (cdr rule))))
- (re (trawl--get-string re-form)))
+ (re (trawl--get-string re-form file pos path)))
(when (stringp re)
(trawl--check-re-string
re (format "%s (%s)" name rule-name) file pos path)))))
- (trawl--get-list form)))
+ (trawl--get-list form file pos path)))
(defun trawl--check-form-recursively (form file pos path)
(pcase form
- [elpa] externals/relint af745bb 30/44: Update the package description. Increment version to 1.4, (continued)
- [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, 2019/03/26
- [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 <=
- [elpa] externals/relint 8e37762 18/44: Protect against improper lists in function calls, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 66522ca 12/44: Increment version to 1.1, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 683f31b 28/44: Increment version to 1.3, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint ac5d0cf 25/44: Add more safe functions, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 02bf0ba 21/44: Use explicit list of pure functions, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 7d0e177 20/44: Rewrite the higher-order function handling, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint be3979a 19/44: Check TRIM argument of `split-string' as well, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 5143edf 17/44: Fix indentation accidents, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint d6320f9 14/44: Detect functions with regexp arguments, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint d19133e 09/44: Better variable name patterns, Mattias Engdegård, 2019/03/26