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

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

[nongnu] elpa/swift-mode 462ea17e 221/496: Improve closures grammar and


From: ELPA Syncer
Subject: [nongnu] elpa/swift-mode 462ea17e 221/496: Improve closures grammar and add several related indentation rules
Date: Sun, 29 Aug 2021 11:33:39 -0400 (EDT)

branch: elpa/swift-mode
commit 462ea17e0898ecd6334575d9a1501d121b095078
Author: ap4y <lod@pisem.net>
Commit: ap4y <lod@pisem.net>

    Improve closures grammar and add several related indentation rules
---
 swift-mode.el             | 26 +++++++++++++------
 test/indentation-tests.el | 64 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 8 deletions(-)

diff --git a/swift-mode.el b/swift-mode.el
index 65796e4..7fa4452 100644
--- a/swift-mode.el
+++ b/swift-mode.el
@@ -126,9 +126,9 @@
              (tern-exp)
              (in-exp)
              (dot-exp)
-             (dot-exp "{" insts "}")
+             (dot-exp "{" closure "}")
              (method-call)
-             (method-call "{" insts "}")
+             (method-call "{" closure "}")
              ("enum" decl-exp "{" enum-body "}")
              ("switch" exp "{" switch-body "}")
              (if-clause)
@@ -139,7 +139,7 @@
 
        (method-call (dot-exp "(" method-args ")"))
        (method-args (method-arg) (method-arg "," method-arg))
-       (method-arg (exp "," "{" insts "}") (exp))
+       (method-arg (exp "," "{" closure "}") (exp))
 
        (exp (op-exp)
             ("[" decl-exps "]"))
@@ -161,9 +161,11 @@
 
        (if-conditional (exp) (let-decl))
        (if-body ("if" if-conditional "{" insts "}"))
-       (if-clause (if-body) (if-body "else" if-body)))
+       (if-clause (if-body) (if-body "else" if-body))
+
+       (closure (insts) (id "in" insts) (id "->" id "in" insts)))
      ;; Conflicts
-     '((nonassoc "{") (assoc ",") (assoc ";") (assoc ":") (right "="))
+     '((nonassoc "{") (assoc "in") (assoc ",") (assoc ";") (assoc ":") (right 
"="))
      '((assoc "in") (assoc "where") (assoc "OP"))
      '((assoc ";") (assoc "ecase"))
      '((assoc "case")))
@@ -215,6 +217,8 @@
              (looking-back "[[:space:]][?!]" (- (point) 2) t)
              ;; ??, is? and as? are operators
              (looking-back "[?][?]\\|as[?]\\|is[?]" (- (point) 3) t)
+             ;; "in" operator in closure
+             (looking-back "in" (- (point) 2) t)
              ;; Characters placed on the second line in multi-line expression
              (looking-at "[ \n\t]+[.?:]")
              ;; Operators placed on the second line in multi-line expression
@@ -362,15 +366,21 @@
 
     ;; Disable unnecessary default indentation for
     ;; "func" and "class" keywords
-    (`(:after . ,(or `"func" `"class")) (smie-rule-parent 0))
+    (`(:after . ,(or `"func" `"class")) (smie-rule-parent))
 
-    (`(:after . "(") (smie-rule-parent swift-indent-offset))
+    ;; "in" token in closure
+    (`(:after . "in")
+     (if (smie-rule-parent-p "{")
+         (smie-rule-parent swift-indent-offset)))
 
+    (`(:after . "(")
+     (if (smie-rule-parent-p "(") 0
+       (smie-rule-parent swift-indent-offset)))
     (`(:before . "(")
      (cond
       ((smie-rule-next-p "[") (smie-rule-parent))
       ;; Custom indentation for method arguments
-      ((smie-rule-parent-p "." "func") (smie-rule-parent 0))))
+      ((smie-rule-parent-p "." "func") (smie-rule-parent))))
 
     (`(:before . "[")
      (cond
diff --git a/test/indentation-tests.el b/test/indentation-tests.el
index 2d24fa8..f3a2bc2 100644
--- a/test/indentation-tests.el
+++ b/test/indentation-tests.el
@@ -1805,6 +1805,70 @@ func foo() {
 }
 ")
 
+(check-indentation anonymous-function-as-a-argument/5
+                   "
+foo.bar(10,
+        completionHandler: { complete in
+        |foo
+        }
+)
+" "
+foo.bar(10,
+        completionHandler: { complete in
+            |foo
+        }
+)
+")
+
+(check-indentation anonymous-function-as-a-argument/6
+                   "
+foo.bar(10,
+        completionHandler: {
+            complete in
+        |foo
+        }
+)
+" "
+foo.bar(10,
+        completionHandler: {
+            complete in
+            |foo
+        }
+)
+")
+
+(check-indentation anonymous-function-as-a-argument/7
+                   "
+foo.bar(10,
+        completionHandler: { (
+        |bar, baz) in
+            foo
+        }
+)
+" "
+foo.bar(10,
+        completionHandler: { (
+            |bar, baz) in
+            foo
+        }
+)
+")
+
+(check-indentation anonymous-function-as-a-argument/8
+                   "
+foo.bar(10,
+        completionHandler: { (bar, baz) -> Void in
+        |foo
+        }
+)
+" "
+foo.bar(10,
+        completionHandler: { (bar, baz) -> Void in
+            |foo
+        }
+)
+")
+
 (check-indentation indents-expression-with-optional-type/1
                    "
 var object: JsonObject?



reply via email to

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