[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/xr 7160235 02/10: Refactor repetition subsumption check
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/xr 7160235 02/10: Refactor repetition subsumption check to avoid code duplication |
Date: |
Sun, 3 May 2020 11:13:07 -0400 (EDT) |
branch: externals/xr
commit 7160235fe06fdbd8814d9384f4239c9a6e8ad809
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Refactor repetition subsumption check to avoid code duplication
---
xr-test.el | 2 +-
xr.el | 52 +++++++++-------------------------------------------
2 files changed, 10 insertions(+), 44 deletions(-)
diff --git a/xr-test.el b/xr-test.el
index 2001a39..a46cf60 100644
--- a/xr-test.el
+++ b/xr-test.el
@@ -602,7 +602,7 @@
'((13 . "First item in repetition subsumes last item
(wrapped)"))))
(should (equal
(xr-lint "\\(?3:a*xa*\\)\\{7\\}")
- '((14 . "First item in repetition subsumes last item
(wrapped)"))))
+ '((14 . "Last item in repetition subsumes first item
(wrapped)"))))
))
(ert-deftest xr-skip-set ()
diff --git a/xr.el b/xr.el
index 985f4d8..3e09ac0 100644
--- a/xr.el
+++ b/xr.el
@@ -490,11 +490,11 @@ like (* (* X) ... (* X))."
(when (cddr operands)
(let* ((first (car operands))
(last (car (last operands)))
- (subsumption (xr--adjacent-subsumption first last)))
+ (subsumption (xr--adjacent-subsumption last first)))
(when subsumption
(xr--report
warnings pos
- (if (eq subsumption 'a-subsumes-b)
+ (if (eq subsumption 'b-subsumes-a)
"First item in repetition subsumes last item (wrapped)"
"Last item in repetition subsumes first item (wrapped)"))))))))
@@ -743,48 +743,14 @@ like (* (* X) ... (* X))."
(t (error "Backslash at end of regexp")))
(when (and warnings (cdr sequence))
- ;; Check for subsuming repetitions in sequence: (Rx X) (Ry Y)
- ;; where Rx and Ry are repetition operators, and X and Y are
operands.
- ;; We conclude that (Rx X) subsumes (Ry Y), in the sense that the
- ;; sequence is equivalent to just (Rx X), if:
- ;; X matches a superset of Y
- ;; and Rx can match infinitely many times
- ;; and Ry can match zero times
- ;; and Ry is non-greedy if Rx is non-greedy.
- ;; Example: [ab]+a?
(let* ((item (car sequence))
- (expr (and (consp item)
- (memq (car item)
- '(zero-or-more one-or-more opt *? +? ??))
- (xr--make-seq (cdr item)))))
- (when expr
- (let* ((prev-item (cadr sequence))
- (prev-expr
- (and (consp prev-item)
- (memq (car prev-item)
- '(zero-or-more one-or-more opt *? +? ??))
- (xr--make-seq (cdr prev-item)))))
- (when prev-expr
- (let ((op (car item))
- (prev-op (car prev-item)))
- ;; Test the same condition twice, but mirrored.
- (cond
- ((and (memq op '(zero-or-more opt *? ??))
- (memq prev-op '(zero-or-more one-or-more *? +?))
- (not (and (memq prev-op '(*? +?))
- (memq op '(zero-or-more opt))))
- (xr--superset-p prev-expr expr))
- (xr--report
- warnings item-start
- "Repetition subsumed by preceding repetition"))
- ((and (memq prev-op '(zero-or-more opt *? ??))
- (memq op '(zero-or-more one-or-more *? +?))
- (not (and (memq op '(*? +?))
- (memq prev-op '(zero-or-more opt))))
- (xr--superset-p expr prev-expr))
- (xr--report
- warnings item-start
- "Repetition subsumes preceding repetition")))))))))))
+ (prev-item (cadr sequence))
+ (subsumption (xr--adjacent-subsumption prev-item item)))
+ (when subsumption
+ (xr--report warnings item-start
+ (if (eq subsumption 'a-subsumes-b)
+ "Repetition subsumed by preceding repetition"
+ "Repetition subsumes preceding repetition")))))))
(let ((item-seq (xr--rev-join-seq sequence)))
(cond ((null item-seq)
- [elpa] externals/xr updated (434b300 -> 35dbbeb), Mattias Engdegård, 2020/05/03
- [elpa] externals/xr e5b51bf 01/10: Add wrapped subsumption in repeated forms, Mattias Engdegård, 2020/05/03
- [elpa] externals/xr f3b61ef 05/10: Fix false negative in empty string repetition check, Mattias Engdegård, 2020/05/03
- [elpa] externals/xr c98bb7b 03/10: Handle whitespace and word syntax subsumption in one place, Mattias Engdegård, 2020/05/03
- [elpa] externals/xr c7e7557 07/10: Broaden anchor check to check more paths, Mattias Engdegård, 2020/05/03
- [elpa] externals/xr d752aab 09/10: Use "option" instead of "repetition" in diagnostics for ? and ??, Mattias Engdegård, 2020/05/03
- [elpa] externals/xr c6e12b7 04/10: Handle \w and \W in subsumption checks, Mattias Engdegård, 2020/05/03
- [elpa] externals/xr 21eab3c 06/10: Check for bol, eol and eos in conflict with other expressions, Mattias Engdegård, 2020/05/03
- [elpa] externals/xr 7160235 02/10: Refactor repetition subsumption check to avoid code duplication,
Mattias Engdegård <=
- [elpa] externals/xr d0b09e1 08/10: Add filename-specific checks, Mattias Engdegård, 2020/05/03
- [elpa] externals/xr 35dbbeb 10/10: Increment version to 1.19, Mattias Engdegård, 2020/05/03