[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode add2ae9 282/496: Merge pull request #111 from u
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode add2ae9 282/496: Merge pull request #111 from uk-ar/indent-according-to-prec |
Date: |
Sun, 29 Aug 2021 11:33:51 -0400 (EDT) |
branch: elpa/swift-mode
commit add2ae9875b45101a262eebbc5270ec07eba9084
Merge: 4d90ca5 6793bd9
Author: Arthur Evstifeev <mail@ap4y.me>
Commit: Arthur Evstifeev <mail@ap4y.me>
Merge pull request #111 from uk-ar/indent-according-to-prec
Indent according to operators precedence
---
swift-mode.el | 43 ++++++++++++++++++++-----------------------
test/indentation-tests.el | 14 +++++++++++++-
2 files changed, 33 insertions(+), 24 deletions(-)
diff --git a/swift-mode.el b/swift-mode.el
index 2833047..9b74ae8 100644
--- a/swift-mode.el
+++ b/swift-mode.el
@@ -144,12 +144,10 @@
(method-args (method-arg) (method-args "," method-args))
(method-arg (id "{" closure "}") (exp))
- (exp (op-exp)
- ("[" decl-exps "]"))
+ (exp ("[" decl-exps "]"))
(in-exp (id "in" exp))
(guard-exp (exp "where" exp))
- (op-exp (exp "OP" exp))
- (tern-exp (op-exp "?" exp ":" exp))
+ (tern-exp (exp "?" exp ":" exp))
(enum-case ("ecase" assign-exp)
("ecase" "(" type ")"))
@@ -176,7 +174,7 @@
(closure (insts) (exp "in" insts) (exp "->" id "in" insts)))
;; Conflicts
'((nonassoc "{") (assoc "in") (assoc ",") (assoc ";") (assoc ":") (right
"="))
- '((assoc "in") (assoc "where") (assoc "OP"))
+ '((assoc "in") (assoc "where"))
'((assoc ";") (assoc "ecase"))
'((assoc "case")))
@@ -186,6 +184,7 @@
"^=" "|=" "&&=" "||=" "=") ;; Assignment
(Right associative, precedence level 90)
(left "||") ;; Disjunctive
(Left associative, precedence level 110)
(left "&&") ;; Conjunctive
(Left associative, precedence level 120)
+ (right "??") ;; Nil
Coalescing (Right associativity, precedence level 120)
(nonassoc "<" "<=" ">" ">=" "==" "!=" "===" "!==" "~=") ;; Comparative
(No associativity, precedence level 130)
(nonassoc "is" "as" "as!" "as?") ;; Cast (No
associativity, precedence level 132)
(nonassoc "..<" "...") ;; Range (No
associativity, precedence level 135)
@@ -204,13 +203,16 @@
value)
value))
+(defvar swift-smie--operators
+ '("*=" "/=" "%=" "+=" "-=" "<<=" ">>=" "&=" "^=" "|=" "&&=" "||="
+ "<" "<=" ">" ">=" "==" "!=" "===" "!==" "~=" "||" "&&"
+ "is" "as" "as!" "as?" "..<" "..."
+ "+" "-" "&+" "&-" "|" "^"
+ "*" "/" "%" "&*" "&/" "&%" "&"
+ "<<" ">>" "??"))
+
(defvar swift-smie--operators-regexp
- (regexp-opt '("*=" "/=" "%=" "+=" "-=" "<<=" ">>=" "&=" "^=" "|=" "&&=" "||="
- "<" "<=" ">" ">=" "==" "!=" "===" "!==" "~=" "||" "&&"
- "is" "as" "as!" "as?" "..<" "..."
- "+" "-" "&+" "&-" "|" "^"
- "*" "/" "%" "&*" "&/" "&%" "&"
- "<<" ">>" "??")))
+ (regexp-opt swift-smie--operators))
(defvar swift-smie--decl-specifier-regexp
"\\(?1:mutating\\|override\\|static\\|unowned\\|weak\\)")
@@ -287,14 +289,11 @@ We try to constraint those lookups by reasonable number
of lines.")
((looking-at "->") (forward-char 2) "->")
((looking-at "<") (forward-char 1)
- (if (looking-at "[[:upper:]]") "<T" "OP"))
+ (if (looking-at "[[:upper:]]") "<T" "<"))
((looking-at ">[?!]?")
(goto-char (match-end 0))
- (if (looking-back "[[:space:]]>" 2 t) "OP" "T>"))
-
- ((looking-at swift-smie--operators-regexp)
- (goto-char (match-end 0)) "OP")
+ (if (looking-back "[[:space:]]>" 2 t) ">" "T>"))
((looking-at swift-smie--decl-specifier-regexp)
(goto-char (match-end 1)) "DECSPEC")
@@ -344,18 +343,15 @@ We try to constraint those lookups by reasonable number
of lines.")
(goto-char (match-beginning 0)) "->")
((eq (char-before) ?<) (backward-char 1)
- (if (looking-at "<[[:upper:]]") "<T" "OP"))
+ (if (looking-at "<[[:upper:]]") "<T" "<"))
((looking-back ">[?!]?" (- (point) 2) t)
(goto-char (match-beginning 0))
- (if (looking-back "[[:space:]]" 1 t) "OP" "T>"))
+ (if (looking-back "[[:space:]]" 1 t) ">" "T>"))
((looking-back (regexp-opt swift-mode--type-decl-keywords) (- (point) 9)
t)
(goto-char (match-beginning 0))
(match-string-no-properties 0))
- ((looking-back swift-smie--operators-regexp (- (point) 3) t)
- (goto-char (match-beginning 0)) "OP")
-
((looking-back swift-smie--decl-specifier-regexp (- (point) 8) t)
(goto-char (match-beginning 1)) "DECSPEC")
@@ -412,9 +408,10 @@ We try to constraint those lookups by reasonable number of
lines.")
;; Apply swift-indent-multiline-statement-offset if
;; operator is the last symbol on the line
- (`(:before . "OP")
+ (`(:before . ,(pred (lambda (token)
+ (member token swift-smie--operators))))
(when (and (smie-rule-hanging-p)
- (not (smie-rule-parent-p "OP")))
+ (not (apply 'smie-rule-parent-p swift-smie--operators)))
(if (smie-rule-parent-p "{")
(+ swift-indent-offset swift-indent-multiline-statement-offset)
swift-indent-multiline-statement-offset)))
diff --git a/test/indentation-tests.el b/test/indentation-tests.el
index bb11116..4e01ab0 100644
--- a/test/indentation-tests.el
+++ b/test/indentation-tests.el
@@ -1663,7 +1663,7 @@ let foo = bar >
|baz
")
-(check-indentation indents-multiline-operators-only-once
+(check-indentation indents-multiline-operators-only-once/1
"
1 +
2 + 5 *
@@ -1671,6 +1671,18 @@ let foo = bar >
" "
1 +
2 + 5 *
+ |3
+"
+)
+
+(check-indentation indents-multiline-operators-only-once/2
+ "
+1 +
+ 2 * 5 +
+|3
+" "
+1 +
+ 2 * 5 +
|3
"
)
- [nongnu] elpa/swift-mode 7709e04 256/496: Fix token for DECSPEC, (continued)
- [nongnu] elpa/swift-mode 7709e04 256/496: Fix token for DECSPEC, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7169a3b 265/496: Fix class when empty (no insts), ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 391752f 272/496: Add test case for forward-list & backward-list, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7ffd59d 273/496: Fix forward-list test by adding brackets, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 3ce22b1 275/496: Remove needless code, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c40887e 276/496: Merge pull request #108 from syohex/remove-needless-code, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode ade8e95 277/496: Use with-eval-after-load instead of eval-after-load, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode a3bcb19 278/496: Merge pull request #109 from syohex/with-eval-after-load, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 3aec61f 279/496: Update Emacs version requirement in README, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 6793bd9 281/496: Indent according to operators precedence, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode add2ae9 282/496: Merge pull request #111 from uk-ar/indent-according-to-prec,
ELPA Syncer <=
- [nongnu] elpa/swift-mode 8889a6a 285/496: Merge pull request #112 from uk-ar/fix-multiline-expressions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 064d4ee 287/496: Update acknowledgments section in readme, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode b7cc115 293/496: Merge pull request #116 from syohex/use-cl-lib, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode e9648b1 296/496: Use .el for file extension in distributed package., ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 1563e8b 300/496: Bump the development version to 0.5.0-snapshot, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode a5e1acf 297/496: Merge pull request #122 from N4tr0n/make-install-fix-issue120, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cfaeaff 294/496: Update MELPA URL, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 9471669 304/496: Merge taku0/swift3-mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 848d088 310/496: Fix indentation after attributes with arguments, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cad72a1 306/496: Fix a link in README.md, ELPA Syncer, 2021/08/29