emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/xr 5318a94 1/3: Eliminate duplicated \ in character alt


From: Mattias Engdegård
Subject: [elpa] externals/xr 5318a94 1/3: Eliminate duplicated \ in character alternatives
Date: Thu, 21 Feb 2019 08:59:20 -0500 (EST)

branch: externals/xr
commit 5318a946ec06aae190203d59ec7adc5f8c12ace3
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>

    Eliminate duplicated \ in character alternatives
    
    Since we detect duplicated \ in character alternatives, we might just
    as well remove them in the translation. The warning remains.
---
 xr-test.el |  2 ++
 xr.el      | 21 ++++++++++++---------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/xr-test.el b/xr-test.el
index 718471d..33c1e3e 100644
--- a/xr-test.el
+++ b/xr-test.el
@@ -170,6 +170,8 @@
                  '(zero-or-more (not (any "]" "A-Za-z" "-")))))
   (should (equal (xr "[+*%A-Ka-k0-3${-}]")
                  '(any "+*%" "A-Ka-k0-3" "$" "{-}")))
+  (should (equal (xr "[^\\\\o][A-\\\\][A-\\\\-a]")
+                 '(seq (not (any "\\o")) (any "A-\\") (any "A-\\\\-a"))))
   )
 
 (ert-deftest xr-empty ()
diff --git a/xr.el b/xr.el
index f8b83c2..5a5fff4 100644
--- a/xr.el
+++ b/xr.el
@@ -121,17 +121,20 @@
        (t
         (let* ((ch (following-char))
                (ch-str (char-to-string ch)))
-          (when (and (eq ch ?\\)
-                     (stringp (car set))
-                     (string-match "\\\\\\'" (car set)))
+          (cond
+           ;; Duplicated \ are common enough for us to remove them (and warn).
+           ((and (eq ch ?\\)
+                 (stringp (car set))
+                 (eq (string-to-char (substring (car set) -1)) ?\\))
             (xr--report warnings (1- (point))
                         "Escaped `\\' inside character alternative"))
-          ;; Merge with the previous string if neither contains "-".
-          (if (and (stringp (car set))
-                   (not (eq ch ?-))
-                   (not (string-match "-" (car set))))
-              (setq set (cons (concat (car set) ch-str) (cdr set)))
-            (push ch-str set)))
+           ;; Merge with the previous string if neither contains "-".
+           ((and (stringp (car set))
+                 (not (eq ch ?-))
+                 (not (string-match "-" (car set))))
+            (setq set (cons (concat (car set) ch-str) (cdr set))))
+           (t
+            (push ch-str set))))
         (forward-char 1))))
 
     (forward-char 1)                    ; eat the ]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]