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

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

[nongnu] elpa/swift-mode 778e9e6f35: Exclude regex ending with spaces or


From: ELPA Syncer
Subject: [nongnu] elpa/swift-mode 778e9e6f35: Exclude regex ending with spaces or tabs
Date: Tue, 17 Jan 2023 07:00:01 -0500 (EST)

branch: elpa/swift-mode
commit 778e9e6f35b41fd171bd9f42fd7b89c1001e2a82
Author: taku0 <mxxouy6x3m_github@tatapa.org>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>

    Exclude regex ending with spaces or tabs
    
    
https://github.com/apple/swift-evolution/commit/d9cae77aef0142944daf953b4bd227edc7fb239c#diff-1f63d0b96db9d2236f665756eae4dcbe5ad40270963a936cb14522ffbc4136ecR222
---
 swift-mode-lexer.el                   |  5 +++
 test/swift-files/indent/strings.swift | 64 ++++++++++++++++++++++-------------
 2 files changed, 45 insertions(+), 24 deletions(-)

diff --git a/swift-mode-lexer.el b/swift-mode-lexer.el
index f22916f5a8..60719c0ccf 100644
--- a/swift-mode-lexer.el
+++ b/swift-mode-lexer.el
@@ -508,6 +508,11 @@ return non-nil."
           (if (memq (char-after) '(?/ ?*))
               (goto-char limit)
             (setq end-of-regex (point)))))))
+    (when (and end-of-regex
+               (memq (char-before (1- end-of-regex)) '(?\s ?\t))
+               (not (swift-mode:escaped-p (- end-of-regex 2) 0)))
+      ;; Cannot ends with spaces or tabs unless escaped.
+      (setq end-of-regex nil))
     (unless end-of-regex
       (goto-char pos))
     end-of-regex))
diff --git a/test/swift-files/indent/strings.swift 
b/test/swift-files/indent/strings.swift
index 044bd52208..9b998579dd 100644
--- a/test/swift-files/indent/strings.swift
+++ b/test/swift-files/indent/strings.swift
@@ -169,7 +169,7 @@ func f() {
     let x = /a/
 
     // Slashes can be escaped.
-    let x = /\/ /
+    let x = /\/ +/
 
     // Slashes must be escaped in character classes.
     let x = /[/ + "]/ + // "
@@ -217,18 +217,18 @@ func f() {
 
     // Regexes without extended delimiters cannot be preceded by infix
     // operators without whitespaces.
-    // `a`, infix operator `+/`, `b`, and infix operator `/`
-    let x = a+/b /
+    // `a`, infix operator `+/`, `b`, and infix operator `%/`
+    let x = a+/b %/
       c()
 
     // Regexes without extended delimiters can be preceded by infix operators
     // with whitespaces.
-    // `a`, infix operator `+`, and regex /b /
-    let x = a + /b /
+    // `a`, infix operator `+`, and regex /b %/
+    let x = a + /b %/
     c()
 
     // Comments are whitespaces.
-    let x = a/**/+/**//b /
+    let x = a/**/+/**//b %/
     c()
 
     // Regexes with extended delimiters can be preceded by infix operators
@@ -240,26 +240,42 @@ func f() {
     // Regexes without extended delimiters cannot start with spaces.
     let regex = Regex {
         digit
-          / [+-] /
+        // infix operator `/`, and `a` with postfix operator `/'
+          / a/
+        digit
+    }
+    // Regexes without extended delimiters cannot end with spaces.
+    let regex = Regex {
+        digit
+        // prefix operator `/`, `a`, and infix operator `/'
+        /a /
           digit
     }
     let regex = Regex {
         digit
-        /[+-]/
+        // regex /a/
+        /a/
         digit
     }
 
     // Initial space must be escaped.
     let regex = Regex {
         digit
-        /\ [+-] /
+        /\ a/
+        digit
+    }
+
+    // Final space must be escaped.
+    let regex = Regex {
+        digit
+        /a\ /
         digit
     }
 
     // Regexes with extended delimiters can start with spaces.
     let regex = Regex {
         digit
-        #/ [+-] /#
+        #/ a /#
         digit
     }
 
@@ -291,39 +307,39 @@ func f() {
       c()
 
     // Regexes can be preceded with prefix operators wihtout spaces.
-    // prefix operator `+` and regex /a /.
-    let x = +/a /
+    // prefix operator `+` and regex /a %/.
+    let x = +/a %/
     b()
 
     // Regexes without extended delimiters cannot contain unmatching close
     // parentheses.
-    array.reduce(1, /) { otherArray.reduce(1, /)
-                         array.reduce(1, /) }; otherArray.reduce(1, /)
+    array.reduce(1,/) { otherArray.reduce(1,/)
+                        array.reduce(1,/) }; otherArray.reduce(1,/)
 
     // Regexes without extended delimiters can contain matching close
     // parentheses.
-    array.reduce(1, /(a) { otherArray.reduce(1, /)
-    array.reduce(1, /(a) }; otherArray.reduce(1, /)
+    array.reduce(1,/(a) { otherArray.reduce(1,/)
+    array.reduce(1,/(a) }; otherArray.reduce(1,/)
 
     // Regexes without extended delimiters can contain escaped close
     // parentheses.
-    array.reduce(1, /\) { otherArray.reduce(1, /)
-    array.reduce(1, /\) }; otherArray.reduce(1, /)
+    array.reduce(1,/\) { otherArray.reduce(1,/)
+    array.reduce(1,/\) }; otherArray.reduce(1,/)
 
     // Character classes can contain closing parentheses.
-    array.reduce(1, /[)] { otherArray.reduce(1, /)
-    array.reduce(1, /[)] }; otherArray.reduce(1, /)
+    array.reduce(1,/[)] { otherArray.reduce(1,/)
+    array.reduce(1,/[)] }; otherArray.reduce(1,/)
 
     // Regexes with extended delimiters can contain unmatching close
     // parentheses.
-    array.reduce(1, #/) { otherArray.reduce(1, /#)
-    array.reduce(1, #/) }; otherArray.reduce(1, /#)
+    array.reduce(1,#/) { otherArray.reduce(1,/#)
+    array.reduce(1,#/) }; otherArray.reduce(1,/#)
 
 
     // Regexes can contain unmatching close square brackets.
-    let d = a[/] /
+    let d = a[/] %/
     ]
-    let d = a[(/)] /
+    let d = a[(/)] %/
       b()
 
     // Comments have higher precedence.



reply via email to

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