branch: externals/xr commit 1b26866aad4ceae17da416bd9328641a516c0d6a Author: Mattias Engdegård <matti...@acm.org> Commit: Mattias Engdegård <matti...@acm.org>
Warn about repetition of repetition Make xr-lint complain about constructs such as a?* as they are usually mistakes. --- xr-test.el | 5 +++++ xr.el | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/xr-test.el b/xr-test.el index 7077283..c0a86a2 100644 --- a/xr-test.el +++ b/xr-test.el @@ -274,6 +274,11 @@ '((0 . "Escaped non-special character `}'") (4 . "Escaped non-special character `a'") (8 . "Escaped non-special character `%'")))) + (should (equal (xr-lint "a?+b+?\\(?:c?\\)*d\\{3\\}+e*\\{2,5\\}") + '((2 . "Repetition of repetition") + (14 . "Repetition of repetition") + (21 . "Repetition of repetition") + (24 . "Repetition of repetition")))) ) (provide 'xr-test) diff --git a/xr.el b/xr.el index 60d84b9..6114ee7 100644 --- a/xr.el +++ b/xr.el @@ -26,7 +26,7 @@ ;; ;; - Migrating existing code to rx form, for better readability and ;; maintainability -;; - Understanding complex regexp strings +;; - Understanding complex regexp strings and finding errors in them ;; ;; Please refer to `rx' for more information about the notation. ;; @@ -310,6 +310,12 @@ (if (and sequence (not (and (eq (car sequence) 'bol) (eq (preceding-char) ?^)))) (let ((operator (match-string 0))) + (when (and (consp (car sequence)) + (memq (caar sequence) + '(opt zero-or-more one-or-more + repeat = >=))) + (xr--report warnings (match-beginning 0) + "Repetition of repetition")) (goto-char (match-end 0)) (setq sequence (cons (xr--postfix operator (car sequence)) (cdr sequence)))) @@ -324,6 +330,12 @@ sequence (not (and (eq (car sequence) 'bol) (eq (preceding-char) ?^)))) (forward-char 2) + (when (and (consp (car sequence)) + (memq (caar sequence) + '(opt zero-or-more one-or-more + repeat = >=))) + (xr--report warnings (match-beginning 0) + "Repetition of repetition")) (if (looking-at (rx (opt (group (one-or-more digit))) (opt (group ",") (opt (group (one-or-more digit))))