Skip to content

Commit 6194d95

Browse files
committed
1 parent 221863c commit 6194d95

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

swift-mode-font-lock.el

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ Return nil otherwise."
524524
'("associatedtype" "class" "deinit" "enum" "extension" "fileprivate" "func"
525525
"import" "init" "inout" "internal" "let" "open" "operator" "private"
526526
"protocol" "public" "any" "some" "static" "struct" "subscript" "typealias"
527-
"var" "actor" "nonisolated" "isolated" "distributed")
527+
"var" "actor" "nonisolated" "isolated" "distributed"
528+
"borrowing" "consuming")
528529
"Keywords used in declarations.")
529530

530531
(defconst swift-mode:statement-keywords
@@ -534,7 +535,7 @@ Return nil otherwise."
534535

535536
(defconst swift-mode:expression-keywords
536537
'("as" "catch" "dynamicType" "is" "rethrows" "super" "self" "Self" "throws"
537-
"throw" "try" "async" "await" "consume")
538+
"throw" "try" "async" "await" "consume" "copy")
538539
"Keywords used in expressions and types.
539540
540541
Excludes true, false, and keywords begin with a number sign.")

swift-mode-indent.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ It is a Generic parameter list if:
16491649
"as" "as?" "as!"
16501650
"is"
16511651
"await"
1652-
"consume"
1652+
"consume" "copy"
16531653
"in"
16541654
"init" "deinit" "get" "set" "willSet" "didSet" "subscript"
16551655
"for" "case" "default" "while" "let" "var" "repeat" "if" "else"

swift-mode-lexer.el

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ END is the point after the token."
9999

100100
;; Token types is one of the following symbols:
101101
;;
102-
;; - prefix-operator (including try, try?, try!, await, and consume)
102+
;; - prefix-operator (including try, try?, try!, await, consume, and copy)
103103
;; - postfix-operator
104104
;; - binary-operator (including as, as?, as!, is, =, ., and ->)
105105
;; - attribute (e.g. @objc, @abc(def))
@@ -609,10 +609,11 @@ return non-nil."
609609
;; Suppress implicit semicolon around keywords that cannot start or end
610610
;; statements.
611611
(member (swift-mode:token:text previous-token)
612-
'("any" "some" "inout" "in" "where" "isolated"))
612+
'("any" "some" "inout" "borrowing" "consuming" "in" "where"
613+
"isolated"))
613614
(member (swift-mode:token:text next-token)
614-
'("any" "some" "inout" "throws" "rethrows" "in" "where"
615-
"isolated")))
615+
'("any" "some" "inout" "borrowing" "consuming" "throws"
616+
"rethrows" "in" "where" "isolated")))
616617
nil)
617618

618619
;; Before async
@@ -987,7 +988,7 @@ Other properties are the same as the TOKEN."
987988
(type
988989
(cond
989990
(is-declaration 'identifier)
990-
((member text '("try" "try?" "try!" "await" "consume"))
991+
((member text '("try" "try?" "try!" "await" "consume" "copy"))
991992
'prefix-operator)
992993
((equal text ".") 'binary-operator)
993994
((and has-preceding-space has-following-space) 'binary-operator)
@@ -1146,7 +1147,7 @@ This function does not return `implicit-;' or `type-:'."
11461147
pos-after-comment
11471148
(point))))
11481149

1149-
;; Operator (other than as, try, is, await, or consume)
1150+
;; Operator (other than as, try, is, await, consume, or copy)
11501151
;;
11511152
;; Operators starts with a dot can contains dots. Other operators cannot
11521153
;; contain dots.
@@ -1245,7 +1246,7 @@ This function does not return `implicit-;' or `type-:'."
12451246
text
12461247
(- (point) (length text))
12471248
(point)))
1248-
((member text '("await" "consume"))
1249+
((member text '("await" "consume" "copy"))
12491250
(swift-mode:token 'prefix-operator
12501251
text
12511252
(- (point) (length text))
@@ -1418,7 +1419,7 @@ This function does not return `implicit-;' or `type-:'."
14181419
(point)
14191420
pos-before-comment)))
14201421

1421-
;; Operator (other than as, try, is, await, or consume)
1422+
;; Operator (other than as, try, is, await, consume, or copy)
14221423
;;
14231424
;; Operators which starts with a dot can contain other dots. Other
14241425
;; operators cannot contain dots.
@@ -1500,7 +1501,7 @@ This function does not return `implicit-;' or `type-:'."
15001501
text
15011502
(point)
15021503
(+ (point) (length text))))
1503-
((member text '("try" "await" "consume"))
1504+
((member text '("try" "await" "consume" "copy"))
15041505
(swift-mode:token 'prefix-operator
15051506
text
15061507
(point)

test/swift-files/indent/declarations.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,13 @@ private
343343
inout
344344
Int,
345345
y:
346+
borrowing
346347
Int
347348
=
348349
1,
349350
z,
350351
w:
352+
consuming
351353
Int
352354
...
353355
)

test/swift-files/indent/expressions.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,3 +833,13 @@ func foo() {
833833

834834
return y
835835
}
836+
837+
838+
// copy operator
839+
// https://github.com/apple/swift-evolution/blob/main/proposals/0377-parameter-ownership-modifiers.md
840+
841+
func foo() {
842+
// copy operator cannot be followed by a line break.
843+
copy
844+
x
845+
}

test/swift-files/indent/identifiers.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ func foo() {
6767
foo(
6868
inout: 1
6969
)
70+
foo(
71+
borrowing: 1
72+
)
73+
foo(
74+
consuming: 1
75+
)
7076
foo(
7177
internal: 1
7278
)
@@ -215,6 +221,9 @@ func foo() {
215221
foo(
216222
consume: 1
217223
)
224+
foo(
225+
copy: 1
226+
)
218227

219228
// Keywords reserved in particular contexts
220229
foo(

0 commit comments

Comments
 (0)