[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/xr 549cbc5 3/3: Detect duplicated branches in alternati
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/xr 549cbc5 3/3: Detect duplicated branches in alternatives |
Date: |
Fri, 15 Mar 2019 13:17:27 -0400 (EDT) |
branch: externals/xr
commit 549cbc55fa3160e4246fefdead4130c85a91b608
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
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"))