-
Notifications
You must be signed in to change notification settings - Fork 0
/
swift.grammer
563 lines (464 loc) · 25.3 KB
/
swift.grammer
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
// Statements
// GRAMMAR OF A STATEMENT
statement : expression
statement : declaration
statement : loop-statement
statement : branch-statement
statement : labeled-statement
statement : control-transfer-statement
statements : statementstatements
// GRAMMAR OF A LOOP STATEMENT
loop-statement → for-statement
loop-statement → for-in-statement
loop-statement → while-statement
loop-statement → do-while-statement
// GRAMMAR OF A FOR STATEMENT
for-statement → forfor-initopt;expressionopt;expressionoptcode-block
for-statement → for(for-initopt;expressionopt;expressionopt)code-block
for-init → variable-declaration expression-list
GRAMMAR OF A FOR-IN STATEMENT
for-in-statement → forpatterninexpressioncode-block
GRAMMAR OF A WHILE STATEMENT
while-statement → whilewhile-conditioncode-block
while-condition → expression declaration
GRAMMAR OF A DO-WHILE STATEMENT
do-while-statement → docode-blockwhilewhile-condition
GRAMMAR OF A BRANCH STATEMENT
branch-statement → if-statement
branch-statement → switch-statement
GRAMMAR OF AN IF STATEMENT
if-statement → ifif-conditioncode-blockelse-clauseopt
if-condition → expression declaration
else-clause → elsecode-block elseif-statement
GRAMMAR OF A SWITCH STATEMENT
switch-statement → switchexpression{switch-casesopt}
switch-cases → switch-caseswitch-casesopt
switch-case → case-labelstatements default-labelstatements
switch-case → case-label; default-label;
case-label → casecase-item-list:
case-item-list → patternguard-clauseopt patternguard-clauseopt,case-item-list
default-label → default:
guard-clause → whereguard-expression
guard-expression → expression
GRAMMAR OF A LABELED STATEMENT
labeled-statement → statement-labelloop-statement statement-labelswitch-statement
statement-label → label-name:
label-name → identifier
GRAMMAR OF A CONTROL TRANSFER STATEMENT
control-transfer-statement → break-statement
control-transfer-statement → continue-statement
control-transfer-statement → fallthrough-statement
control-transfer-statement → return-statement
GRAMMAR OF A BREAK STATEMENT
break-statement → breaklabel-nameopt
GRAMMAR OF A CONTINUE STATEMENT
continue-statement → continuelabel-nameopt
GRAMMAR OF A FALLTHROUGH STATEMENT
fallthrough-statement → fallthrough
GRAMMAR OF A RETURN STATEMENT
return-statement → returnexpressionopt
Generic Parameters and Arguments
GRAMMAR OF A GENERIC PARAMETER CLAUSE
generic-parameter-clause → <generic-parameter-listrequirement-clauseopt>
generic-parameter-list → generic-parameter generic-parameter,generic-parameter-list
generic-parameter → type-name
generic-parameter → type-name:type-identifier
generic-parameter → type-name:protocol-composition-type
requirement-clause → whererequirement-list
requirement-list → requirement requirement,requirement-list
requirement → conformance-requirement same-type-requirement
conformance-requirement → type-identifier:type-identifier
conformance-requirement → type-identifier:protocol-composition-type
same-type-requirement → type-identifier==type-identifier
GRAMMAR OF A GENERIC ARGUMENT CLAUSE
generic-argument-clause → <generic-argument-list>
generic-argument-list → generic-argument generic-argument,generic-argument-list
generic-argument → type
Declarations
GRAMMAR OF A DECLARATION
declaration → import-declaration
declaration → constant-declaration
declaration → variable-declaration
declaration → typealias-declaration
declaration → function-declaration
declaration → enum-declaration
declaration → struct-declaration
declaration → class-declaration
declaration → protocol-declaration
declaration → initializer-declaration
declaration → deinitializer-declaration
declaration → extension-declaration
declaration → subscript-declaration
declaration → operator-declaration
declarations → declarationdeclarationsopt
declaration-specifiers → declaration-specifierdeclaration-specifiersopt
declaration-specifier → class mutating nonmutating override static unowned unowned(safe) unowned(unsafe) weak
GRAMMAR OF A TOP-LEVEL DECLARATION
top-level-declaration → statementsopt
GRAMMAR OF A CODE BLOCK
code-block → {statementsopt}
GRAMMAR OF AN IMPORT DECLARATION
import-declaration → attributesoptimportimport-kindoptimport-path
import-kind → typealias struct class enum protocol var func
import-path → import-path-identifier import-path-identifier.import-path
import-path-identifier → identifier operator
GRAMMAR OF A CONSTANT DECLARATION
constant-declaration → attributesoptdeclaration-specifiersoptletpattern-initializer-list
pattern-initializer-list → pattern-initializer pattern-initializer,pattern-initializer-list
pattern-initializer → patterninitializeropt
initializer → =expression
GRAMMAR OF A VARIABLE DECLARATION
variable-declaration → variable-declaration-headpattern-initializer-list
variable-declaration → variable-declaration-headvariable-nametype-annotationcode-block
variable-declaration → variable-declaration-headvariable-nametype-annotationgetter-setter-block
variable-declaration → variable-declaration-headvariable-nametype-annotationgetter-setter-keyword-block
variable-declaration → variable-declaration-headvariable-nametype-annotationinitializeroptwillSet-didSet-block
variable-declaration-head → attributesoptdeclaration-specifiersoptvar
variable-name → identifier
getter-setter-block → {getter-clausesetter-clauseopt}
getter-setter-block → {setter-clausegetter-clause}
getter-clause → attributesoptgetcode-block
setter-clause → attributesoptsetsetter-nameoptcode-block
setter-name → (identifier)
getter-setter-keyword-block → {getter-keyword-clausesetter-keyword-clauseopt}
getter-setter-keyword-block → {setter-keyword-clausegetter-keyword-clause}
getter-keyword-clause → attributesoptget
setter-keyword-clause → attributesoptset
willSet-didSet-block → {willSet-clausedidSet-clauseopt}
willSet-didSet-block → {didSet-clausewillSet-clause}
willSet-clause → attributesoptwillSetsetter-nameoptcode-block
didSet-clause → attributesoptdidSetsetter-nameoptcode-block
GRAMMAR OF A TYPE ALIAS DECLARATION
typealias-declaration → typealias-headtypealias-assignment
typealias-head → typealiastypealias-name
typealias-name → identifier
typealias-assignment → =type
GRAMMAR OF A FUNCTION DECLARATION
function-declaration → function-headfunction-namegeneric-parameter-clauseoptfunction-signaturefunction-body
function-head → attributesoptdeclaration-specifiersoptfunc
function-name → identifier operator
function-signature → parameter-clausesfunction-resultopt
function-result → ->attributesopttype
function-body → code-block
parameter-clauses → parameter-clauseparameter-clausesopt
parameter-clause → () (parameter-list...opt)
parameter-list → parameter parameter,parameter-list
parameter → inoutoptletopt#optparameter-namelocal-parameter-nameopttype-annotationdefault-argument-clauseopt
parameter → inoutoptvar#optparameter-namelocal-parameter-nameopttype-annotationdefault-argument-clauseopt
parameter → attributesopttype
parameter-name → identifier _
local-parameter-name → identifier _
default-argument-clause → =expression
GRAMMAR OF AN ENUMERATION DECLARATION
enum-declaration → attributesoptunion-style-enum attributesoptraw-value-style-enum
union-style-enum → enum-namegeneric-parameter-clauseopt{union-style-enum-membersopt}
union-style-enum-members → union-style-enum-memberunion-style-enum-membersopt
union-style-enum-member → declaration union-style-enum-case-clause
union-style-enum-case-clause → attributesoptcaseunion-style-enum-case-list
union-style-enum-case-list → union-style-enum-case union-style-enum-case,union-style-enum-case-list
union-style-enum-case → enum-case-nametuple-typeopt
enum-name → identifier
enum-case-name → identifier
raw-value-style-enum → enum-namegeneric-parameter-clauseopt:type-identifier{raw-value-style-enum-membersopt}
raw-value-style-enum-members → raw-value-style-enum-memberraw-value-style-enum-membersopt
raw-value-style-enum-member → declaration raw-value-style-enum-case-clause
raw-value-style-enum-case-clause → attributesoptcaseraw-value-style-enum-case-list
raw-value-style-enum-case-list → raw-value-style-enum-case raw-value-style-enum-case,raw-value-style-enum-case-list
raw-value-style-enum-case → enum-case-nameraw-value-assignmentopt
raw-value-assignment → =literal
GRAMMAR OF A STRUCTURE DECLARATION
struct-declaration → attributesoptstructstruct-namegeneric-parameter-clauseopttype-inheritance-clauseoptstruct-body
struct-name → identifier
struct-body → {declarationsopt}
GRAMMAR OF A CLASS DECLARATION
class-declaration → attributesoptclassclass-namegeneric-parameter-clauseopttype-inheritance-clauseoptclass-body
class-name → identifier
class-body → {declarationsopt}
GRAMMAR OF A PROTOCOL DECLARATION
protocol-declaration → attributesoptprotocolprotocol-nametype-inheritance-clauseoptprotocol-body
protocol-name → identifier
protocol-body → {protocol-member-declarationsopt}
protocol-member-declaration → protocol-property-declaration
protocol-member-declaration → protocol-method-declaration
protocol-member-declaration → protocol-initializer-declaration
protocol-member-declaration → protocol-subscript-declaration
protocol-member-declaration → protocol-associated-type-declaration
protocol-member-declarations → protocol-member-declarationprotocol-member-declarationsopt
GRAMMAR OF A PROTOCOL PROPERTY DECLARATION
protocol-property-declaration → variable-declaration-headvariable-nametype-annotationgetter-setter-keyword-block
GRAMMAR OF A PROTOCOL METHOD DECLARATION
protocol-method-declaration → function-headfunction-namegeneric-parameter-clauseoptfunction-signature
GRAMMAR OF A PROTOCOL INITIALIZER DECLARATION
protocol-initializer-declaration → initializer-headgeneric-parameter-clauseoptparameter-clause
GRAMMAR OF A PROTOCOL SUBSCRIPT DECLARATION
protocol-subscript-declaration → subscript-headsubscript-resultgetter-setter-keyword-block
GRAMMAR OF A PROTOCOL ASSOCIATED TYPE DECLARATION
protocol-associated-type-declaration → typealias-headtype-inheritance-clauseopttypealias-assignmentopt
GRAMMAR OF AN INITIALIZER DECLARATION
initializer-declaration → initializer-headgeneric-parameter-clauseoptparameter-clauseinitializer-body
initializer-head → attributesoptconvenienceoptinit
initializer-body → code-block
GRAMMAR OF A DEINITIALIZER DECLARATION
deinitializer-declaration → attributesoptdeinitcode-block
GRAMMAR OF AN EXTENSION DECLARATION
extension-declaration → extensiontype-identifiertype-inheritance-clauseoptextension-body
extension-body → {declarationsopt}
GRAMMAR OF A SUBSCRIPT DECLARATION
subscript-declaration → subscript-headsubscript-resultcode-block
subscript-declaration → subscript-headsubscript-resultgetter-setter-block
subscript-declaration → subscript-headsubscript-resultgetter-setter-keyword-block
subscript-head → attributesoptsubscriptparameter-clause
subscript-result → ->attributesopttype
GRAMMAR OF AN OPERATOR DECLARATION
operator-declaration → prefix-operator-declaration postfix-operator-declaration infix-operator-declaration
prefix-operator-declaration → operatorprefixoperator{}
postfix-operator-declaration → operatorpostfixoperator{}
infix-operator-declaration → operatorinfixoperator{infix-operator-attributesopt}
infix-operator-attributes → precedence-clauseoptassociativity-clauseopt
precedence-clause → precedenceprecedence-level
precedence-level → Digit 0 through 255
associativity-clause → associativityassociativity
associativity → left right none
Patterns
GRAMMAR OF A PATTERN
pattern → wildcard-patterntype-annotationopt
pattern → identifier-patterntype-annotationopt
pattern → value-binding-pattern
pattern → tuple-patterntype-annotationopt
pattern → enum-case-pattern
pattern → type-casting-pattern
pattern → expression-pattern
GRAMMAR OF A WILDCARD PATTERN
wildcard-pattern → _
GRAMMAR OF AN IDENTIFIER PATTERN
identifier-pattern → identifier
GRAMMAR OF A VALUE-BINDING PATTERN
value-binding-pattern → varpattern letpattern
GRAMMAR OF A TUPLE PATTERN
tuple-pattern → (tuple-pattern-element-listopt)
tuple-pattern-element-list → tuple-pattern-element tuple-pattern-element,tuple-pattern-element-list
tuple-pattern-element → pattern
GRAMMAR OF AN ENUMERATION CASE PATTERN
enum-case-pattern → type-identifieropt.enum-case-nametuple-patternopt
GRAMMAR OF A TYPE CASTING PATTERN
type-casting-pattern → is-pattern as-pattern
is-pattern → istype
as-pattern → patternastype
GRAMMAR OF AN EXPRESSION PATTERN
expression-pattern → expression
Attributes
GRAMMAR OF AN ATTRIBUTE
attribute → @attribute-nameattribute-argument-clauseopt
attribute-name → identifier
attribute-argument-clause → (balanced-tokensopt)
attributes → attributeattributesopt
balanced-tokens → balanced-tokenbalanced-tokensopt
balanced-token → (balanced-tokensopt)
balanced-token → [balanced-tokensopt]
balanced-token → {balanced-tokensopt}
balanced-token → Any identifier, keyword, literal, or operator
balanced-token → Any punctuation except (, ), [, ], {, or }
Expressions
GRAMMAR OF AN EXPRESSION
expression → prefix-expressionbinary-expressionsopt
expression-list → expression expression,expression-list
GRAMMAR OF A PREFIX EXPRESSION
prefix-expression → prefix-operatoroptpostfix-expression
prefix-expression → in-out-expression
in-out-expression → &identifier
GRAMMAR OF A BINARY EXPRESSION
binary-expression → binary-operatorprefix-expression
binary-expression → assignment-operatorprefix-expression
binary-expression → conditional-operatorprefix-expression
binary-expression → type-casting-operator
binary-expressions → binary-expressionbinary-expressionsopt
GRAMMAR OF AN ASSIGNMENT OPERATOR
assignment-operator → =
GRAMMAR OF A CONDITIONAL OPERATOR
conditional-operator → ?expression:
GRAMMAR OF A TYPE-CASTING OPERATOR
type-casting-operator → istype as?opttype
GRAMMAR OF A PRIMARY EXPRESSION
primary-expression → identifiergeneric-argument-clauseopt
primary-expression → literal-expression
primary-expression → self-expression
primary-expression → superclass-expression
primary-expression → closure-expression
primary-expression → parenthesized-expression
primary-expression → implicit-member-expression
primary-expression → wildcard-expression
GRAMMAR OF A LITERAL EXPRESSION
literal-expression → literal
literal-expression → array-literal dictionary-literal
literal-expression → __FILE__ __LINE__ __COLUMN__ __FUNCTION__
array-literal → [array-literal-itemsopt]
array-literal-items → array-literal-item,opt array-literal-item,array-literal-items
array-literal-item → expression
dictionary-literal → [dictionary-literal-items] [:]
dictionary-literal-items → dictionary-literal-item,opt dictionary-literal-item,dictionary-literal-items
dictionary-literal-item → expression:expression
GRAMMAR OF A SELF EXPRESSION
self-expression → self
self-expression → self.identifier
self-expression → self[expression]
self-expression → self.init
GRAMMAR OF A SUPERCLASS EXPRESSION
superclass-expression → superclass-method-expression superclass-subscript-expression superclass-initializer-expression
superclass-method-expression → super.identifier
superclass-subscript-expression → super[expression]
superclass-initializer-expression → super.init
GRAMMAR OF A CLOSURE EXPRESSION
closure-expression → {closure-signatureoptstatements}
closure-signature → parameter-clausefunction-resultoptin
closure-signature → identifier-listfunction-resultoptin
closure-signature → capture-listparameter-clausefunction-resultoptin
closure-signature → capture-listidentifier-listfunction-resultoptin
closure-signature → capture-listin
capture-list → [capture-specifierexpression]
capture-specifier → weak unowned unowned(safe) unowned(unsafe)
GRAMMAR OF A IMPLICIT MEMBER EXPRESSION
implicit-member-expression → .identifier
GRAMMAR OF A PARENTHESIZED EXPRESSION
parenthesized-expression → (expression-element-listopt)
expression-element-list → expression-element expression-element,expression-element-list
expression-element → expression identifier:expression
GRAMMAR OF A WILDCARD EXPRESSION
wildcard-expression → _
GRAMMAR OF A POSTFIX EXPRESSION
postfix-expression → primary-expression
postfix-expression → postfix-expressionpostfix-operator
postfix-expression → function-call-expression
postfix-expression → initializer-expression
postfix-expression → explicit-member-expression
postfix-expression → postfix-self-expression
postfix-expression → dynamic-type-expression
postfix-expression → subscript-expression
postfix-expression → forced-value-expression
postfix-expression → optional-chaining-expression
GRAMMAR OF A FUNCTION CALL EXPRESSION
function-call-expression → postfix-expressionparenthesized-expression
function-call-expression → postfix-expressionparenthesized-expressionopttrailing-closure
trailing-closure → closure-expression
GRAMMAR OF AN INITIALIZER EXPRESSION
initializer-expression → postfix-expression.init
GRAMMAR OF AN EXPLICIT MEMBER EXPRESSION
explicit-member-expression → postfix-expression.decimal-digit
explicit-member-expression → postfix-expression.identifiergeneric-argument-clauseopt
GRAMMAR OF A SELF EXPRESSION
postfix-self-expression → postfix-expression.self
GRAMMAR OF A DYNAMIC TYPE EXPRESSION
dynamic-type-expression → postfix-expression.dynamicType
GRAMMAR OF A SUBSCRIPT EXPRESSION
subscript-expression → postfix-expression[expression-list]
GRAMMAR OF A FORCED-VALUE EXPRESSION
forced-value-expression → postfix-expression!
GRAMMAR OF AN OPTIONAL-CHAINING EXPRESSION
optional-chaining-expression → postfix-expression?
Lexical Structure
GRAMMAR OF AN IDENTIFIER
identifier → identifier-headidentifier-charactersopt
identifier → `identifier-headidentifier-charactersopt`
identifier → implicit-parameter-name
identifier-list → identifier identifier,identifier-list
identifier-head → Upper- or lowercase letter A through Z
identifier-head → U+00A8, U+00AA, U+00AD, U+00AF, U+00B2–U+00B5, or U+00B7–U+00BA
identifier-head → U+00BC–U+00BE, U+00C0–U+00D6, U+00D8–U+00F6, or U+00F8–U+00FF
identifier-head → U+0100–U+02FF, U+0370–U+167F, U+1681–U+180D, or U+180F–U+1DBF
identifier-head → U+1E00–U+1FFF
identifier-head → U+200B–U+200D, U+202A–U+202E, U+203F–U+2040, U+2054, or U+2060–U+206F
identifier-head → U+2070–U+20CF, U+2100–U+218F, U+2460–U+24FF, or U+2776–U+2793
identifier-head → U+2C00–U+2DFF or U+2E80–U+2FFF
identifier-head → U+3004–U+3007, U+3021–U+302F, U+3031–U+303F, or U+3040–U+D7FF
identifier-head → U+F900–U+FD3D, U+FD40–U+FDCF, U+FDF0–U+FE1F, or U+FE30–U+FE44
identifier-head → U+FE47–U+FFFD
identifier-head → U+10000–U+1FFFD, U+20000–U+2FFFD, U+30000–U+3FFFD, or U+40000–U+4FFFD
identifier-head → U+50000–U+5FFFD, U+60000–U+6FFFD, U+70000–U+7FFFD, or U+80000–U+8FFFD
identifier-head → U+90000–U+9FFFD, U+A0000–U+AFFFD, U+B0000–U+BFFFD, or U+C0000–U+CFFFD
identifier-head → U+D0000–U+DFFFD or U+E0000–U+EFFFD
identifier-character → Digit 0 through 9
identifier-character → U+0300–U+036F, U+1DC0–U+1DFF, U+20D0–U+20FF, or U+FE20–U+FE2F
identifier-character → identifier-head
identifier-characters → identifier-characteridentifier-charactersopt
implicit-parameter-name → $decimal-digits
GRAMMAR OF A LITERAL
literal → integer-literal floating-point-literal string-literal
GRAMMAR OF AN INTEGER LITERAL
integer-literal → binary-literal
integer-literal → octal-literal
integer-literal → decimal-literal
integer-literal → hexadecimal-literal
binary-literal → 0bbinary-digitbinary-literal-charactersopt
binary-digit → Digit 0 or 1
binary-literal-character → binary-digit _
binary-literal-characters → binary-literal-characterbinary-literal-charactersopt
octal-literal → 0ooctal-digitoctal-literal-charactersopt
octal-digit → Digit 0 through 7
octal-literal-character → octal-digit _
octal-literal-characters → octal-literal-characteroctal-literal-charactersopt
decimal-literal → decimal-digitdecimal-literal-charactersopt
decimal-digit → Digit 0 through 9
decimal-digits → decimal-digitdecimal-digitsopt
decimal-literal-character → decimal-digit _
decimal-literal-characters → decimal-literal-characterdecimal-literal-charactersopt
hexadecimal-literal → 0xhexadecimal-digithexadecimal-literal-charactersopt
hexadecimal-digit → Digit 0 through 9, a through f, or A through F
hexadecimal-literal-character → hexadecimal-digit _
hexadecimal-literal-characters → hexadecimal-literal-characterhexadecimal-literal-charactersopt
GRAMMAR OF A FLOATING-POINT LITERAL
floating-point-literal → decimal-literaldecimal-fractionoptdecimal-exponentopt
floating-point-literal → hexadecimal-literalhexadecimal-fractionopthexadecimal-exponent
decimal-fraction → .decimal-literal
decimal-exponent → floating-point-esignoptdecimal-literal
hexadecimal-fraction → .hexadecimal-literalopt
hexadecimal-exponent → floating-point-psignopthexadecimal-literal
floating-point-e → e E
floating-point-p → p P
sign → + -
GRAMMAR OF A STRING LITERAL
string-literal → "quoted-text"
quoted-text → quoted-text-itemquoted-textopt
quoted-text-item → escaped-character
quoted-text-item → \(expression)
quoted-text-item → Any Unicode extended grapheme cluster except ", \, U+000A, or U+000D
escaped-character → \0 \\ \t \n \r \" \'
escaped-character → \xhexadecimal-digithexadecimal-digit
escaped-character → \uhexadecimal-digithexadecimal-digithexadecimal-digithexadecimal-digit
escaped-character → \Uhexadecimal-digithexadecimal-digithexadecimal-digithexadecimal-digithexadecimal-digithexadecimal-digithexadecimal-digithexadecimal-digit
GRAMMAR OF OPERATORS
operator → operator-characteroperatoropt
operator-character → / = - + ! * % < > & | ^ ~ .
binary-operator → operator
prefix-operator → operator
postfix-operator → operator
Types
GRAMMAR OF A TYPE
type → array-type function-type type-identifier tuple-type optional-type implicitly-unwrapped-optional-type protocol-composition-type metatype-type
GRAMMAR OF A TYPE ANNOTATION
type-annotation → :attributesopttype
GRAMMAR OF A TYPE IDENTIFIER
type-identifier → type-namegeneric-argument-clauseopt type-namegeneric-argument-clauseopt.type-identifier
type-name → identifier
GRAMMAR OF A TUPLE TYPE
tuple-type → (tuple-type-bodyopt)
tuple-type-body → tuple-type-element-list...opt
tuple-type-element-list → tuple-type-element tuple-type-element,tuple-type-element-list
tuple-type-element → attributesoptinoutopttype inoutoptelement-nametype-annotation
element-name → identifier
GRAMMAR OF A FUNCTION TYPE
function-type → type->type
GRAMMAR OF AN ARRAY TYPE
array-type → type[] array-type[]
GRAMMAR OF AN OPTIONAL TYPE
optional-type → type?
GRAMMAR OF AN IMPLICITLY UNWRAPPED OPTIONAL TYPE
implicitly-unwrapped-optional-type → type!
GRAMMAR OF A PROTOCOL COMPOSITION TYPE
protocol-composition-type → protocol<protocol-identifier-listopt>
protocol-identifier-list → protocol-identifier protocol-identifier,protocol-identifier-list
protocol-identifier → type-identifier
GRAMMAR OF A METATYPE TYPE
metatype-type → type.Type type.Protocol
GRAMMAR OF A TYPE INHERITANCE CLAUSE
type-inheritance-clause → :type-inheritance-list
type-inheritance-list → type-identifier type-identifier,type-inheritance-list
Generic Parameters and Arguments