branch: externals/xr commit 549cbc55fa3160e4246fefdead4130c85a91b608 Author: Mattias Engdegård <matti...@acm.org> Commit: Mattias Engdegård <matti...@acm.org>
Detect duplicated branches in alternatives Eg. "A\\|A". Sometimes indication of deeper mistake, always wasteful. --- xr-test.el | 2 ++ xr.el | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/xr-test.el b/xr-test.el index c90258a..c1c9b31 100644 --- a/xr-test.el +++ b/xr-test.el @@ -349,6 +349,8 @@ (29 . "Character `3' included in range `3-7'")))) (should (equal (xr-lint "[a[:digit:]b[:punct:]c[:digit:]]") '((22 . "Duplicated character class `[:digit:]'")))) + (should (equal (xr-lint "a*\\|b+\\|\\(?:a\\)*") + '((8 . "Duplicated alternative branch")))) ) (provide 'xr-test) diff --git a/xr.el b/xr.el index 5f644bb..d287165 100644 --- a/xr.el +++ b/xr.el @@ -545,7 +545,11 @@ (push (xr--parse-seq warnings) alternatives) (while (not (looking-at (rx (or "\\)" eos)))) (forward-char 2) ; skip \| - (push (xr--parse-seq warnings) alternatives)) + (let ((pos (point)) + (seq (xr--parse-seq warnings))) + (when (and warnings (member seq alternatives)) + (xr--report warnings pos "Duplicated alternative branch")) + (push seq alternatives))) (if (cdr alternatives) ;; Simplify (or nonl "\n") to anything (if (or (equal alternatives '(nonl "\n"))