-
Notifications
You must be signed in to change notification settings - Fork 1
/
Swift.sublime-syntax
199 lines (182 loc) · 7.2 KB
/
Swift.sublime-syntax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
# This file is a porting of the Swift Language Reference
# https://docs.swift.org/swift-book/ReferenceManual/zzSummaryOfTheGrammar.html
name: Swift
scope: source.swift
file_extensions:
- swift
variables:
identifier_head_unicode: \x00A8\x00AA\x00AD\x00AF\x00B2–\x00B5\x00B7–\x00BA\x00BC–\x00BE\x00C0–\x00D6\x00D8–\x00F6\x00F8–\x00FF\x0100–\x02FF\x0370–\x167F\x1681–\x180D\x180F–\x1DBF\x1E00–\x1FFF\x200B–\x200D\x202A–\x202E\x203F–\x2040\x2054\x2060–\x206F\x2070–\x20CF\x2100–\x218F\x2460–\x24FF\x2776–\x2793\x2C00–\x2DFF\x2E80–\x2FFF\x3004–\x3007\x3021–\x302F\x3031–\x303F\x3040–\xD7FF\xF900–\xFD3D\xFD40–\xFDCF\xFDF0–\xFE1F\xFE30–\xFE44\xFE47–\xFFFD\x10000–\x1FFFD\x20000–\x2FFFD\x30000–\x3FFFD\x40000–\x4FFFD\x50000–\x5FFFD\x60000–\x6FFFD\x70000–\x7FFFD\x80000–\x8FFFD\x90000–\x9FFFD\xA0000–\xAFFFD\xB0000–\xBFFFD\xC0000–\xCFFFD\xD0000–\xDFFFD\xE0000–\xEFFFD
identifier_head: '[a-zA-Z_{{identifier_head_unicode}}]'
identifier_character: '[0-9\x0300–\x036F\x1DC0–\x1DFF\x20D0–\x20FF\xFE20–\xFE2F{{identifier_head}}]'
line_break: '(?:\x0D\x0A?|\x0A)'
inline_space: '[\x09\x20]'
contexts:
main:
- include: expression
whitespace:
- include: line-break
- include: inline-spaces
- include: comment
- include: multiline-comment
- match: '[\x00\x0B\x0C]+'
line-break:
- match: '{{line_break}}'
inline-spaces:
- match: '{{inline_space}}+'
comment:
- match: //
scope: punctuation.definition.comment.begin.swift
push:
- meta_scope: comment.line.swift
# TODO: add MARK section navigation
- match: '{{line_break}}'
pop: 1
multiline-comment:
- match: '/\*'
scope: punctuation.definition.comment.begin.swift
push:
- meta_scope: comment.block.swift
- include: multiline-comment
- match: '\*/'
scope: punctuation.definition.comment.end.swift
pop: 1
implicit-parameter-name:
- match: '\$[0-9]+\b'
property-wrapper-projection:
- match: '\${{identifier_character}}+'
identifier:
- match: '\b{{identifier_head}}{{identifier_character}}*'
scope: variable
- match: '`{{identifier_head}}{{identifier_character}}*`'
scope: variable
- include: implicit-parameter-name
- include: property-wrapper-projection
integer-literal:
- match: \b(0b)([01][01_]*)
scope: meta.number.integer.binary.swift
captures:
1: constant.numeric.base.swift
2: constant.numeric.value.swift
- match: \b(0o)([0-7][0-7_]*)
scope: meta.number.integer.octal.swift
captures:
1: constant.numeric.base.swift
2: constant.numeric.value.swift
- match: \b(0x)([0-9a-fA-F][0-9a-fA-F_]*)
scope: meta.number.integer.hexadecimal.swift
captures:
1: constant.numeric.base.swift
2: constant.numeric.value.swift
- match: \b[0-9][0-9_]*
scope: meta.number.integer.decimal.swift constant.numeric.value.swift
floating-point-literal:
- match: \b[0-9][0-9_]*(\.)[0-9][0-9_]*(?:[eE][\-+]?[0-9][0-9_]*)?
scope: meta.number.float.decimal.swift constant.numeric.value.swift
captures:
1: punctuation.separator.decimal.swift
- match: \b(0x)([0-9a-fA-F][0-9a-fA-F_]*(\.)[0-9a-fA-F][0-9a-fA-F_]*(?:[pP][\-+]?[0-9][0-9_]*)?)
scope: meta.number.float.hexadecimal.swift
captures:
1: constant.numeric.base.swift
2: constant.numeric.value.swift
3: punctuation.separator.decimal.swift
string-literal:
- match: '#+"""'
scope: punctuation.definition.string.begin.swift
push:
- meta_scope: meta.string.swift string.quoted.double.block.swift
- match: '\\#+[0\\tnr"'']'
scope: constant.character.escape.swift
- match: '\\#+u\{[0-9a-fA-F]{1,8}\}'
scope: constant.character.escape.unicode.swift
- match: '\\#+\('
scope: punctuation.section.interpolation.begin.swift
push:
- clear_scopes: 1
- meta_scope: meta.interpolation.swift
- match: '\)'
scope: punctuation.section.interpolation.end.swift
pop: 1
- match: '\\{{inline_space}}*{{line_break}}'
scope: punctuation.separator.continuation.line.swift
- match: '"""#+'
scope: punctuation.definition.string.end.swift
pop: 1
- match: '"""'
scope: punctuation.definition.string.begin.swift
push:
- meta_scope: meta.string.swift string.quoted.double.block.swift
- match: '\\[0\\tnr"'']'
scope: constant.character.escape.swift
- match: '\\u\{[0-9a-fA-F]{1,8}\}'
scope: constant.character.escape.unicode.swift
- match: '\\\('
scope: punctuation.section.interpolation.begin.swift
push:
- clear_scopes: 1
- meta_scope: meta.interpolation.swift
- include: expression
- match: '\)'
scope: punctuation.section.interpolation.end.swift
pop: 1
- match: '\\{{inline_space}}*{{line_break}}'
scope: punctuation.separator.continuation.line.swift
- match: '"""'
scope: punctuation.definition.string.end.swift
pop: 1
- match: '#+"'
scope: punctuation.definition.string.begin.swift
push:
- meta_scope: meta.string.swift string.quoted.double.swift
- match: '\\#+[0\\tnr"'']'
scope: constant.character.escape.swift
- match: '\\#+u\{[0-9a-fA-F]{1,8}\}'
scope: constant.character.escape.unicode.swift
- match: '\\#+\('
scope: punctuation.section.interpolation.begin.swift
push:
- clear_scopes: 1
- meta_scope: meta.interpolation.swift
- include: expression
- match: '\)'
scope: punctuation.section.interpolation.end.swift
pop: 1
- match: '{{line_break}}'
scope: invalid.illegal.unclosed-string.swift
pop: 1
- match: '"#+'
scope: punctuation.definition.string.end.swift
pop: 1
- match: '"'
scope: punctuation.definition.string.begin.swift
push:
- meta_scope: meta.string.swift string.quoted.double.swift
- match: '\\[0\\tnr"'']'
scope: constant.character.escape.swift
- match: '\\u\{[0-9a-fA-F]{1,8}\}'
scope: constant.character.escape.unicode.swift
- match: '\\\('
scope: punctuation.section.interpolation.begin.swift
push:
- clear_scopes: 1
- meta_scope: meta.interpolation.swift
- include: expression
- match: '\)'
scope: punctuation.section.interpolation.end.swift
pop: 1
- match: '\\'
scope: invalid.illegal.unexpected-text.swift
- match: '{{line_break}}'
scope: invalid.illegal.unclosed-string.swift
pop: 1
- match: '"'
scope: punctuation.definition.string.end.swift
pop: 1
expression:
- include: whitespace
- include: string-literal
- include: floating-point-literal
- include: integer-literal