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

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

[elpa] externals/xr be3e1a45df 1/3: Repetition operators are literals af


From: ELPA Syncer
Subject: [elpa] externals/xr be3e1a45df 1/3: Repetition operators are literals after string-start anchor
Date: Mon, 31 Jul 2023 12:59:21 -0400 (EDT)

branch: externals/xr
commit be3e1a45df0165f3a54102e5cb7347d078cd78b3
Author: Mattias EngdegÄrd <mattiase@acm.org>
Commit: Mattias EngdegÄrd <mattiase@acm.org>

    Repetition operators are literals after string-start anchor
    
    Thus \` has the same effect as ^ on repetition operators; this was
    always the case in Emacs but only recently documented
    (see https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64128).
    
    This change also means that (xr-lint "\\`*") now complains about an
    unescaped literal instead of a repeated zero-width assertion.
---
 xr-test.el | 19 ++++++++++++++++++-
 xr.el      | 12 ++++++------
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/xr-test.el b/xr-test.el
index e06dac49c9..10a3933047 100644
--- a/xr-test.el
+++ b/xr-test.el
@@ -267,6 +267,14 @@
                  '(seq "a" (zero-or-more "^"))))
   (should (equal (xr "a^\\{2,7\\}")
                  '(seq "a" (repeat 2 7 "^"))))
+  (should (equal (xr "a\\|\\`?b")
+                 '(or "a" (seq bos "?b"))))
+  (should (equal (xr "a\\|\\`\\{3,4\\}b")
+                 '(or "a" (seq bos "{3,4}b"))))
+  (should (equal (xr "\\(?:\\`\\)*")
+                 '(zero-or-more bos)))
+  (should (equal (xr "\\(?:\\`\\)\\{3,4\\}")
+                 '(repeat 3 4 bos)))
   )
 
 (ert-deftest xr-simplify ()
@@ -373,6 +381,11 @@
                      (3 . "Unescaped literal `$'"))))
     (should (equal (xr-lint "^**$")
                    '((1 . "Unescaped literal `*'"))))
+    (should (equal (xr-lint "a\\|\\`?b")
+                   '((5 . "Unescaped literal `?'"))))
+    (should (equal (xr-lint "a\\|\\`\\{3,4\\}b")
+                   '((5 . "Escaped non-special character `{'")
+                     (10 . "Escaped non-special character `}'"))))
     (should (equal (xr-lint "\\{\\(+\\|?\\)\\[\\]\\}\\\t")
                    '((0  . "Escaped non-special character `{'")
                      (4  . "Unescaped literal `+'")
@@ -411,9 +424,13 @@
                      (5 . "Optional zero-width assertion")
                      (13 . "Repetition of zero-width assertion"))))
     (should (equal
-             (xr-lint "\\`\\{2\\}\\(a\\|\\|b\\)\\{,8\\}")
+             (xr-lint "\\b\\{2\\}\\(a\\|\\|b\\)\\{,8\\}")
              '((2 . "Repetition of zero-width assertion")
                (17 . "Repetition of expression matching an empty string"))))
+    (should (equal (xr-lint "\\(?:\\`\\)*")
+                   '((8 . "Repetition of zero-width assertion"))))
+    (should (equal (xr-lint "\\(?:\\`\\)\\{3,4\\}")
+                   '((8 . "Repetition of zero-width assertion"))))
     ))
 
 (ert-deftest xr-lint-char-alt ()
diff --git a/xr.el b/xr.el
index 7c2232e4bc..fb4895b592 100644
--- a/xr.el
+++ b/xr.el
@@ -574,10 +574,10 @@ like (* (* X) ... (* X))."
 
          ;; * ? + (and non-greedy variants)
          ((memq next-char '(?* ?? ?+))
-          ;; - not special at beginning of sequence or after ^
+          ;; - not special at beginning of sequence or after ^ or \`
           (if (and sequence
-                   (not (and (eq (car sequence) 'bol)
-                             (eq (preceding-char) ?^))))
+                   (not (and (memq (car sequence) '(bol bos))
+                             (memq (preceding-char) '(?^ ?`)))))
               (let ((operator-char next-char)
                     (lazy (eq (char-after (1+ item-start)) ??))
                     (operand (car sequence)))
@@ -679,11 +679,11 @@ like (* (* X) ... (* X))."
                                 (t group))))
                 (push item sequence))))
 
-           ;; \{..\} - not special at beginning of sequence or after ^
+           ;; \{..\} - not special at beginning of sequence or after ^ or \`
            ((eq next-char ?\{)
             (if (and sequence
-                     (not (and (eq (car sequence) 'bol)
-                               (eq (char-after (1- item-start)) ?^))))
+                     (not (and (memq (car sequence) '(bol bos))
+                               (memq (char-after (1- item-start)) '(?^ ?`)))))
                 (progn
                   (forward-char)
                   (let ((operand (car sequence)))



reply via email to

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