branch: elpa/swift-mode
commit 2cb54c90fa4b629dec56882a0f811db897372ec6
Author: ap4y <[email protected]>
Commit: ap4y <[email protected]>
Make grammar for if statement a bit more precise
It still a bit hard to express actual grammar for this statements
---
swift-mode.el | 18 +++++++++--------
test/indentation-tests.el | 50 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 8 deletions(-)
diff --git a/swift-mode.el b/swift-mode.el
index 7fa4452..786763c 100644
--- a/swift-mode.el
+++ b/swift-mode.el
@@ -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 "elseif" if-conditional "{" insts "}")
+ (if-body "else" "{" insts "}"))
- (closure (insts) (id "in" insts) (id "->" id "in" insts)))
+ (closure (insts) (exp "in" insts) (exp "->" id "in" insts)))
;; Conflicts
'((nonassoc "{") (assoc "in") (assoc ",") (assoc ";") (assoc ":") (right
"="))
'((assoc "in") (assoc "where") (assoc "OP"))
@@ -259,6 +261,9 @@
((looking-at "\\<default\\>")
(goto-char (match-end 0)) "case")
+ ((looking-at "else if")
+ (goto-char (match-end 0)) "elseif")
+
(t (let ((tok (smie-default-forward-token)))
(cond
((equal tok "case")
@@ -303,6 +308,9 @@
((looking-back "\\<default\\>" (- (point) 9) t)
(goto-char (match-beginning 0)) "case")
+ ((looking-back "else if" (- (point) 7) t)
+ (goto-char (match-beginning 0)) "elseif")
+
(t (let ((tok (smie-default-backward-token)))
(cond
((equal tok "case")
@@ -358,12 +366,6 @@
(if (smie-rule-parent-p "class")
(smie-rule-parent swift-indent-offset)))
- (`(:before . "if")
- (if (smie-rule-prev-p "else")
- (if (smie-rule-parent-p "{")
- (smie-rule-parent swift-indent-offset)
- (smie-rule-parent))))
-
;; Disable unnecessary default indentation for
;; "func" and "class" keywords
(`(:after . ,(or `"func" `"class")) (smie-rule-parent))
diff --git a/test/indentation-tests.el b/test/indentation-tests.el
index f3a2bc2..b5fa50e 100644
--- a/test/indentation-tests.el
+++ b/test/indentation-tests.el
@@ -1869,6 +1869,56 @@ foo.bar(10,
)
")
+(check-indentation anonymous-function-as-a-argument/9
+ "
+foo.bar(10,
+ completionHandler: { complete in
+
+ if foo {
+ bar
+ } else {
+ |bar
+ }
+ }
+)
+" "
+foo.bar(10,
+ completionHandler: { complete in
+
+ if foo {
+ bar
+ } else {
+ |bar
+ }
+ }
+)
+")
+
+(check-indentation anonymous-function-as-a-argument/10
+ "
+foo.bar(10,
+ completionHandler: { complete in
+
+ if foo {
+ bar
+ } else {
+ bar
+ |}
+ }
+)
+" "
+foo.bar(10,
+ completionHandler: { complete in
+
+ if foo {
+ bar
+ } else {
+ bar
+ |}
+ }
+)
+")
+
(check-indentation indents-expression-with-optional-type/1
"
var object: JsonObject?