[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode 2cb54c9 222/496: Make grammar for if statement
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode 2cb54c9 222/496: Make grammar for if statement a bit more precise |
Date: |
Sun, 29 Aug 2021 11:33:40 -0400 (EDT) |
branch: elpa/swift-mode
commit 2cb54c90fa4b629dec56882a0f811db897372ec6
Author: ap4y <lod@pisem.net>
Commit: ap4y <lod@pisem.net>
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?
- [nongnu] elpa/swift-mode ae32a8b 071/496: Add basic imenu support, (continued)
- [nongnu] elpa/swift-mode ae32a8b 071/496: Add basic imenu support, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d02e2dc 024/496: Update contributors, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode fc64626 156/496: Merge pull request #56 from ap4y/fix_flycheck_issues, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 9cf667c 159/496: Start work on 0.4, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cba4538 161/496: Merge pull request #61 from ckruse/fix_55, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 5611c0f 164/496: Updated syntax: a lot of attributes moved to keywords, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 250e8e4 172/496: Merge pull request #67 from jmibanez/fix-flycheck-and-byte-compilation-bug, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode a6267eb 189/496: Improve indentation for the function definitions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 782378c 214/496: Correct regex in lexer for the "default" keyword, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c38b721 216/496: Support default values for arguments in function declaration, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 2cb54c9 222/496: Make grammar for if statement a bit more precise,
ELPA Syncer <=
- [nongnu] elpa/swift-mode b6bad10 225/496: Set minimum required version to 24.4, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 4a27477 230/496: Merge pull request #89 from uk-ar/fix-indent-in-trailing-closure, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 4289bd7 235/496: Fix implicit semicolon rule, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode a29398b 239/496: Fix half-open range operator, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7f25806 241/496: Add as! operator, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 86339ed 247/496: Fix curly bracket's syntax table to enable electric-pair, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 37cab39 263/496: Improve indentation for switch and class statements, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cb7ba6f 245/496: Add an option for indent after hanging comma, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0185315 274/496: Merge pull request #107 from uk-ar/fix-forward-list, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 27ec163 286/496: Merge pull request #113 from uk-ar/add-keyword-for-attribute, ELPA Syncer, 2021/08/29