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

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

[nongnu] elpa/swift-mode a2c0b6a 251/496: Merge pull request #98 from ak


From: ELPA Syncer
Subject: [nongnu] elpa/swift-mode a2c0b6a 251/496: Merge pull request #98 from akoaysigod/master
Date: Sun, 29 Aug 2021 11:33:45 -0400 (EDT)

branch: elpa/swift-mode
commit a2c0b6aef5cac77eb67bc50e9d507aef3c184f20
Merge: 071cd18 5e7d1b9
Author: Arthur Evstifeev <mail@ap4y.me>
Commit: Arthur Evstifeev <mail@ap4y.me>

    Merge pull request #98 from akoaysigod/master
    
    added guard statement
---
 swift-mode.el             | 14 +++++++++++++-
 test/indentation-tests.el | 11 +++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/swift-mode.el b/swift-mode.el
index d00b212..b45391c 100644
--- a/swift-mode.el
+++ b/swift-mode.el
@@ -139,6 +139,7 @@
              ("enum" decl-exp "{" enum-body "}")
              ("switch" exp "{" switch-body "}")
              (if-clause)
+             (guard-statement)
              ("for" for-head "{" insts "}")
              ("while" exp "{" insts "}"))
 
@@ -168,6 +169,9 @@
 
        (for-head (in-exp) (op-exp) (for-head ";" for-head))
 
+       (guard-conditional (exp) (let-decl) (var-decl))
+       (guard-statement ("guard" guard-conditional "elseguard" "{" insts "}"))
+
        (if-conditional (exp) (let-decl))
        (if-body ("if" if-conditional "{" insts "}"))
        (if-clause (if-body)
@@ -292,6 +296,10 @@
           (if (looking-at "\\([\n\t ]\\|.\\)+?\\(where.*[,]\\|:\\)")
               "case"
             "ecase"))
+         ((equal tok "else")
+          (if (looking-back "\\(guard.*\\)")
+              "elseguard"
+            "else"))
          (t tok))))
    ))
 
@@ -345,6 +353,10 @@
             (if (looking-at "\\([\n\t ]\\|.\\)+?\\(where.*[,]\\|:\\)")
                 "case"
               "ecase"))
+           ((equal tok "else")
+            (if (looking-back "\\(guard.*\\)")
+                "elseguard"
+              "else"))
            (t tok))))
      )))
 
@@ -446,7 +458,7 @@
 
 (defvar swift-mode--statement-keywords
   '("break" "case" "continue" "default" "do" "else" "fallthrough"
-    "if" "in" "for" "return" "switch" "where" "while"))
+    "if" "in" "for" "return" "switch" "where" "while" "guard"))
 
 (defvar swift-mode--contextual-keywords
   '("associativity" "didSet" "get" "infix" "inout" "left" "mutating" "none"
diff --git a/test/indentation-tests.el b/test/indentation-tests.el
index 3153cf1..5535a70 100644
--- a/test/indentation-tests.el
+++ b/test/indentation-tests.el
@@ -2067,6 +2067,17 @@ func foo() {
 }
 ")
 
+(check-indentation indents-guard-statement/1
+                   "
+guard let x = y else {
+        |return
+}
+" "
+guard let x = y else {
+    |return
+}
+")
+
 (provide 'indentation-tests)
 
 ;;; indentation-tests.el ends here



reply via email to

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