[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode 1f39b11 288/496: Fix indent for ternary operato
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode 1f39b11 288/496: Fix indent for ternary operator |
Date: |
Sun, 29 Aug 2021 11:33:53 -0400 (EDT) |
branch: elpa/swift-mode
commit 1f39b11c0fc35526ffc946bfe75aa22f60df7493
Author: uk-ar <yuuki.ari@gmail.com>
Commit: uk-ar <yuuki.ari@gmail.com>
Fix indent for ternary operator
---
swift-mode.el | 18 +++++++-----------
test/indentation-tests.el | 13 +++++++++++++
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/swift-mode.el b/swift-mode.el
index 3440019..c071c73 100644
--- a/swift-mode.el
+++ b/swift-mode.el
@@ -88,13 +88,11 @@
(decl (decl ";" decl))
(decl (let-decl) (var-decl))
(let-decl
- ("let" id ":" type)
- ("let" id "=" exp)
- ("let" id ":" type "=" exp))
+ ("let" decl-exp)
+ ("let" decl-exp "=" exp))
(var-decl
- ("var" id ":" type)
- ("var" id "=" exp)
- ("var" id ":" type "=" exp))
+ ("var" decl-exp)
+ ("var" decl-exp "=" exp))
(top-level-sts (top-level-st) (top-level-st ";" top-level-st))
(top-level-st
@@ -125,7 +123,6 @@
(insts (inst) (insts ";" insts))
(inst (decl)
(exp "=" exp)
- (tern-exp)
(in-exp)
(dot-exp)
(dot-exp "{" closure "}")
@@ -147,7 +144,6 @@
(exp ("[" decl-exps "]"))
(in-exp (id "in" exp))
(guard-exp (exp "where" exp))
- (tern-exp (exp "?" exp ":" exp))
(enum-case ("ecase" assign-exp)
("ecase" "(" type ")"))
@@ -173,7 +169,7 @@
(closure (insts) (exp "in" insts) (exp "->" id "in" insts)))
;; Conflicts
- '((nonassoc "{") (assoc "in") (assoc ",") (assoc ";") (assoc ":") (right
"="))
+ '((nonassoc "{") (assoc "in") (assoc ",") (assoc ";") (right "=") (right
":"))
'((assoc "in") (assoc "where"))
'((assoc ";") (assoc "ecase"))
'((assoc "case")))
@@ -182,6 +178,7 @@
'(
(right "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" "&="
"^=" "|=" "&&=" "||=" "=") ;; Assignment
(Right associative, precedence level 90)
+ (right "?" ":") ;; Ternary
Conditional (Right associative, precedence level 100)
(left "||") ;; Disjunctive
(Left associative, precedence level 110)
(left "&&") ;; Conjunctive
(Left associative, precedence level 120)
(right "??") ;; Nil
Coalescing (Right associativity, precedence level 120)
@@ -386,8 +383,7 @@ We try to constraint those lookups by reasonable number of
lines.")
(cond
;; Rule for ternary operator in
;; assignment expression.
- ;; Static indentation relatively to =
- ((smie-rule-parent-p "=") 2)
+ ((and (smie-rule-parent-p "?") (smie-rule-bolp)) 0)
((smie-rule-parent-p ",") (smie-rule-parent swift-indent-offset))
;; Rule for the class definition.
((smie-rule-parent-p "class") (smie-rule-parent swift-indent-offset))))
diff --git a/test/indentation-tests.el b/test/indentation-tests.el
index c77666b..ce406b5 100644
--- a/test/indentation-tests.el
+++ b/test/indentation-tests.el
@@ -1836,6 +1836,19 @@ func foo() {
}
")
+(check-indentation conditional-operator/11
+ "
+let a = a ? a +
+ 1
+ |: a +
+ 1
+" "
+let a = a ? a +
+ 1
+ |: a +
+ 1
+")
+
(check-indentation blank-line/1
"
func foo() {
- [nongnu] elpa/swift-mode 2d0194e 184/496: Correct several indentation cases for class defitinion, (continued)
- [nongnu] elpa/swift-mode 2d0194e 184/496: Correct several indentation cases for class defitinion, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode f8190d6 186/496: Extract function into separate grammar and add return typo to the, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode fb2f48e 187/496: Add rule for assignment expression, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 01bcc35 192/496: Improve grammar for functions and contraint protocols grammar to, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c09229a 198/496: Use semantic hanging-p function instead of custom regex when checking, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 462ea17e 221/496: Improve closures grammar and add several related indentation rules, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode f42752b 223/496: Respect comments when calculating position of the implicit semicolon, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode b4b56f6 246/496: Merge pull request #99 from uk-ar/fix-indents-around-comma, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d047843 258/496: Fix token for :, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode ba39552 261/496: Fix test failure on travis, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 1f39b11 288/496: Fix indent for ternary operator,
ELPA Syncer <=
- [nongnu] elpa/swift-mode 4d90ca5 280/496: Merge pull request #110 from lunaryorn/patch-1, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0cb5e13 303/496: Improve some wording, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode b6f3664 302/496: Update a few URLs, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 9c180cf 315/496: Fix testing error when running the test twice interactively, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 2955e8f 314/496: Simplify indentation for commas, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 8e69064 034/496: Mention package.el as an installation option, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cfb3a6f 045/496: Setup some basic code style conventions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7ea5f66 059/496: Fix markdown formatting typo, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cd0aa34 072/496: Adding flycheck plugin for syntax check with swift cli, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 14c6bdd 079/496: Add swift repl commands to mode map, ELPA Syncer, 2021/08/29