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 →
identifier-list → identifier | ,
identifier-list
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-characters → identifier-character opt
implicit-parameter-name → $
decimal-digits
property-wrapper-projection → $
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
string-literal-opening-delimiter → opt "
string-literal-closing-delimiter → "
extended-string-literal-delimiter opt
static-string-literal → quoted-text opt
static-string-literal → multiline-string-literal-opening-delimiter opt multiline-string-literal-closing-delimiter
multiline-string-literal-opening-delimiter → """
multiline-string-literal-closing-delimiter → """
extended-string-literal-delimiter
extended-string-literal-delimiter → #
opt
quoted-text → quoted-text-item opt
quoted-text-item → escaped-character
quoted-text-item → Any Unicode scalar value except "
, \
, U+000A, or U+000D
multiline-quoted-text → multiline-quoted-text opt
multiline-quoted-text-item →
multiline-quoted-text-item → Any Unicode scalar value except \
multiline-quoted-text-item → escaped-newline
interpolated-string-literal → interpolated-text opt
interpolated-string-literal → multiline-string-literal-opening-delimiter opt multiline-string-literal-closing-delimiter
interpolated-text → interpolated-text opt
interpolated-text-item → \(
)
| quoted-text-item
multiline-interpolated-text → multiline-interpolated-text opt
multiline-interpolated-text-item → \(
)
| multiline-quoted-text-item
escape-sequence → \
escaped-character → escape-sequence 0
| \
| escape-sequence t
| n
| escape-sequence r
| "
| escape-sequence '
escaped-character → u
{
unicode-scalar-digits }
unicode-scalar-digits → Between one and eight hexadecimal digits
escaped-newline → whitespace opt
Grammar of operators
operator → operator-head opt
operator → dot-operator-head
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
operator-head → U+00B6, U+00BB, U+00BF, U+00D7, or U+00F7
operator-head → U+2016–U+2017
operator-head → 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
operator-head → U+3030
operator-character → operator-head
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-characters opt
dot-operator-head → .
dot-operator-character → .
|
dot-operator-characters → dot-operator-character opt
binary-operator → operator
prefix-operator →
postfix-operator → operator
Types
Grammar of a type
type → function-type
type →
type → dictionary-type
type →
type → tuple-type
type →
type → implicitly-unwrapped-optional-type
type →
type → opaque-type
type →
type → self-type
type → Any
type → (
)
Grammar of a type annotation
type-annotation → :
attributes opt inout
opt
Grammar of a type identifier
type-identifier → type-name opt | type-name opt .
type-identifier
type-name →
Grammar of a tuple type
tuple-type → (
)
| (
tuple-type-element ,
)
tuple-type-element-list → tuple-type-element | ,
tuple-type-element-list
tuple-type-element → type-annotation |
element-name → identifier
Grammar of a function type
function-type → opt function-type-argument-clause throws
opt ->
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 an opaque type
opaque-type → some
type
Grammar of a metatype type
metatype-type → .
Type
| type .
Protocol
Grammar of a Self type
self-type → Self
Grammar of a type inheritance clause
type-inheritance-clause → :
type-inheritance-list → type-identifier | ,
type-inheritance-list
Grammar of an expression
expression → opt prefix-expression opt
expression-list → expression | ,
expression-list
Grammar of a prefix expression
prefix-expression → opt postfix-expression
prefix-expression →
in-out-expression → &
identifier
Grammar of a try expression
try-operator → try
| try
?
| try
!
Grammar of a binary expression
binary-expression → prefix-expression
binary-expression → try-operator opt
binary-expression → conditional-operator opt prefix-expression
binary-expression →
binary-expressions → binary-expression opt
Grammar of an assignment operator
assignment-operator → =
Grammar of a conditional operator
conditional-operator → ?
expression :
Grammar of a type-casting operator
type-casting-operator → is
type-casting-operator → as
type
type-casting-operator → as
?
type-casting-operator → as
!
type
Grammar of a primary expression
primary-expression → generic-argument-clause opt
primary-expression →
primary-expression → self-expression
primary-expression →
primary-expression → closure-expression
primary-expression →
primary-expression → tuple-expression
primary-expression →
primary-expression → wildcard-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-items → ,
opt | dictionary-literal-item ,
dictionary-literal-item → expression :
playground-literal → #colorLiteral
(
red
:
expression ,
green
:
,
blue
:
expression ,
alpha
:
)
playground-literal → #fileLiteral
(
resourceName
:
expression )
playground-literal → #imageLiteral
(
resourceName
:
)
Grammar of a self expression
self-expression → self
| self-method-expression | | self-initializer-expression
self-method-expression → self
.
self-subscript-expression → self
[
function-call-argument-list ]
self-initializer-expression → self
.
init
Grammar of a superclass expression
superclass-expression → | superclass-subscript-expression |
superclass-method-expression → super
.
identifier
superclass-subscript-expression → super
[
]
superclass-initializer-expression → super
.
init
Grammar of a closure expression
closure-expression → {
closure-signature opt opt }
closure-signature → capture-list opt throws
opt function-result opt in
closure-signature → in
closure-parameter-clause → (
)
| (
closure-parameter-list )
|
closure-parameter-list → closure-parameter | ,
closure-parameter-list
closure-parameter → type-annotation opt
closure-parameter → type-annotation ...
closure-parameter-name →
capture-list → capture-list-items ]
capture-list-items → | capture-list-item ,
capture-list-item → capture-specifier opt
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 → (
)
Grammar of a tuple expression
tuple-expression → (
)
| (
tuple-element ,
)
tuple-element-list → tuple-element | ,
tuple-element-list
tuple-element → | identifier :
Grammar of a wildcard expression
wildcard-expression → _
Grammar of a key-path expression
key-path-expression → \
type opt .
key-path-components → key-path-component | .
key-path-components
key-path-component → key-path-postfixes opt |
key-path-postfixes → key-path-postfix opt
key-path-postfix → ?
| !
| self
| [
function-call-argument-list ]
Grammar of a selector expression
selector-expression → #selector
(
)
selector-expression → #selector
(
getter:
expression )
selector-expression → #selector
(
setter:
)
Grammar of a key-path string expression
key-path-string-expression → #keyPath
(
expression )
Grammar of a postfix expression
postfix-expression →
postfix-expression → postfix-expression
postfix-expression → function-call-expression
postfix-expression →
postfix-expression → explicit-member-expression
postfix-expression →
postfix-expression → subscript-expression
postfix-expression →
postfix-expression → optional-chaining-expression
Grammar of a function call expression
function-call-expression → function-call-argument-clause
function-call-expression → function-call-argument-clause opt
function-call-argument-clause → (
)
| (
function-call-argument-list )
function-call-argument-list → | function-call-argument ,
function-call-argument → expression | :
expression
function-call-argument → | identifier :
trailing-closure → closure-expression
Grammar of an initializer expression
initializer-expression → .
init
initializer-expression → postfix-expression .
init
(
)
Grammar of an explicit member expression
explicit-member-expression → postfix-expression .
explicit-member-expression → postfix-expression .
generic-argument-clause opt
explicit-member-expression → .
identifier (
)
argument-names → argument-name opt
argument-name → identifier :
Grammar of a postfix self expression
postfix-self-expression → .
self
Grammar of a subscript expression
subscript-expression → postfix-expression [
]
Grammar of a forced-value expression
forced-value-expression → postfix-expression !
Grammar of an optional-chaining expression
optional-chaining-expression → ?
Statements
Grammar of a statement
statement → ;
opt
statement → declaration ;
opt
statement → ;
opt
statement → branch-statement ;
opt
statement → ;
opt
statement → control-transfer-statement ;
opt
statement → ;
opt
statement → do-statement ;
opt
statement →
statements → statement opt
Grammar of a loop statement
loop-statement → for-in-statement
loop-statement →
loop-statement → repeat-while-statement
Grammar of a for-in statement
for-in-statement → for
case
opt in
expression opt code-block
Grammar of a while statement
while-statement → while
code-block
condition-list → | condition ,
condition → expression | | case-condition |
case-condition → case
pattern
optional-binding-condition → let
pattern | var
pattern
Grammar of a repeat-while statement
repeat-while-statement → repeat
code-block while
Grammar of a branch statement
branch-statement → if-statement
branch-statement →
branch-statement → switch-statement
Grammar of an if statement
if-statement → if
code-block opt
else-clause → else
code-block | else
Grammar of a guard statement
guard-statement → guard
condition-list else
Grammar of a switch statement
switch-statement → switch
expression {
opt }
switch-cases → switch-case opt
switch-case → case-label
switch-case → default-label
switch-case → conditional-switch-case
case-label → opt case
case-item-list :
case-item-list → where-clause opt | where-clause opt ,
default-label → attributes opt default
:
where-clause → where
where-expression → expression
conditional-switch-case → switch-elseif-directive-clauses opt opt endif-directive
switch-if-directive-clause → compilation-condition opt
switch-elseif-directive-clauses → elseif-directive-clause opt
switch-elseif-directive-clause → elseif-directive switch-cases opt
switch-else-directive-clause → switch-cases opt
Grammar of a labeled statement
labeled-statement → loop-statement
labeled-statement → if-statement
labeled-statement → switch-statement
labeled-statement → do-statement
statement-label → :
label-name → identifier
Grammar of a control transfer statement
control-transfer-statement →
control-transfer-statement → continue-statement
control-transfer-statement →
control-transfer-statement → return-statement
control-transfer-statement →
Grammar of a break statement
break-statement → break
label-name opt
Grammar of a continue statement
continue-statement → continue
opt
Grammar of a fallthrough statement
fallthrough-statement → fallthrough
Grammar of a return statement
return-statement → return
expression opt
Grammar of a throw statement
throw-statement → throw
Grammar of a defer statement
defer-statement → defer
code-block
Grammar of a do statement
do-statement → do
catch-clauses opt
catch-clauses → catch-clauses opt
catch-clause → catch
opt where-clause opt
Grammar of a compiler control statement
compiler-control-statement → conditional-compilation-block
compiler-control-statement →
compiler-control-statement → diagnostic-statement
Grammar of a conditional compilation block
conditional-compilation-block → elseif-directive-clauses opt opt endif-directive
if-directive-clause → compilation-condition opt
elseif-directive-clauses → elseif-directive-clause opt
elseif-directive-clause → elseif-directive statements opt
else-directive-clause → statements opt
if-directive → #if
elseif-directive → #elseif
else-directive → #else
endif-directive → #endif
compilation-condition →
compilation-condition → identifier
compilation-condition →
compilation-condition → (
compilation-condition )
compilation-condition → !
compilation-condition → compilation-condition &&
compilation-condition → compilation-condition ||
platform-condition → os
(
operating-system )
platform-condition → arch
(
)
platform-condition → swift
(
>=
swift-version )
| swift
(
<
)
platform-condition → compiler
(
>=
swift-version )
| compiler
(
<
)
platform-condition → canImport
(
module-name )
platform-condition → targetEnvironment
(
)
operating-system → macOS
| iOS
| watchOS
| tvOS
architecture → i386
| x86_64
| arm
| arm64
swift-version → decimal-digits opt
swift-version-continuation → .
decimal-digits opt
module-name → identifier
environment → simulator
Grammar of a line control statement
line-control-statement → #sourceLocation
(
file:
,
line:
line-number )
line-control-statement → #sourceLocation
(
)
line-number → A decimal integer greater than zero
file-name →
Grammar of a compile-time diagnostic statement
diagnostic-statement → #error
(
diagnostic-message )
diagnostic-statement → #warning
(
)
diagnostic-message → static-string-literal
Grammar of an availability condition
availability-condition → #available
(
)
availability-arguments → availability-argument | ,
availability-arguments
availability-argument → platform-version
availability-argument → *
platform-name → iOS
| iOSApplicationExtension
platform-name → macOS
| macOSApplicationExtension
platform-name → watchOS
platform-name → tvOS
platform-version →
platform-version → decimal-digits .
platform-version → decimal-digits .
.
decimal-digits
Grammar of a declaration
declaration →
declaration → constant-declaration
declaration →
declaration → function-declaration
declaration →
declaration → struct-declaration
declaration →
declaration → protocol-declaration
declaration →
declaration → deinitializer-declaration
declaration →
declaration → subscript-declaration
declaration →
declaration → precedence-group-declaration
declarations → declarations opt
Grammar of a top-level declaration
top-level-declaration → opt
Grammar of a code block
code-block → {
statements opt }
Grammar of an import declaration
import-declaration → opt import
import-kind opt
import-kind → typealias
| struct
| class
| enum
| protocol
| let
| var
|
import-path → import-path-identifier | .
import-path
import-path-identifier → | operator
Grammar of a constant declaration
constant-declaration → opt declaration-modifiers opt let
pattern-initializer-list → pattern-initializer | ,
pattern-initializer-list
pattern-initializer → initializer opt
initializer → =
Grammar of a variable declaration
variable-declaration → variable-declaration-head
variable-declaration → variable-declaration-head type-annotation
variable-declaration → variable-declaration-head type-annotation
variable-declaration → variable-declaration-head type-annotation
variable-declaration → variable-declaration-head initializer
variable-declaration → variable-declaration-head type-annotation opt willSet-didSet-block
variable-declaration-head → opt declaration-modifiers opt var
variable-name →
getter-setter-block → code-block
getter-setter-block → {
setter-clause opt }
getter-setter-block → {
getter-clause }
getter-clause → opt mutation-modifier opt get
setter-clause → attributes opt opt set
setter-name opt
setter-name → (
identifier )
getter-setter-keyword-block → {
setter-keyword-clause opt }
getter-setter-keyword-block → {
getter-keyword-clause }
getter-keyword-clause → opt mutation-modifier opt get
setter-keyword-clause → opt mutation-modifier opt set
willSet-didSet-block → {
didSet-clause opt }
willSet-didSet-block → {
willSet-clause opt }
willSet-clause → opt willSet
setter-name opt
didSet-clause → attributes opt didSet
opt code-block
Grammar of a type alias declaration
typealias-declaration → opt access-level-modifier opt typealias
generic-parameter-clause opt
typealias-name → identifier
typealias-assignment → =
Grammar of a function declaration
function-declaration → function-head generic-parameter-clause opt generic-where-clause opt opt
function-head → attributes opt opt func
function-name → identifier |
function-signature → parameter-clause throws
opt opt
function-signature → parameter-clause rethrows
opt
function-result → ->
attributes opt
function-body → code-block
parameter-clause → (
)
| (
)
parameter-list → parameter | ,
parameter-list
parameter → opt local-parameter-name default-argument-clause opt
parameter → opt local-parameter-name
parameter → external-parameter-name opt type-annotation ...
external-parameter-name →
local-parameter-name → identifier
default-argument-clause → =
Grammar of an enumeration declaration
enum-declaration → attributes opt opt union-style-enum
enum-declaration → opt access-level-modifier opt
union-style-enum → indirect
opt enum
enum-name opt type-inheritance-clause opt opt {
union-style-enum-members opt }
union-style-enum-members → union-style-enum-members opt
union-style-enum-member → | union-style-enum-case-clause |
union-style-enum-case-clause → attributes opt indirect
opt case
union-style-enum-case-list → union-style-enum-case | ,
union-style-enum-case-list
union-style-enum-case → tuple-type opt
enum-name →
enum-case-name → identifier
raw-value-style-enum → enum
generic-parameter-clause opt generic-where-clause opt {
}
raw-value-style-enum-members → raw-value-style-enum-member opt
raw-value-style-enum-member → declaration | | compiler-control-statement
raw-value-style-enum-case-clause → opt case
raw-value-style-enum-case-list
raw-value-style-enum-case-list → | raw-value-style-enum-case ,
raw-value-style-enum-case → enum-case-name opt
raw-value-assignment → =
raw-value-literal
raw-value-literal → | static-string-literal |
Grammar of a structure declaration
struct-declaration → attributes opt opt struct
struct-name opt type-inheritance-clause opt opt struct-body
struct-name →
struct-body → {
struct-members opt }
struct-members → struct-members opt
struct-member → | compiler-control-statement
Grammar of a class declaration
class-declaration → opt access-level-modifier opt final
opt class
generic-parameter-clause opt opt generic-where-clause opt
class-declaration → attributes opt final
opt class
class-name opt type-inheritance-clause opt opt class-body
class-name →
class-body → {
class-members opt }
class-members → class-members opt
class-member → | compiler-control-statement
Grammar of a protocol declaration
protocol-declaration → opt access-level-modifier opt protocol
type-inheritance-clause opt opt protocol-body
protocol-name →
protocol-body → {
protocol-members opt }
protocol-members → protocol-members opt
protocol-member → | compiler-control-statement
protocol-member-declaration →
protocol-member-declaration → protocol-method-declaration
protocol-member-declaration →
protocol-member-declaration → protocol-subscript-declaration
protocol-member-declaration →
protocol-member-declaration → typealias-declaration
Grammar of a protocol property declaration
protocol-property-declaration → variable-name getter-setter-keyword-block
Grammar of a protocol method declaration
protocol-method-declaration → function-name opt function-signature opt
Grammar of a protocol initializer declaration
protocol-initializer-declaration → initializer-head opt parameter-clause throws
opt opt
protocol-initializer-declaration → initializer-head opt parameter-clause rethrows
opt
Grammar of a protocol subscript declaration
protocol-subscript-declaration → subscript-head generic-where-clause opt
Grammar of a protocol associated type declaration
protocol-associated-type-declaration → attributes opt opt associatedtype
typealias-name opt typealias-assignment opt opt
Grammar of an initializer declaration
initializer-declaration → initializer-head opt parameter-clause throws
opt opt initializer-body
initializer-declaration → generic-parameter-clause opt rethrows
generic-where-clause opt
initializer-head → attributes opt opt init
initializer-head → attributes opt opt init
?
initializer-head → attributes opt opt init
!
initializer-body → code-block
Grammar of a deinitializer declaration
deinitializer-declaration → opt deinit
code-block
Grammar of an extension declaration
extension-declaration → opt access-level-modifier opt extension
type-inheritance-clause opt opt extension-body
extension-body → {
opt }
extension-members → extension-member opt
extension-member → declaration |
Grammar of a subscript declaration
subscript-declaration → subscript-head generic-where-clause opt
subscript-declaration → subscript-head generic-where-clause opt
subscript-declaration → subscript-head generic-where-clause opt
subscript-head → attributes opt opt subscript
generic-parameter-clause opt
subscript-result → ->
attributes opt
Grammar of an operator declaration
operator-declaration → prefix-operator-declaration | | infix-operator-declaration
prefix-operator-declaration → prefix
operator
postfix-operator-declaration → postfix
operator
operator
infix-operator-declaration → infix
operator
infix-operator-group opt
infix-operator-group → :
Grammar of a precedence group declaration
precedence-group-declaration → precedencegroup
precedence-group-name {
opt }
precedence-group-attributes → precedence-group-attribute opt
precedence-group-attribute → precedence-group-relation
precedence-group-attribute →
precedence-group-attribute → precedence-group-associativity
precedence-group-relation → higherThan
:
precedence-group-relation → lowerThan
:
precedence-group-names
precedence-group-assignment → assignment
:
precedence-group-associativity → associativity
:
left
precedence-group-associativity → associativity
:
right
precedence-group-associativity → associativity
:
none
precedence-group-names → precedence-group-name | ,
precedence-group-names
precedence-group-name →
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 → access-level-modifier
declaration-modifier →
declaration-modifiers → declaration-modifier 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-argument-clause opt
attribute-name →
attribute-argument-clause → (
balanced-tokens opt )
attributes → attributes opt
balanced-tokens → balanced-tokens opt
balanced-token → (
opt )
balanced-token → [
balanced-tokens opt ]
balanced-token → {
opt }
balanced-token → Any identifier, keyword, literal, or operator
balanced-token → Any punctuation except (
, )
, [
, ]
, {
, or }
Grammar of a pattern
pattern → wildcard-pattern opt
pattern → identifier-pattern opt
pattern → value-binding-pattern
pattern → type-annotation opt
pattern →
pattern → optional-pattern
pattern →
pattern → expression-pattern
Grammar of a wildcard pattern
wildcard-pattern → _
Grammar of an identifier pattern
identifier-pattern →
Grammar of a value-binding pattern
value-binding-pattern → var
pattern | let
Grammar of a tuple pattern
tuple-pattern → (
tuple-pattern-element-list opt )
tuple-pattern-element-list → | tuple-pattern-element ,
tuple-pattern-element → pattern | :
pattern
Grammar of an enumeration case pattern
enum-case-pattern → opt .
enum-case-name opt
Grammar of an optional pattern
optional-pattern → identifier-pattern ?
Grammar of a type casting pattern
type-casting-pattern → | as-pattern
is-pattern → is
as-pattern → pattern as
Grammar of an expression pattern
expression-pattern → expression
Generic Parameters and Arguments
Grammar of a generic parameter clause
generic-parameter-clause → <
generic-parameter-list >
generic-parameter-list → | generic-parameter ,
generic-parameter → type-name
generic-parameter → :
type-identifier
generic-parameter → :
protocol-composition-type
generic-where-clause → where
requirement-list → requirement | ,
requirement-list
requirement → | same-type-requirement
conformance-requirement → :
type-identifier
conformance-requirement → :
protocol-composition-type
same-type-requirement → ==
type
Grammar of a generic argument clause
generic-argument-clause → <
generic-argument → type