@@ -0,0 +1,371 @@
1+%YAML 1.2
2+---
3+# http://www.sublimetext.com/docs/3/syntax.html
4+name: Swift
5+file_extensions:
6+ - swift
7+first_line_match: ^#!/.*\bswift
8+scope: source.swift
9+contexts:
10+ main:
11+ - include: shebang-line
12+ - include: comment
13+ - include: attribute
14+ - include: literal
15+ - include: operator
16+ - include: declaration
17+ - include: storage-type
18+ - include: keyword
19+ - include: type
20+ - include: boolean
21+ comment:
22+ - include: documentation-comment
23+ - include: block-comment
24+ - include: in-line-comment
25+ access-level-modifier:
26+ - match: \b(open|public|internal|fileprivate|private)\b(?:\(set\))?
27+ comment: access-level-modifier
28+ scope: keyword.other.access-level-modifier.swift
29+ arithmetic-operator:
30+ - match: '(?<![/=\-+!*%<>&|\^~.])(\+|\-|\*|\/)(?![/=\-+!*%<>&|\^~.])'
31+ scope: keyword.operator.arithmetic.swift
32+ array-type:
33+ - match: \b(Array)(<)
34+ captures:
35+ 1: support.type.array.swift
36+ 2: punctuation.array.begin.swift
37+ push:
38+ - meta_scope: meta.array.swift
39+ - match: (>)
40+ captures:
41+ 1: punctuation.array.end.swift
42+ pop: true
43+ - include: main
44+ assignment-operator:
45+ - match: '(?<![/=\-+!*%<>&|\^~.])(\+|\-|\*|\/|%|<<|>>|&|\^|\||&&|\|\|)?=(?![/=\-+!*%<>&|\^~.])'
46+ scope: keyword.operator.assignment.swift
47+ attribute:
48+ - match: '((@)(\B\$[0-9]+|\b[\w^\d][\w\d]*\b|\B`[\w^\d][\w\d]*`\B))(\()'
49+ captures:
50+ 1: storage.modifier.attribute.swift
51+ 2: punctuation.definition.attribute.swift
52+ 3: punctuation.definition.attribute-arguments.begin.swift
53+ push:
54+ - meta_content_scope: meta.attribute.arguments.swift
55+ - match: \)
56+ captures:
57+ 0: punctuation.definition.attribute-arguments.end.swift
58+ pop: true
59+ - include: main
60+ - match: '((@)(\B\$[0-9]+|\b[\w^\d][\w\d]*\b|\B`[\w^\d][\w\d]*`\B))'
61+ captures:
62+ 1: storage.modifier.attribute.swift
63+ 2: punctuation.definition.attribute.swift
64+ bitwise-operator:
65+ - match: '(?<![/=\-+!*%<>&|\^~.])(&|\||\^|<<|>>)(?![/=\-+!*%<>&|\^~.])'
66+ scope: keyword.operator.bitwise.swift
67+ block-comment:
68+ - match: /\*
69+ comment: Block comment
70+ captures:
71+ 0: punctuation.definition.comment.block.begin.swift
72+ push:
73+ - meta_scope: comment.block.swift
74+ - match: \*/
75+ captures:
76+ 0: punctuation.definition.comment.block.end.swift
77+ pop: true
78+ boolean:
79+ - match: \b(true|false)\b
80+ scope: keyword.constant.boolean.swift
81+ branch-statement-keyword:
82+ - include: if-statement-keyword
83+ - include: switch-statement-keyword
84+ catch-statement-keyword:
85+ - match: \b(catch|do)\b
86+ comment: catch-statement
87+ scope: kewyord.control.catch.swift
88+ code-block:
89+ - match: '(\{)'
90+ comment: code-block
91+ captures:
92+ 1: punctuation.definition.code-block.begin.swift
93+ push:
94+ - match: '(\})'
95+ captures:
96+ 1: punctuation.definition.code-block.end.swift
97+ pop: true
98+ - include: main
99+ collection-type:
100+ - include: array-type
101+ - include: dictionary-type
102+ - match: \b(Array|Dictionary)\b
103+ scope: support.type.swift
104+ comparative-operator:
105+ - match: '(?<![/=\-+!*%<>&|\^~.])((=|!)==?|(<|>)=?|~=)(?![/=\-+!*%<>&|\^~.])'
106+ scope: keyword.operator.comparative.swift
107+ control-transfer-statement-keyword:
108+ - match: \b(continue|break|fallthrough|return)\b
109+ comment: control-transfer-statement
110+ scope: keyword.control.transfer.swift
111+ custom-operator:
112+ - match: '(?<=[\s(\[{,;:])([/=\-+!*%<>&|\^~.]++)(?![\s)\]},;:])'
113+ scope: keyword.operator.custom.prefix.unary.swift
114+ - match: '(?<![\s(\[{,;:])([/=\-+!*%<>&|\^~.]++)(?![\s)\]},;:\.])'
115+ scope: keyword.operator.custom.postfix.unary.swift
116+ - match: '(?<=[\s(\[{,;:])([/=\-+!*%<>&|\^~.]++)(?=[\s)\]},;:])'
117+ scope: keyword.operator.custom.binary.swift
118+ declaration:
119+ - include: import-declaration
120+ - include: function-declaration
121+ declaration-modifier:
122+ - match: \b(class|convenience|dynamic|final|lazy|(non)?mutating|optional|override|required|static|unowned((un)?safe)?|weak)\b
123+ comment: declaration-modifier
124+ scope: keyword.other.declaration-modifier.swift
125+ dictionary-type:
126+ - match: \b(Dictionary)(<)
127+ captures:
128+ 1: support.type.dictionary.swift
129+ 2: punctuation.dictionary.begin.swift
130+ push:
131+ - meta_scope: meta.dictionary.swift
132+ - match: (>)
133+ captures:
134+ 1: punctuation.dictionary.end.swift
135+ pop: true
136+ - include: main
137+ documentation-comment:
138+ - match: /\*\*
139+ comment: Documentation comment
140+ captures:
141+ 0: punctuation.definition.comment.block.documentation.begin.swift
142+ push:
143+ - meta_scope: comment.block.documentation.swift
144+ - match: \*/
145+ captures:
146+ 0: punctuation.definition.comment.block.documentation.end.swift
147+ pop: true
148+ floating-point-literal:
149+ - match: '\b([0-9][0-9_]*)(\.([0-9][0-9_]*))?([eE][+\-]?([0-9][0-9_]*))?\b'
150+ comment: floating-point-literal -> (decimal-literal)(decimal-fraction)?(decimal-exponent)?
151+ - match: '\b(0x\h[\h_]*)(\.(0x\h[\h_]*))?([pP][+\-]?(0x\h[\h_]*))\b'
152+ comment: floating-point-literal -> (hexadecimal-literal)(hexadecimal-fraction)?(hexadecimal-exponent)
153+ function-body:
154+ - include: code-block
155+ function-declaration:
156+ - match: '\b(func)\s+(\B\$[0-9]+|\b[\w^\d][\w\d]*\b|\B`[\w^\d][\w\d]*`\B|[/=\-+!*%<>&|\^~.]+)\s*(?=\(|<)'
157+ comment: function-declaration
158+ captures:
159+ 1: storage.type.function.swift
160+ 2: entity.type.function.swift
161+ push:
162+ - meta_scope: meta.function-declaration.swift
163+ - match: '(?<=\})'
164+ pop: true
165+ - include: generic-parameter-clause
166+ - include: parameter-clause
167+ - include: function-result
168+ - include: function-body
169+ function-result:
170+ - match: '(?<![/=\-+!*%<>&|\^~.])(\->)(?![/=\-+!*%<>&|\^~.])\s*'
171+ comment: function-result
172+ captures:
173+ 1: keyword.operator.function-result.swift
174+ push:
175+ - meta_scope: meta.function-result.swift
176+ - match: '\s*(?=\{)'
177+ pop: true
178+ - include: type
179+ generic-parameter-clause:
180+ - match: (<)
181+ comment: generic-parameter-clause
182+ captures:
183+ 1: punctuation.definition.generic-parameter-clause.begin.swift
184+ push:
185+ - meta_scope: meta.generic-parameter-clause.swift
186+ - match: (>)
187+ captures:
188+ 1: punctuation.definition.generic-parameter-clause.end.swift
189+ pop: true
190+ - include: main
191+ identifier:
192+ - match: '(\B\$[0-9]+|\b[\w^\d][\w\d]*\b|\B`[\w^\d][\w\d]*`\B)'
193+ comment: identifier
194+ scope: meta.identifier.swift
195+ if-statement-keyword:
196+ - match: \b(if|else)\b
197+ comment: if-statement
198+ scope: keyword.control.if.swift
199+ import-declaration:
200+ - match: '\b(import)\s+(?:(typealias|struct|class|enum|protocol|var|func)\s+)?((?:\B\$[0-9]+|\b[\w^\d][\w\d]*\b|\B`[\w^\d][\w\d]*`\B|[/=\-+!*%<>&|\^~.]+)(?:\.(?:\B\$[0-9]+|\b[\w^\d][\w\d]*\b|\B`[\w^\d][\w\d]*`\B|[/=\-+!*%<>&|\^~.]+))*)'
201+ comment: import-declaration
202+ scope: meta.import.swift
203+ captures:
204+ 1: keyword.other.import.swift
205+ 2: storage.modifier.swift
206+ 3: support.type.module.import.swift
207+ in-line-comment:
208+ - match: (//).*
209+ comment: In-line comment
210+ scope: comment.line.double-slash.swift
211+ captures:
212+ 1: punctuation.definition.comment.line.double-slash.swift
213+ increment-decrement-operator:
214+ - match: '(?<![/=\-+!*%<>&|\^~.])(\+\+|\-\-)(?![/=\-+!*%<>&|\^~.])'
215+ scope: keyword.operator.increment-or-decrement.swift
216+ integer-literal:
217+ - match: '(\B\-|\b)(0b[01][01_]*)\b'
218+ comment: binary-literal
219+ scope: constant.numeric.integer.binary.swift
220+ - match: '(\B\-|\b)(0o[0-7][0-7_]*)\b'
221+ comment: octal-literal
222+ scope: constant.numeric.integer.octal.swift
223+ - match: '(\B\-|\b)([0-9][0-9_]*)\b'
224+ comment: decimal-literal
225+ scope: constant.numeric.integer.decimal.swift
226+ - match: '(\B\-|\b)(0x\h[\h_]*)\b'
227+ comment: hexadecimal-literal
228+ scope: constant.numeric.integer.hexadecimal.swift
229+ integer-type:
230+ - match: \bU?Int(8|16|32|64)?\b
231+ comment: Int types
232+ scope: support.type.swift
233+ keyword:
234+ - include: branch-statement-keyword
235+ - include: control-transfer-statement-keyword
236+ - include: loop-statement-keyword
237+ - include: catch-statement-keyword
238+ - include: operator-declaration-modifier
239+ - include: declaration-modifier
240+ - include: access-level-modifier
241+ - match: \b(class|deinit|enum|extension|func|import|init|let|protocol|static|struct|subscript|typealias|var|throws|rethrows)\b
242+ comment: declaration keyword
243+ scope: keyword.declaration.swift
244+ - match: \b(break|case|continue|default|do|else|fallthrough|if|in|for|return|switch|where|while|repeat|catch|guard|defer|try|throw)\b
245+ comment: statement keyword
246+ scope: keyword.statement.swift
247+ - match: \b(as|dynamicType|is|new|super|self|Self|Type)\b
248+ comment: expression and type keyword
249+ scope: keyword.other.statement.swift
250+ - match: \b(associativity|didSet|get|infix|inout|left|mutating|none|nonmutating|operator|override|postfix|precedence|prefix|right|set|unowned((un)?safe)?|weak|willSet)\b
251+ comment: other keyword
252+ scope: keyword.other.swift
253+ literal:
254+ - include: integer-literal
255+ - include: floating-point-literal
256+ - include: nil-literal
257+ - include: string-literal
258+ - include: special-literal
259+ logical-operator:
260+ - match: '(?<![/=\-+!*%<>&|\^~.])(!|&&|\|\|)(?![/=\-+!*%<>&|\^~.])'
261+ scope: keyword.operator.logical.swift
262+ loop-statement-keyword:
263+ - match: \b(while|repeat|for|in)\b
264+ comment: loop-statement
265+ scope: keyword.control.loop.swift
266+ nil-literal:
267+ - match: \bnil\b
268+ comment: nil-literal
269+ scope: constant.nil.swift
270+ operator:
271+ - include: comparative-operator
272+ - include: assignment-operator
273+ - include: logical-operator
274+ - include: remainder-operator
275+ - include: increment-decrement-operator
276+ - include: overflow-operator
277+ - include: range-operator
278+ - include: bitwise-operator
279+ - include: arithmetic-operator
280+ - include: ternary-operator
281+ - include: type-casting-operator
282+ - include: custom-operator
283+ operator-declaration-modifier:
284+ - match: \b(operator|prefix|infix|postfix)\b
285+ comment: operator-declaration
286+ scope: keyword.other.operator.swift
287+ optional-type:
288+ - match: \b(Optional)(<)
289+ scope: meta.optional.swift
290+ overflow-operator:
291+ - match: '(?<![/=\-+!*%<>&|\^~.])\&(\+|\-|\*|\/|%)(?![/=\-+!*%<>&|\^~.])'
292+ scope: keyword.operator.overflow.swift
293+ parameter-clause:
294+ - match: (\()
295+ comment: parameter-clause
296+ captures:
297+ 1: punctuation.definition.function-arguments.begin.swift
298+ push:
299+ - meta_scope: meta.parameter-clause.swift
300+ - match: (\))
301+ captures:
302+ 1: punctuation.definition.function-arguments.end.swift
303+ pop: true
304+ - include: main
305+ primitive-type:
306+ - match: \b(Int|Float|Double|String|Bool|Character|Void)\b
307+ comment: Primitive types
308+ scope: support.type.swift
309+ protocol-composition-type:
310+ - match: \b(protocol)(<)
311+ scope: meta.protocol.swift
312+ range-operator:
313+ - match: '(?<![/=\-+!*%<>&|\^~.])\.\.(?:\.)?(?![/=\-+!*%<>&|\^~.])'
314+ scope: keyword.operator.range.swift
315+ remainder-operator:
316+ - match: '(?<![/=\-+!*%<>&|\^~.])\%(?![/=\-+!*%<>&|\^~.])'
317+ scope: keyword.operator.remainder.swift
318+ shebang-line:
319+ - match: ^(#!).*$
320+ comment: Shebang line
321+ scope: comment.line.shebang.swift
322+ captures:
323+ 1: punctuation.definition.comment.line.shebang.swift
324+ special-literal:
325+ - match: \b__(FILE|LINE|COLUMN|FUNCTION)__\b
326+ scope: keyword.other.literal.swift
327+ storage-type:
328+ - match: \b(var|func|let|class|enum|struct|protocol|extension|typealias)\b
329+ scope: storage.type.swift
330+ string-literal:
331+ - match: \"
332+ captures:
333+ 0: string.quoted.double.swift
334+ push:
335+ - meta_scope: meta.literal.string.swift
336+ - match: \"
337+ captures:
338+ 0: string.quoted.double.swift
339+ pop: true
340+ - match: '\\([0tnr\"\''\\]|x\h{2}|u\h{4}|U\h{8})'
341+ scope: constant.character.escape.swift
342+ - match: (\\\()
343+ captures:
344+ 1: support.punctuation.expression.begin.swift
345+ push:
346+ - meta_content_scope: meta.expression.swift
347+ - match: (\))
348+ captures:
349+ 1: support.punctuation.expression.end.swift
350+ pop: true
351+ - include: scope:source.swift
352+ - match: (\"|\\)
353+ scope: invalid.illegal.swift
354+ - match: (.)
355+ scope: string.quoted.double.swift
356+ switch-statement-keyword:
357+ - match: \b(switch|case|default|where)\b
358+ comment: switch-statement
359+ scope: keyword.control.switch.swift
360+ ternary-operator:
361+ - match: '(?<=[\s(\[{,;:])(\?|:)(?=[\s)\]},;:])'
362+ scope: keyword.operator.ternary.swift
363+ type:
364+ - include: primitive-type
365+ - include: integer-type
366+ - include: collection-type
367+ - include: optional-type
368+ - include: protocol-composition-type
369+ type-casting-operator:
370+ - match: \b(is\b|as(\?\B|\b))
371+ scope: keyword.operator.type-casting.swift