branch: externals/xr commit 5318a946ec06aae190203d59ec7adc5f8c12ace3 Author: Mattias Engdegård <matti...@acm.org> Commit: Mattias Engdegård <matti...@acm.org>
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 ]