Summary of the Grammar
Grammar of whitespace
whitespace → whitespace-item opt
whitespace-item → line-break
whitespace-item →
whitespace-item → multiline-comment
whitespace-item → U+0000, U+0009, U+000B, U+000C, or U+0020
line-break → U+000A
line-break → U+000D
line-break → U+000D followed by U+000A
comment → line-break
multiline-comment → /*
*/
comment-text → comment-text-item opt
comment-text-item → Any Unicode scalar value except U+000A or U+000D
multiline-comment-text → multiline-comment-text-item opt
multiline-comment-text-item → multiline-comment
multiline-comment-text-item →
multiline-comment-text-item → Any Unicode scalar value except /*
or */
Grammar of an identifier
identifier → identifier-head opt
identifier → `
identifier-head opt `
identifier → implicit-parameter-name
identifier-list → | identifier ,
identifier-head → Upper- or lowercase letter A through Z
identifier-head → _
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-characters opt
implicit-parameter-name → $
Grammar of a literal
literal → numeric-literal | | boolean-literal |
numeric-literal → -
opt integer-literal | -
opt
boolean-literal → true
| false
nil-literal → nil
Grammar of an integer literal
integer-literal → binary-literal
integer-literal →
integer-literal → decimal-literal
integer-literal →
binary-literal → 0b
binary-digit opt
binary-digit → Digit 0 or 1
binary-literal-character → binary-digit | _
binary-literal-characters → binary-literal-characters opt
octal-literal → 0o
octal-literal-characters opt
octal-digit → Digit 0 through 7
octal-literal-character → | _
octal-literal-characters → octal-literal-character opt
decimal-literal → decimal-digit opt
decimal-digit → Digit 0 through 9
decimal-digits → decimal-digit opt
decimal-literal-character → decimal-digit | _
decimal-literal-characters → decimal-literal-characters opt
hexadecimal-literal → 0x
hexadecimal-literal-characters opt
hexadecimal-digit → Digit 0 through 9, a through f, or A through F
hexadecimal-literal-character → | _
hexadecimal-literal-characters → hexadecimal-literal-character opt
Grammar of a floating-point literal
floating-point-literal → decimal-literal opt decimal-exponent opt
floating-point-literal → hexadecimal-fraction opt
decimal-fraction → .
decimal-literal
decimal-exponent → sign opt
hexadecimal-fraction → .
hexadecimal-digit opt
hexadecimal-exponent → floating-point-p opt decimal-literal
floating-point-e → e
| E
floating-point-p → p
| P
sign → +
| -
Grammar of a string literal
string-literal → | interpolated-string-literal
static-string-literal → "
opt "
static-string-literal → """
multiline-quoted-text opt """
quoted-text → quoted-text opt
quoted-text-item →
quoted-text-item → Any Unicode scalar value except "
, \
, U+000A, or U+000D
multiline-quoted-text → multiline-quoted-text-item opt
multiline-quoted-text-item → escaped-character
multiline-quoted-text-item → Any Unicode scalar value except \
multiline-quoted-text-item →
interpolated-string-literal → "
interpolated-text opt "
interpolated-string-literal → """
opt """
interpolated-text → interpolated-text-item opt
interpolated-text-item → \(
expression )
|
multiline-interpolated-text → multiline-interpolated-text-item opt
multiline-interpolated-text-item → \(
expression )
|
escaped-character → \0
| \\
| \t
| \n
| \r
| \"
| \'
escaped-character → \u
{
unicode-scalar-digits }
unicode-scalar-digits → Between one and eight hexadecimal digits
escaped-newline → \
opt line-break
Grammar of operators
operator → operator-characters opt
operator → dot-operator-characters
operator-head → /
| =
| -
| +
| !
| *
| %
| <
| >
| &
| |
| ^
| ~
| ?
operator-head → U+00A1–U+00A7
operator-head → U+00A9 or U+00AB
operator-head → U+00AC or U+00AE
operator-head → U+00B0–U+00B1, U+00B6, U+00BB, U+00BF, U+00D7, or U+00F7
operator-head → U+2016–U+2017 or U+2020–U+2027
operator-head → U+2030–U+203E
operator-head → U+2041–U+2053
operator-head → U+2055–U+205E
operator-head → U+2190–U+23FF
operator-head → U+2500–U+2775
operator-head → U+2794–U+2BFF
operator-head → U+2E00–U+2E7F
operator-head → U+3001–U+3003
operator-head → U+3008–U+3020 or U+3030
operator-character →
operator-character → U+0300–U+036F
operator-character → U+1DC0–U+1DFF
operator-character → U+20D0–U+20FF
operator-character → U+FE00–U+FE0F
operator-character → U+FE20–U+FE2F
operator-character → U+E0100–U+E01EF
operator-characters → operator-character opt
dot-operator-head → .
dot-operator-character → .
| operator-character
dot-operator-characters → dot-operator-characters opt
binary-operator →
prefix-operator → operator
postfix-operator →
Types
Grammar of a type
type →
type → dictionary-type
type →
type → type-identifier
type →
type → optional-type
type →
type → protocol-composition-type
type →
type → Any
type → Self
type → (
type )
Grammar of a type annotation
type-annotation → :
opt inout
opt type
Grammar of a type identifier
type-identifier → generic-argument-clause opt | generic-argument-clause opt .
type-name → identifier
Grammar of a tuple type
tuple-type → (
)
| (
,
tuple-type-element-list )
tuple-type-element-list → | tuple-type-element ,
tuple-type-element → element-name | type
element-name →
Grammar of a function type
function-type → attributes opt throws
opt ->
type
function-type → opt function-type-argument-clause rethrows
->
function-type-argument-clause → (
)
function-type-argument-clause → (
function-type-argument-list ...
opt )
function-type-argument-list → | function-type-argument ,
function-type-argument → attributes opt inout
opt | argument-label
argument-label → identifier
Grammar of an array type
array-type → [
]
Grammar of a dictionary type
dictionary-type → [
type :
]
Grammar of an optional type
optional-type → type ?
Grammar of an implicitly unwrapped optional type
implicitly-unwrapped-optional-type → !
Grammar of a protocol composition type
protocol-composition-type → type-identifier &
protocol-composition-continuation → type-identifier |
Grammar of a metatype type
metatype-type → type .
Type
| .
Protocol
Grammar of a type inheritance clause
type-inheritance-clause → :
type-inheritance-list
type-inheritance-list → | type-identifier ,
Grammar of an expression
expression → try-operator opt binary-expressions opt
expression-list → | expression ,
Grammar of a prefix expression
prefix-expression → prefix-operator opt
prefix-expression → in-out-expression
in-out-expression → &
Grammar of a try expression
try-operator → try
| try
?
| try
!
Grammar of a binary expression
binary-expression → binary-operator
binary-expression → assignment-operator opt prefix-expression
binary-expression → try-operator opt
binary-expression → type-casting-operator
binary-expressions → binary-expressions opt
Grammar of an assignment operator
assignment-operator → =
Grammar of a conditional operator
conditional-operator → ?
:
Grammar of a type-casting operator
type-casting-operator → is
type
type-casting-operator → as
type-casting-operator → as
?
type
type-casting-operator → as
!
Grammar of a primary expression
primary-expression → identifier opt
primary-expression → literal-expression
primary-expression →
primary-expression → superclass-expression
primary-expression →
primary-expression → parenthesized-expression
primary-expression →
primary-expression → implicit-member-expression
primary-expression →
primary-expression → key-path-expression
primary-expression →
primary-expression → key-path-string-expression
Grammar of a literal expression
literal-expression →
literal-expression → array-literal | | playground-literal
literal-expression → #file
| #line
| #column
| #function
| #dsohandle
array-literal → [
opt ]
array-literal-items → array-literal-item ,
opt | ,
array-literal-items
array-literal-item →
dictionary-literal → [
dictionary-literal-items ]
| [
:
]
dictionary-literal-item → :
expression
playground-literal → #colorLiteral
(
red
:
,
green
:
expression ,
blue
:
,
alpha
:
expression )
playground-literal → #fileLiteral
(
resourceName
:
)
playground-literal → #imageLiteral
(
resourceName
:
expression )
Grammar of a self expression
self-expression → self
| | self-subscript-expression |
self-method-expression → self
.
identifier
self-subscript-expression → self
[
]
self-initializer-expression → self
.
init
Grammar of a superclass expression
superclass-expression → superclass-method-expression | | superclass-initializer-expression
superclass-method-expression → super
.
superclass-subscript-expression → super
[
function-call-argument-list ]
superclass-initializer-expression → super
.
init
Grammar of a closure expression
closure-expression → {
opt statements opt }
closure-signature → opt closure-parameter-clause throws
opt opt in
closure-signature → capture-list in
closure-parameter-clause → (
| (
)
| identifier-list
closure-parameter-list → | closure-parameter ,
closure-parameter → closure-parameter-name opt
closure-parameter → closure-parameter-name ...
closure-parameter-name → identifier
capture-list → [
]
capture-list-items → capture-list-item | ,
capture-list-items
capture-list-item → opt expression
capture-specifier → weak
| unowned
| unowned(safe)
| unowned(unsafe)
Grammar of a implicit member expression
implicit-member-expression → .
Grammar of a parenthesized expression
parenthesized-expression → (
expression )
Grammar of a tuple expression
tuple-expression → (
)
| (
,
tuple-element-list )
tuple-element-list → | tuple-element ,
tuple-element → expression | :
expression
Grammar of a wildcard expression
wildcard-expression → _
Grammar of a key-path expression
key-path-expression → \
opt .
key-path-components
key-path-components → | key-path-component .
key-path-component → identifier opt | key-path-postfixes
key-path-postfixes → key-path-postfixes opt
key-path-postfix → ?
| !
| [
]
Grammar of a selector expression
selector-expression → #selector
(
expression )
selector-expression → #selector
(
getter:
)
selector-expression → #selector
(
setter:
expression )
Grammar of a key-path string expression
key-path-string-expression → #keyPath
(
)
Grammar of a postfix expression
postfix-expression → primary-expression
postfix-expression → postfix-operator
postfix-expression →
postfix-expression → initializer-expression
postfix-expression →
postfix-expression → postfix-self-expression
postfix-expression →
postfix-expression → forced-value-expression
postfix-expression →
Grammar of a function call expression
function-call-expression → postfix-expression
function-call-expression → postfix-expression opt trailing-closure
function-call-argument-clause → (
)
| (
)
function-call-argument-list → function-call-argument | ,
function-call-argument-list
function-call-argument → | identifier :
function-call-argument → operator | :
operator
trailing-closure →
Grammar of an initializer expression
initializer-expression → postfix-expression .
init
initializer-expression → .
init
(
argument-names )
Grammar of an explicit member expression
explicit-member-expression → .
decimal-digits
explicit-member-expression → .
identifier opt
explicit-member-expression → postfix-expression .
(
argument-names )
argument-names → argument-names opt
argument-name → :
Grammar of a self expression
postfix-self-expression → postfix-expression .
self
Grammar of a subscript expression
subscript-expression → [
function-call-argument-list ]
Grammar of a forced-value expression
forced-value-expression → !
Grammar of an optional-chaining expression
optional-chaining-expression → postfix-expression ?
Statements
Grammar of a statement
statement → expression ;
opt
statement → ;
opt
statement → loop-statement ;
opt
statement → ;
opt
statement → labeled-statement ;
opt
statement → ;
opt
statement → defer-statement ;
opt
statement → ;
opt
statement → compiler-control-statement
statements → statements opt
Grammar of a loop statement
loop-statement →
loop-statement → while-statement
loop-statement →
Grammar of a for-in statement
for-in-statement → for
case
opt pattern in
where-clause opt
Grammar of a while statement
while-statement → while
condition-list
condition-list → condition | ,
condition-list
condition → | availability-condition | | optional-binding-condition
case-condition → case
initializer
optional-binding-condition → let
initializer | var
initializer
Grammar of a repeat-while statement
repeat-while-statement → repeat
while
expression
Grammar of a branch statement
branch-statement →
branch-statement → guard-statement
branch-statement →
Grammar of an if statement
if-statement → if
condition-list else-clause opt
else-clause → else
| else
if-statement
Grammar of a guard statement
guard-statement → guard
else
code-block
Grammar of a switch statement
switch-statement → switch
{
switch-cases opt }
switch-cases → switch-cases opt
switch-case → statements
switch-case → statements
switch-case →
case-label → case
case-item-list :
case-item-list → where-clause opt | where-clause opt ,
default-label → default
:
where-clause → where
where-expression
where-expression →
conditional-switch-case → switch-if-directive-clause opt switch-else-directive-clause opt
switch-if-directive-clause → if-directive switch-cases opt
switch-elseif-directive-clauses → switch-elseif-directive-clauses opt
switch-elseif-directive-clause → compilation-condition opt
switch-else-directive-clause → else-directive opt
Grammar of a labeled statement
labeled-statement → statement-label
labeled-statement → statement-label
labeled-statement → statement-label
labeled-statement → statement-label
statement-label → label-name :
label-name →
Grammar of a control transfer statement
control-transfer-statement → break-statement
control-transfer-statement →
control-transfer-statement → fallthrough-statement
control-transfer-statement →
control-transfer-statement → throw-statement
Grammar of a break statement
break-statement → break
opt
Grammar of a continue statement
continue-statement → continue
label-name opt
Grammar of a fallthrough statement
fallthrough-statement → fallthrough
Grammar of a return statement
return-statement → return
opt
Grammar of a throw statement
throw-statement → throw
expression
Grammar of a defer statement
defer-statement → defer
Grammar of a do statement
do-statement → do
code-block opt
catch-clauses → catch-clause opt
catch-clause → catch
pattern opt opt code-block
Grammar of a compiler control statement
compiler-control-statement →
compiler-control-statement → line-control-statement
compiler-control-statement →
Grammar of a conditional compilation block
conditional-compilation-block → if-directive-clause opt else-directive-clause opt
if-directive-clause → if-directive statements opt
elseif-directive-clauses → elseif-directive-clauses opt
elseif-directive-clause → compilation-condition opt
else-directive-clause → else-directive opt
if-directive → #if
elseif-directive → #elseif
else-directive → #else
endif-directive → #endif
compilation-condition → platform-condition
compilation-condition →
compilation-condition → boolean-literal
compilation-condition → (
)
compilation-condition → !
compilation-condition
compilation-condition → &&
compilation-condition
compilation-condition → ||
compilation-condition
platform-condition → os
(
)
platform-condition → arch
(
architecture )
platform-condition → swift
(
>=
)
platform-condition → compiler
(
>=
swift-version )
platform-condition → canImport
(
)
platform-condition → targetEnvironment
(
environment )
operating-system → macOS
| iOS
| watchOS
| tvOS
architecture → i386
| x86_64
| arm
| arm64
swift-version → swift-version-continuation opt
swift-version-continuation → .
swift-version-continuation opt
module-name →
environment → simulator
Grammar of a line control statement
line-control-statement → #sourceLocation
(
file:
file-name ,
line:
)
line-control-statement → #sourceLocation
(
)
line-number → A decimal integer greater than zero
file-name → static-string-literal
Grammar of a compile-time diagnostic statement
diagnostic-statement → #error
(
)
diagnostic-statement → #warning
(
diagnostic-message )
diagnostic-message →
Grammar of an availability condition
availability-condition → #available
(
availability-arguments )
availability-arguments → | availability-argument ,
availability-argument → platform-name
availability-argument → *
platform-name → iOS
| iOSApplicationExtension
platform-name → macOS
| macOSApplicationExtension
platform-name → watchOS
platform-name → tvOS
platform-version → decimal-digits
platform-version → .
decimal-digits
platform-version → .
decimal-digits .
Grammar of a declaration
declaration → import-declaration
declaration →
declaration → variable-declaration
declaration →
declaration → function-declaration
declaration →
declaration → struct-declaration
declaration →
declaration → initializer-declaration
declaration →
declaration → extension-declaration
declaration →
declaration → operator-declaration
declaration →
declarations → declaration opt
Grammar of a top-level declaration
top-level-declaration → statements opt
Grammar of a code block
code-block → {
opt }
Grammar of an import declaration
import-declaration → attributes opt import
opt import-path
import-kind → typealias
| struct
| class
| enum
| protocol
| let
| var
| func
import-path → | import-path-identifier .
import-path-identifier → identifier |
Grammar of a constant declaration
constant-declaration → attributes opt opt pattern-initializer-list
pattern-initializer-list → | pattern-initializer ,
pattern-initializer → pattern opt
initializer → =
expression
Grammar of a variable declaration
variable-declaration → pattern-initializer-list
variable-declaration → variable-name code-block
variable-declaration → variable-name getter-setter-block
variable-declaration → variable-name getter-setter-keyword-block
variable-declaration → variable-name willSet-didSet-block
variable-declaration → variable-name initializer opt
variable-declaration-head → attributes opt opt var
variable-name → identifier
getter-setter-block →
getter-setter-block → {
getter-clause opt }
getter-setter-block → {
setter-clause }
getter-clause → attributes opt opt get
code-block
setter-clause → opt mutation-modifier opt set
opt code-block
setter-name → (
)
getter-setter-keyword-block → {
getter-keyword-clause opt }
getter-setter-keyword-block → {
setter-keyword-clause }
getter-keyword-clause → attributes opt opt get
setter-keyword-clause → attributes opt opt set
willSet-didSet-block → {
willSet-clause opt }
willSet-didSet-block → {
didSet-clause opt }
willSet-clause → attributes opt willSet
opt code-block
didSet-clause → opt didSet
setter-name opt
Grammar of a type alias declaration
typealias-declaration → attributes opt opt typealias
typealias-name opt typealias-assignment
typealias-name →
typealias-assignment → =
type
Grammar of a function declaration
function-declaration → function-name opt function-signature opt function-body opt
function-head → opt declaration-modifiers opt func
function-name → | operator
function-signature → throws
opt function-result opt
function-signature → rethrows
function-result opt
function-result → ->
opt type
function-body →
parameter-clause → (
)
| (
parameter-list )
parameter-list → | parameter ,
parameter → external-parameter-name opt type-annotation opt
parameter → external-parameter-name opt type-annotation
parameter → opt local-parameter-name ...
external-parameter-name → identifier
local-parameter-name →
default-argument-clause → =
expression
Grammar of an enumeration declaration
enum-declaration → opt access-level-modifier opt
enum-declaration → attributes opt opt raw-value-style-enum
union-style-enum → indirect
opt enum
generic-parameter-clause opt opt generic-where-clause opt {
opt }
union-style-enum-members → union-style-enum-member opt
union-style-enum-member → declaration | | compiler-control-statement
union-style-enum-case-clause → opt indirect
opt case
union-style-enum-case-list
union-style-enum-case-list → | union-style-enum-case ,
union-style-enum-case → enum-case-name opt
enum-name → identifier
enum-case-name →
raw-value-style-enum → enum
enum-name opt type-inheritance-clause opt {
raw-value-style-enum-members }
raw-value-style-enum-members → raw-value-style-enum-members opt
raw-value-style-enum-member → | raw-value-style-enum-case-clause |
raw-value-style-enum-case-clause → attributes opt case
raw-value-style-enum-case-list → raw-value-style-enum-case | ,
raw-value-style-enum-case-list
raw-value-style-enum-case → raw-value-assignment opt
raw-value-assignment → =
raw-value-literal → numeric-literal | | boolean-literal
Grammar of a structure declaration
struct-declaration → opt access-level-modifier opt struct
generic-parameter-clause opt opt generic-where-clause opt
struct-name → identifier
struct-body → {
opt }
struct-members → struct-member opt
struct-member → declaration |
Grammar of a class declaration
class-declaration → attributes opt opt final
opt class
class-name opt type-inheritance-clause opt opt class-body
class-declaration → opt final
access-level-modifier opt class
generic-parameter-clause opt opt generic-where-clause opt
class-name → identifier
class-body → {
opt }
class-members → class-member opt
class-member → declaration |
Grammar of a protocol declaration
protocol-declaration → attributes opt opt protocol
protocol-name opt generic-where-clause opt
protocol-name → identifier
protocol-body → {
opt }
protocol-members → protocol-member opt
protocol-member → protocol-member-declaration |
protocol-member-declaration → protocol-property-declaration
protocol-member-declaration →
protocol-member-declaration → protocol-initializer-declaration
protocol-member-declaration →
protocol-member-declaration → protocol-associated-type-declaration
protocol-member-declaration →
Grammar of a protocol property declaration
protocol-property-declaration → variable-declaration-head type-annotation
Grammar of a protocol method declaration
protocol-method-declaration → function-head generic-parameter-clause opt generic-where-clause opt
Grammar of a protocol initializer declaration
protocol-initializer-declaration → generic-parameter-clause opt throws
opt generic-where-clause opt
protocol-initializer-declaration → generic-parameter-clause opt rethrows
generic-where-clause opt
Grammar of a protocol subscript declaration
protocol-subscript-declaration → subscript-result opt getter-setter-keyword-block
Grammar of a protocol associated type declaration
protocol-associated-type-declaration → opt access-level-modifier opt associatedtype
type-inheritance-clause opt opt generic-where-clause opt
Grammar of an initializer declaration
initializer-declaration → generic-parameter-clause opt throws
opt generic-where-clause opt
initializer-declaration → initializer-head opt parameter-clause rethrows
opt initializer-body
initializer-head → opt declaration-modifiers opt init
initializer-head → opt declaration-modifiers opt init
?
initializer-head → opt declaration-modifiers opt init
!
initializer-body →
Grammar of a deinitializer declaration
deinitializer-declaration → attributes opt deinit
Grammar of an extension declaration
extension-declaration → attributes opt opt extension
type-identifier opt generic-where-clause opt
extension-body → {
extension-members opt }
extension-members → extension-members opt
extension-member → | compiler-control-statement
Grammar of a subscript declaration
subscript-declaration → subscript-result opt code-block
subscript-declaration → subscript-result opt getter-setter-block
subscript-declaration → subscript-result opt getter-setter-keyword-block
subscript-head → opt declaration-modifiers opt subscript
opt parameter-clause
subscript-result → ->
opt type
Grammar of an operator declaration
operator-declaration → | postfix-operator-declaration |
prefix-operator-declaration → prefix
operator
operator
postfix-operator-declaration → postfix
operator
infix-operator-declaration → infix
operator
operator opt
infix-operator-group → :
precedence-group-name
Grammar of a precedence group declaration
precedence-group-declaration → precedencegroup
{
precedence-group-attributes opt }
precedence-group-attributes → precedence-group-attributes opt
precedence-group-attribute →
precedence-group-attribute → precedence-group-assignment
precedence-group-attribute →
precedence-group-relation → higherThan
:
precedence-group-names
precedence-group-relation → lowerThan
:
precedence-group-assignment → assignment
:
boolean-literal
precedence-group-associativity → associativity
:
left
precedence-group-associativity → associativity
:
right
precedence-group-associativity → associativity
:
none
precedence-group-names → | precedence-group-name ,
precedence-group-name → identifier
Grammar of a declaration modifier
declaration-modifier → class
| convenience
| dynamic
| final
| infix
| lazy
| optional
| override
| postfix
| prefix
| required
| static
| unowned
| unowned
(
safe
)
| unowned
(
unsafe
)
| weak
declaration-modifier →
declaration-modifier → mutation-modifier
declaration-modifiers → declaration-modifiers opt
access-level-modifier → private
| private
(
set
)
access-level-modifier → fileprivate
| fileprivate
(
set
)
access-level-modifier → internal
| internal
(
set
)
access-level-modifier → public
| public
(
set
)
access-level-modifier → open
| open
(
set
)
mutation-modifier → mutating
| nonmutating
Attributes
Grammar of an attribute
attribute → @
attribute-name opt
attribute-name → identifier
attribute-argument-clause → (
opt )
attributes → attribute opt
balanced-tokens → balanced-token opt
balanced-token → (
balanced-tokens opt )
balanced-token → [
opt ]
balanced-token → {
balanced-tokens opt }
balanced-token → Any identifier, keyword, literal, or operator
balanced-token → Any punctuation except (
, )
, [
, ]
, {
, or }
Grammar of a pattern
pattern → type-annotation opt
pattern → type-annotation opt
pattern →
pattern → tuple-pattern opt
pattern → enum-case-pattern
pattern →
pattern → type-casting-pattern
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 → var
| let
pattern
Grammar of a tuple pattern
tuple-pattern → (
opt )
tuple-pattern-element-list → tuple-pattern-element | ,
tuple-pattern-element-list
tuple-pattern-element → | identifier :
Grammar of an enumeration case pattern
enum-case-pattern → type-identifier opt .
tuple-pattern opt
Grammar of an optional pattern
optional-pattern → ?
Grammar of a type casting pattern
type-casting-pattern → is-pattern |
is-pattern → is
type
as-pattern → as
type
Grammar of an expression pattern
expression-pattern →
Generic Parameters and Arguments
Grammar of a generic parameter clause
generic-parameter-clause → <
>
generic-parameter-list → generic-parameter | ,
generic-parameter-list
generic-parameter →
generic-parameter → type-name :
generic-parameter → type-name :
generic-where-clause → where
requirement-list
requirement-list → | requirement ,
requirement → conformance-requirement |
conformance-requirement → type-identifier :
conformance-requirement → type-identifier :
same-type-requirement → type-identifier ==
Grammar of a generic argument clause
generic-argument-clause → <
generic-argument-list
generic-argument →