1 GRAMMAR OF WHITESPACE 2 3 whitespace → whitespace-item whitespace opt 4 5 whitespace-item → line-break 6 7 whitespace-item → comment 8 9 whitespace-item → multiline-comment10 11 whitespace-item → U+0000,U+0009,U+000B,U+000C,or U+002012 13 line-break → U+000A14 15 line-break → U+000D16 17 line-break → U+000D followed by U+000A18 19 comment → // comment-text line-break20 21 multiline-comment → /* multiline-comment-text */22 23 comment-text → comment-text-item comment-text opt24 25 comment-text-item → Any Unicode scalar value except U+000A or U+000D26 27 multiline-comment-text → multiline-comment-text-item multiline-comment-text opt28 29 multiline-comment-text-item → multiline-comment30 31 multiline-comment-text-item → comment-text-item32 33 multiline-comment-text-item → Any Unicode scalar value except /* or */
1 GRAMMAR OF AN IDENTIFIER 2 3 IDentifIEr → IDentifIEr-head IDentifIEr-characters opt 4 5 IDentifIEr → ` IDentifIEr-head IDentifIEr-characters opt ` 6 7 IDentifIEr → implicit-parameter-name 8 9 IDentifIEr-List → IDentifIEr | IDentifIEr,IDentifIEr-List10 11 IDentifIEr-head → Upper- or lowercase letter A through Z12 13 IDentifIEr-head → _14 15 IDentifIEr-head → U+00A8,U+00AA,U+00AD,U+00AF,U+00B2–U+00B5,or U+00B7–U+00BA16 17 IDentifIEr-head → U+00BC–U+00BE,U+00C0–U+00D6,U+00D8–U+00F6,or U+00F8–U+00FF18 19 IDentifIEr-head → U+0100–U+02FF,U+0370–U+167F,U+1681–U+180D,or U+180F–U+1DBF20 21 IDentifIEr-head → U+1E00–U+1FFF22 23 IDentifIEr-head → U+200B–U+200D,U+202A–U+202E,U+203F–U+2040,U+2054,or U+2060–U+206F24 25 IDentifIEr-head → U+2070–U+20CF,U+2100–U+218F,U+2460–U+24FF,or U+2776–U+279326 27 IDentifIEr-head → U+2C00–U+2DFF or U+2E80–U+2FFF28 29 IDentifIEr-head → U+3004–U+3007,U+3021–U+302F,U+3031–U+303F,or U+3040–U+D7FF30 31 IDentifIEr-head → U+F900–U+FD3D,U+FD40–U+FDCF,U+FDF0–U+FE1F,or U+FE30–U+FE4432 33 IDentifIEr-head → U+FE47–U+FFFD34 35 IDentifIEr-head → U+10000–U+1FFFD,U+20000–U+2FFFD,U+30000–U+3FFFD,or U+40000–U+4FFFD36 37 IDentifIEr-head → U+50000–U+5FFFD,U+60000–U+6FFFD,U+70000–U+7FFFD,or U+80000–U+8FFFD38 39 IDentifIEr-head → U+90000–U+9FFFD,U+A0000–U+AFFFD,U+B0000–U+BFFFD,or U+C0000–U+CFFFD40 41 IDentifIEr-head → U+D0000–U+DFFFD or U+E0000–U+EFFFD42 43 IDentifIEr-character → Digit 0 through 944 45 IDentifIEr-character → U+0300–U+036F,U+1DC0–U+1DFF,U+20D0–U+20FF,or U+FE20–U+FE2F46 47 IDentifIEr-character → IDentifIEr-head48 49 IDentifIEr-characters → IDentifIEr-character IDentifIEr-characters opt50 51 implicit-parameter-name → $ decimal-digits
1 GRAMMAR OF A literaL2 3 literal → numeric-literal | string-literal | boolean-literal | nil-literal4 5 numeric-literal → -opt integer-literal | -opt floating-point-literal6 7 boolean-literal → true | false8 9 nil-literal → nil
1 GRAMMAR OF AN INTEGER literaL 2 3 integer-literal → binary-literal 4 5 integer-literal → octal-literal 6 7 integer-literal → decimal-literal 8 9 integer-literal → hexadecimal-literal10 11 binary-literal → 0b binary-digit binary-literal-characters opt12 13 binary-digit → Digit 0 or 114 15 binary-literal-character → binary-digit | _16 17 binary-literal-characters → binary-literal-character binary-literal-characters opt18 19 octal-literal → 0o octal-digit octal-literal-characters opt20 21 octal-digit → Digit 0 through 722 23 octal-literal-character → octal-digit | _24 25 octal-literal-characters → octal-literal-character octal-literal-characters opt26 27 decimal-literal → decimal-digit decimal-literal-characters opt28 29 decimal-digit → Digit 0 through 930 31 decimal-digits → decimal-digit decimal-digits opt32 33 decimal-literal-character → decimal-digit | _34 35 decimal-literal-characters → decimal-literal-character decimal-literal-characters opt36 37 hexadecimal-literal → 0x hexadecimal-digit hexadecimal-literal-characters opt38 39 hexadecimal-digit → Digit 0 through 9,a through f,or A through F40 41 hexadecimal-literal-character → hexadecimal-digit | _42 43 hexadecimal-literal-characters → hexadecimal-literal-character hexadecimal-literal-characters opt
1 GRAMMAR OF A floatING-POINT literaL 2 3 floating-point-literal → decimal-literal decimal-fraction opt decimal-exponent opt 4 5 floating-point-literal → hexadecimal-literal hexadecimal-fraction opt hexadecimal-exponent 6 7 decimal-fraction → . decimal-literal 8 9 decimal-exponent → floating-point-e sign opt decimal-literal10 11 hexadecimal-fraction → . hexadecimal-digit hexadecimal-literal-characters opt12 13 hexadecimal-exponent → floating-point-p sign opt decimal-literal14 15 floating-point-e → e | E16 17 floating-point-p → p | P18 19 sign → + | -
1 GRAMMAR OF A STRING literaL 2 3 string-literal → static-string-literal | interpolated-string-literal 4 5 static-string-literal → " quoted-text opt " 6 7 static-string-literal → """ multiline-quoted-text opt """ 8 9 quoted-text → quoted-text-item quoted-text opt10 11 quoted-text-item → escaped-character12 13 quoted-text-item → Any Unicode scalar value except ",\,U+000A,or U+000D14 15 multiline-quoted-text → multiline-quoted-text-item multiline-quoted-text opt16 17 multiline-quoted-text-item → escaped-character18 19 multiline-quoted-text-item → Any Unicode scalar value except 20 21 multiline-quoted-text-item → escaped-newline22 23 interpolated-string-literal → " interpolated-text opt "24 25 interpolated-string-literal → """ multiline-interpolated-text opt """26 27 interpolated-text → interpolated-text-item interpolated-text opt28 29 interpolated-text-item → \( Expression ) | quoted-text-item30 31 multiline-interpolated-text → multiline-interpolated-text-item multiline-interpolated-text opt32 33 multiline-interpolated-text-item → \( Expression ) | multiline-quoted-text-item34 35 escaped-character → \0 | \\ | \t | \n | \r | \" | \‘36 37 escaped-character → \u { unicode-scalar-digits }38 39 unicode-scalar-digits → Between one and eight hexadecimal digits40 41 escaped-newline → \ whitespace opt line-break
1 GRAMMAR OF OPERATORS 2 3 operator → operator-head operator-characters opt 4 5 operator → dot-operator-head dot-operator-characters 6 7 operator-head → / | = | - | + | ! | * | % | < | > | & | | | ^ | ~ | ? 8 9 operator-head → U+00A1–U+00A710 11 operator-head → U+00A9 or U+00AB12 13 operator-head → U+00AC or U+00AE14 15 operator-head → U+00B0–U+00B1,U+00B6,U+00BB,U+00BF,U+00D7,or U+00F716 17 operator-head → U+2016–U+2017 or U+2020–U+202718 19 operator-head → U+2030–U+203E20 21 operator-head → U+2041–U+205322 23 operator-head → U+2055–U+205E24 25 operator-head → U+2190–U+23FF26 27 operator-head → U+2500–U+277528 29 operator-head → U+2794–U+2BFF30 31 operator-head → U+2E00–U+2E7F32 33 operator-head → U+3001–U+300334 35 operator-head → U+3008–U+3020 or U+303036 37 operator-character → operator-head38 39 operator-character → U+0300–U+036F40 41 operator-character → U+1DC0–U+1DFF42 43 operator-character → U+20D0–U+20FF44 45 operator-character → U+FE00–U+FE0F46 47 operator-character → U+FE20–U+FE2F48 49 operator-character → U+E0100–U+E01EF50 51 operator-characters → operator-character operator-characters opt52 53 dot-operator-head → .54 55 dot-operator-character → . | operator-character56 57 dot-operator-characters → dot-operator-character dot-operator-characters opt58 59 binary-operator → operator60 61 prefix-operator → operator62 63 postfix-operator → operator类型
1 GRAMMAR OF A TYPE 2 3 type → array-type 4 5 type → dictionary-type 6 7 type → function-type 8 9 type → type-IDentifIEr10 11 type → tuple-type12 13 type → optional-type14 15 type → implicitly-unwrapped-optional-type16 17 type → protocol-composition-type18 19 type → Metatype-type20 21 type → Any22 23 type → Self24 25 type → ( type )
1 GRAMMAR OF A TYPE ANNOTATION2 3 type-annotation → : attributes opt inoutopt type
1 GRAMMAR OF A TYPE IDENTIFIER2 3 type-IDentifIEr → type-name generic-argument-clause opt | type-name generic-argument-clause opt . type-IDentifIEr4 5 type-name → IDentifIEr
1 GRAMMAR OF A TUPLE TYPE2 3 tuple-type → ( ) | ( tuple-type-element,tuple-type-element-List )4 5 tuple-type-element-List → tuple-type-element | tuple-type-element,tuple-type-element-List6 7 tuple-type-element → element-name type-annotation | type8 9 element-name → IDentifIEr
1 GRAMMAR OF A FUNCTION TYPE 2 3 function-type → attributes opt function-type-argument-clause throwsopt -> type 4 5 function-type → attributes opt function-type-argument-clause rethrows -> type 6 7 function-type-argument-clause → ( ) 8 9 function-type-argument-clause → ( function-type-argument-List ...opt )10 11 function-type-argument-List → function-type-argument | function-type-argument,function-type-argument-List12 13 function-type-argument → attributes opt inoutopt type | argument-label type-annotation14 15 argument-label → IDentifIEr
1 GRAMMAR OF AN ARRAY TYPE2 3 array-type → [ type ]
1 GRAMMAR OF A DICTIONARY TYPE2 3 dictionary-type → [ type : type ]
1 GRAMMAR OF AN OPTIONAL TYPE2 3 optional-type → type ?
1 GRAMMAR OF AN IMPliCITLY UNWRAPPED OPTIONAL TYPE2 3 implicitly-unwrapped-optional-type → type !
1 GRAMMAR OF A PROTOCol COMposition TYPE2 3 protocol-composition-type → type-IDentifIEr & protocol-composition-continuation4 5 protocol-composition-continuation → type-IDentifIEr | protocol-composition-type
1 GRAMMAR OF A MetaTYPE TYPE2 3 Metatype-type → type . Type | type . Protocol
1 GRAMMAR OF A TYPE inheritANCE CLAUSE2 3 type-inheritance-clause → : type-inheritance-List4 5 type-inheritance-List → type-IDentifIEr | type-IDentifIEr,type-inheritance-List表达式
1 GRAMMAR OF AN Expression2 3 Expression → try-operator opt prefix-Expression binary-Expressions opt4 5 Expression-List → Expression | Expression,Expression-List
1 GRAMMAR OF A PREFIX Expression2 3 prefix-Expression → prefix-operator opt postfix-Expression4 5 prefix-Expression → in-out-Expression6 7 in-out-Expression → & IDentifIEr
1 GRAMMAR OF A TRY Expression2 3 try-operator → try | try ? | try !
1 GRAMMAR OF A BINARY Expression 2 3 binary-Expression → binary-operator prefix-Expression 4 5 binary-Expression → assignment-operator try-operator opt prefix-Expression 6 7 binary-Expression → conditional-operator try-operator opt prefix-Expression 8 9 binary-Expression → type-casting-operator10 11 binary-Expressions → binary-Expression binary-Expressions opt
1 GRAMMAR OF AN ASSIgnmENT OPERATOR2 3 assignment-operator → =
1 GRAMMAR OF A CONDITIONAL OPERATOR2 3 conditional-operator → ? Expression :
1 GRAMMAR OF A TYPE-CASTING OPERATOR2 3 type-casting-operator → is type4 5 type-casting-operator → as type6 7 type-casting-operator → as ? type8 9 type-casting-operator → as ! type
1 GRAMMAR OF A PRIMARY Expression 2 3 primary-Expression → IDentifIEr generic-argument-clause opt 4 5 primary-Expression → literal-Expression 6 7 primary-Expression → self-Expression 8 9 primary-Expression → superclass-Expression10 11 primary-Expression → closure-Expression12 13 primary-Expression → parenthesized-Expression14 15 primary-Expression → tuple-Expression16 17 primary-Expression → implicit-member-Expression18 19 primary-Expression → wildcard-Expression20 21 primary-Expression → key-path-Expression22 23 primary-Expression → selector-Expression24 25 primary-Expression → key-path-string-Expression
1 GRAMMAR OF A literaL Expression 2 3 literal-Expression → literal 4 5 literal-Expression → array-literal | dictionary-literal | playground-literal 6 7 literal-Expression → #file | #line | #column | #function | #dsohandle 8 9 array-literal → [ array-literal-items opt ]10 11 array-literal-items → array-literal-item,opt | array-literal-item,array-literal-items12 13 array-literal-item → Expression14 15 dictionary-literal → [ dictionary-literal-items ] | [ : ]16 17 dictionary-literal-items → dictionary-literal-item,opt | dictionary-literal-item,dictionary-literal-items18 19 dictionary-literal-item → Expression : Expression20 21 playground-literal → #colorliteral ( red : Expression,green : Expression,blue : Expression,Alpha : Expression )22 23 playground-literal → #fileliteral ( resourcename : Expression )24 25 playground-literal → #imageliteral ( resourcename : Expression )
1 GRAMMAR OF A SELF Expression2 3 self-Expression → self | self-method-Expression | self-subscript-Expression | self-initializer-Expression4 5 self-method-Expression → self . IDentifIEr6 7 self-subscript-Expression → self [ function-call-argument-List ]8 9 self-initializer-Expression → self . init
1 GRAMMAR OF A SUPERCLASS Expression2 3 superclass-Expression → superclass-method-Expression | superclass-subscript-Expression | superclass-initializer-Expression4 5 superclass-method-Expression → super . IDentifIEr6 7 superclass-subscript-Expression → super [ function-call-argument-List ]8 9 superclass-initializer-Expression → super . init
1 GRAMMAR OF A CLOSURE Expression 2 3 closure-Expression → { closure-signature opt statements opt } 4 5 closure-signature → capture-List opt closure-parameter-clause throwsopt function-result opt in 6 7 closure-signature → capture-List in 8 9 closure-parameter-clause → ( ) | ( closure-parameter-list ) | IDentifIEr-List10 11 closure-parameter-list → closure-parameter | closure-parameter,closure-parameter-List12 13 closure-parameter → closure-parameter-name type-annotation opt14 15 closure-parameter → closure-parameter-name type-annotation ...16 17 closure-parameter-name → IDentifIEr18 19 capture-List → [ capture-List-items ]20 21 capture-List-items → capture-List-item | capture-List-item,capture-List-items22 23 capture-List-item → capture-specifIEr opt Expression24 25 capture-specifIEr → weak | uNowned | uNowned(safe) | uNowned(unsafe)
1 GRAMMAR OF A IMPliCIT MEMBER Expression2 3 implicit-member-Expression → . IDentifIEr
1 GRAMMAR OF A PARENTHESIZED Expression2 3 parenthesized-Expression → ( Expression )
1 GRAMMAR OF A TUPLE Expression2 3 tuple-Expression → ( ) | ( tuple-element,tuple-element-List )4 5 tuple-element-List → tuple-element | tuple-element,tuple-element-List6 7 tuple-element → Expression | IDentifIEr : Expression
1 GRAMMAR OF A WILDCARD Expression2 3 wildcard-Expression → _
1 GRAMMAR OF A KEY-PATH Expression 2 3 key-path-Expression → \ type opt . key-path-components 4 5 key-path-components → key-path-component | key-path-component . key-path-components 6 7 key-path-component → IDentifIEr key-path-postfixes opt | key-path-postfixes 8 9 key-path-postfixes → key-path-postfix key-path-postfixes opt10 11 key-path-postfix → ? | ! | [ function-call-argument-List ]
1 GRAMMAR OF A SELECTOR Expression2 3 selector-Expression → #selector ( Expression )4 5 selector-Expression → #selector ( getter: Expression )6 7 selector-Expression → #selector ( setter: Expression )
1 GRAMMAR OF A KEY-PATH STRING Expression2 3 key-path-string-Expression → #keyPath ( Expression )
1 GRAMMAR OF A POSTFIX Expression 2 3 postfix-Expression → primary-Expression 4 5 postfix-Expression → postfix-Expression postfix-operator 6 7 postfix-Expression → function-call-Expression 8 9 postfix-Expression → initializer-Expression10 11 postfix-Expression → explicit-member-Expression12 13 postfix-Expression → postfix-self-Expression14 15 postfix-Expression → subscript-Expression16 17 postfix-Expression → forced-value-Expression18 19 postfix-Expression → optional-chaining-Expression
1 GRAMMAR OF A FUNCTION CALL Expression 2 3 function-call-Expression → postfix-Expression function-call-argument-clause 4 5 function-call-Expression → postfix-Expression function-call-argument-clause opt trailing-closure 6 7 function-call-argument-clause → ( ) | ( function-call-argument-List ) 8 9 function-call-argument-List → function-call-argument | function-call-argument,function-call-argument-List10 11 function-call-argument → Expression | IDentifIEr : Expression12 13 function-call-argument → operator | IDentifIEr : operator14 15 trailing-closure → closure-Expression
1 GRAMMAR OF AN INITIAliZER Expression2 3 initializer-Expression → postfix-Expression . init4 5 initializer-Expression → postfix-Expression . init ( argument-names )
1 GRAMMAR OF AN EXPliCIT MEMBER Expression 2 3 explicit-member-Expression → postfix-Expression . decimal-digits 4 5 explicit-member-Expression → postfix-Expression . IDentifIEr generic-argument-clause opt 6 7 explicit-member-Expression → postfix-Expression . IDentifIEr ( argument-names ) 8 9 argument-names → argument-name argument-names opt10 11 argument-name → IDentifIEr :
1 GRAMMAR OF A SELF Expression2 3 postfix-self-Expression → postfix-Expression . self
1 GRAMMAR OF A SUBSCRIPT Expression2 3 subscript-Expression → postfix-Expression [ function-call-argument-List ]
1 GRAMMAR OF A FORCED-VALUE Expression2 3 forced-value-Expression → postfix-Expression !
1 GRAMMAR OF AN OPTIONAL-CHAINING Expression2 3 optional-chaining-Expression → postfix-Expression ?语句
1 GRAMMAR OF A STATEMENT 2 3 statement → Expression ;opt 4 5 statement → declaration ;opt 6 7 statement → loop-statement ;opt 8 9 statement → branch-statement ;opt10 11 statement → labeled-statement ;opt12 13 statement → control-transfer-statement ;opt14 15 statement → defer-statement ;opt16 17 statement → do-statement ;opt18 19 statement → compiler-control-statement20 21 statements → statement statements opt
1 GRAMMAR OF A LOOP STATEMENT2 3 loop-statement → for-in-statement4 5 loop-statement → while-statement6 7 loop-statement → repeat-while-statement
1 GRAMMAR OF A FOR-IN STATEMENT2 3 for-in-statement → for caSEOpt pattern in Expression where-clause opt code-block
1 GRAMMAR OF A WHILE STATEMENT 2 3 while-statement → while condition-List code-block 4 5 condition-List → condition | condition,condition-List 6 7 condition → Expression | availability-condition | case-condition | optional-binding-condition 8 9 case-condition → case pattern initializer10 11 optional-binding-condition → let pattern initializer | var pattern initializer
1 GRAMMAR OF A REPEAT-WHILE STATEMENT2 3 repeat-while-statement → repeat code-block while Expression
1 GRAMMAR OF A BRANCH STATEMENT2 3 branch-statement → if-statement4 5 branch-statement → guard-statement6 7 branch-statement → switch-statement
1 GRAMMAR OF AN IF STATEMENT2 3 if-statement → if condition-List code-block else-clause opt4 5 else-clause → else code-block | else if-statement
1 GRAMMAR OF A GUARD STATEMENT2 3 guard-statement → guard condition-List else code-block
1 GRAMMAR OF A SWITCH STATEMENT 2 3 switch-statement → switch Expression { switch-cases opt } 4 5 switch-cases → switch-case switch-cases opt 6 7 switch-case → case-label statements 8 9 switch-case → default-label statements10 11 switch-case → conditional-switch-case12 13 case-label → case case-item-List :14 15 case-item-List → pattern where-clause opt | pattern where-clause opt,case-item-List16 17 default-label → default :18 19 where-clause → where where-Expression20 21 where-Expression → Expression22 23 conditional-switch-case → switch-if-directive-clause switch-elseif-directive-clauses opt switch-else-directive-clause opt endif-directive24 25 switch-if-directive-clause → if-directive compilation-condition switch-cases opt26 27 switch-elseif-directive-clauses → elseif-directive-clause switch-elseif-directive-clauses opt28 29 switch-elseif-directive-clause → elseif-directive compilation-condition switch-cases opt30 31 switch-else-directive-clause → else-directive switch-cases opt
1 GRAMMAR OF A LABELED STATEMENT 2 3 labeled-statement → statement-label loop-statement 4 5 labeled-statement → statement-label if-statement 6 7 labeled-statement → statement-label switch-statement 8 9 labeled-statement → statement-label do-statement10 11 statement-label → label-name :12 13 label-name → IDentifIEr
1 GRAMMAR OF A CONTRol TRANSFER STATEMENT 2 3 control-transfer-statement → break-statement 4 5 control-transfer-statement → continue-statement 6 7 control-transfer-statement → fallthrough-statement 8 9 control-transfer-statement → return-statement10 11 control-transfer-statement → throw-statement
1 GRAMMAR OF A BREAK STATEMENT2 3 break-statement → break label-name opt
1 GRAMMAR OF A CONTINUE STATEMENT2 3 continue-statement → continue label-name opt
1 GRAMMAR OF A FALLTHROUGH STATEMENT2 3 fallthrough-statement → fallthrough
1 GRAMMAR OF A RETURN STATEMENT2 3 return-statement → return Expression opt
1 GRAMMAR OF A THROW STATEMENT2 3 throw-statement → throw Expression
1 GRAMMAR OF A DEFER STATEMENT2 3 defer-statement → defer code-block
1 GRAMMAR OF A DO STATEMENT2 3 do-statement → do code-block catch-clauses opt4 5 catch-clauses → catch-clause catch-clauses opt6 7 catch-clause → catch pattern opt where-clause opt code-block
1 GRAMMAR OF A COMPILER CONTRol STATEMENT2 3 compiler-control-statement → conditional-compilation-block4 5 compiler-control-statement → line-control-statement6 7 compiler-control-statement → diagnostic-statement
1 GRAMMAR OF A CONDITIONAL COMPILATION BLOCK 2 3 conditional-compilation-block → if-directive-clause elseif-directive-clauses opt else-directive-clause opt endif-directive 4 5 if-directive-clause → if-directive compilation-condition statements opt 6 7 elseif-directive-clauses → elseif-directive-clause elseif-directive-clauses opt 8 9 elseif-directive-clause → elseif-directive compilation-condition statements opt10 11 else-directive-clause → else-directive statements opt12 13 if-directive → #if14 15 elseif-directive → #elseif16 17 else-directive → #else18 19 endif-directive → #endif20 21 compilation-condition → platform-condition22 23 compilation-condition → IDentifIEr24 25 compilation-condition → boolean-literal26 27 compilation-condition → ( compilation-condition )28 29 compilation-condition → ! compilation-condition30 31 compilation-condition → compilation-condition && compilation-condition32 33 compilation-condition → compilation-condition || compilation-condition34 35 platform-condition → os ( operating-system )36 37 platform-condition → arch ( architecture )38 39 platform-condition → swift ( >= swift-version )40 41 platform-condition → compiler ( >= swift-version )42 43 platform-condition → canimport ( module-name )44 45 platform-condition → targetEnvironment ( environment )46 47 operating-system → macOS | iOS | watchOS | tvOS48 49 architecture → i386 | x86_64 | arm | arm6450 51 swift-version → decimal-digits swift-version-continuation opt52 53 swift-version-continuation → . decimal-digits swift-version-continuation opt54 55 module-name → IDentifIEr56 57 environment → simulator
1 GRAMMAR OF A liNE CONTRol STATEMENT2 3 line-control-statement → #sourceLocation ( file: file-name,line: line-number )4 5 line-control-statement → #sourceLocation ( )6 7 line-number → A decimal integer greater than zero8 9 file-name → static-string-literal
1 GRAMMAR OF A COMPILE-TIME DIAGNOSTIC STATEMENT2 3 diagnostic-statement → #error ( diagnostic-message )4 5 diagnostic-statement → #warning ( diagnostic-message )6 7 diagnostic-message → static-string-literal
1 GRAMMAR OF AN AVAILABIliTY CONDITION 2 3 availability-condition → #available ( availability-arguments ) 4 5 availability-arguments → availability-argument | availability-argument,availability-arguments 6 7 availability-argument → platform-name platform-version 8 9 availability-argument → *10 11 platform-name → iOS | iOSApplicationExtension12 13 platform-name → macOS | macOSApplicationExtension14 15 platform-name → watchOS16 17 platform-name → tvOS18 19 platform-version → decimal-digits20 21 platform-version → decimal-digits . decimal-digits22 23 platform-version → decimal-digits . decimal-digits . decimal-digits声明
1 GRAMMAR OF A DECLaraTION 2 3 declaration → import-declaration 4 5 declaration → constant-declaration 6 7 declaration → variable-declaration 8 9 declaration → typealias-declaration10 11 declaration → function-declaration12 13 declaration → enum-declaration14 15 declaration → struct-declaration16 17 declaration → class-declaration18 19 declaration → protocol-declaration20 21 declaration → initializer-declaration22 23 declaration → deinitializer-declaration24 25 declaration → extension-declaration26 27 declaration → subscript-declaration28 29 declaration → operator-declaration30 31 declaration → precedence-group-declaration32 33 declarations → declaration declarations opt
1 GRAMMAR OF A top-LEVEL DECLaraTION2 3 top-level-declaration → statements opt
1 GRAMMAR OF A CODE BLOCK2 3 code-block → { statements opt }
1 GRAMMAR OF AN import DECLaraTION2 3 import-declaration → attributes opt import import-kind opt import-path4 5 import-kind → typealias | struct | class | enum | protocol | let | var | func6 7 import-path → import-path-IDentifIEr | import-path-IDentifIEr . import-path8 9 import-path-IDentifIEr → IDentifIEr | operator
1 GRAMMAR OF A CONSTANT DECLaraTION2 3 constant-declaration → attributes opt declaration-modifIErs opt let pattern-initializer-List4 5 pattern-initializer-List → pattern-initializer | pattern-initializer,pattern-initializer-List6 7 pattern-initializer → pattern initializer opt8 9 initializer → = Expression
1 GRAMMAR OF A VARIABLE DECLaraTION 2 3 variable-declaration → variable-declaration-head pattern-initializer-List 4 5 variable-declaration → variable-declaration-head variable-name type-annotation code-block 6 7 variable-declaration → variable-declaration-head variable-name type-annotation getter-setter-block 8 9 variable-declaration → variable-declaration-head variable-name type-annotation getter-setter-keyword-block10 11 variable-declaration → variable-declaration-head variable-name initializer willSet-dIDSet-block12 13 variable-declaration → variable-declaration-head variable-name type-annotation initializer opt willSet-dIDSet-block14 15 variable-declaration-head → attributes opt declaration-modifIErs opt var16 17 variable-name → IDentifIEr18 19 getter-setter-block → code-block20 21 getter-setter-block → { getter-clause setter-clause opt }22 23 getter-setter-block → { setter-clause getter-clause }24 25 getter-clause → attributes opt mutation-modifIEr opt get code-block26 27 setter-clause → attributes opt mutation-modifIEr opt set setter-name opt code-block28 29 setter-name → ( IDentifIEr )30 31 getter-setter-keyword-block → { getter-keyword-clause setter-keyword-clause opt }32 33 getter-setter-keyword-block → { setter-keyword-clause getter-keyword-clause }34 35 getter-keyword-clause → attributes opt mutation-modifIEr opt get36 37 setter-keyword-clause → attributes opt mutation-modifIEr opt set38 39 willSet-dIDSet-block → { willSet-clause dIDSet-clause opt }40 41 willSet-dIDSet-block → { dIDSet-clause willSet-clause opt }42 43 willSet-clause → attributes opt willSet setter-name opt code-block44 45 dIDSet-clause → attributes opt dIDSet setter-name opt code-block
1 GRAMMAR OF A TYPE AliAS DECLaraTION2 3 typealias-declaration → attributes opt access-level-modifIEr opt typealias typealias-name generic-parameter-clause opt typealias-assignment4 5 typealias-name → IDentifIEr6 7 typealias-assignment → = type
1 GRAMMAR OF A FUNCTION DECLaraTION 2 3 function-declaration → function-head function-name generic-parameter-clause opt function-signature generic-where-clause opt function-body opt 4 5 function-head → attributes opt declaration-modifIErs opt func 6 7 function-name → IDentifIEr | operator 8 9 function-signature → parameter-clause throwsopt function-result opt10 11 function-signature → parameter-clause rethrows function-result opt12 13 function-result → -> attributes opt type14 15 function-body → code-block16 17 parameter-clause → ( ) | ( parameter-List )18 19 parameter-list → parameter | parameter,parameter-List20 21 parameter → external-parameter-name opt local-parameter-name type-annotation default-argument-clause opt22 23 parameter → external-parameter-name opt local-parameter-name type-annotation24 25 parameter → external-parameter-name opt local-parameter-name type-annotation ...26 27 external-parameter-name → IDentifIEr28 29 local-parameter-name → IDentifIEr30 31 default-argument-clause → = Expression
1 GRAMMAR OF AN ENUMERATION DECLaraTION 2 3 enum-declaration → attributes opt access-level-modifIEr opt union-style-enum 4 5 enum-declaration → attributes opt access-level-modifIEr opt raw-value-style-enum 6 7 union-style-enum → indirectopt enum enum-name generic-parameter-clause opt type-inheritance-clause opt generic-where-clause opt { union-style-enum-members opt } 8 9 union-style-enum-members → union-style-enum-member union-style-enum-members opt10 11 union-style-enum-member → declaration | union-style-enum-case-clause | compiler-control-statement12 13 union-style-enum-case-clause → attributes opt indirectopt case union-style-enum-case-List14 15 union-style-enum-case-List → union-style-enum-case | union-style-enum-case,union-style-enum-case-List16 17 union-style-enum-case → enum-case-name tuple-type opt18 19 enum-name → IDentifIEr20 21 enum-case-name → IDentifIEr22 23 raw-value-style-enum → enum enum-name generic-parameter-clause opt type-inheritance-clause generic-where-clause opt { raw-value-style-enum-members }24 25 raw-value-style-enum-members → raw-value-style-enum-member raw-value-style-enum-members opt26 27 raw-value-style-enum-member → declaration | raw-value-style-enum-case-clause | compiler-control-statement28 29 raw-value-style-enum-case-clause → attributes opt case raw-value-style-enum-case-List30 31 raw-value-style-enum-case-List → raw-value-style-enum-case | raw-value-style-enum-case,raw-value-style-enum-case-List32 33 raw-value-style-enum-case → enum-case-name raw-value-assignment opt34 35 raw-value-assignment → = raw-value-literal36 37 raw-value-literal → numeric-literal | static-string-literal | boolean-literal
1 GRAMMAR OF A STRUCTURE DECLaraTION 2 3 struct-declaration → attributes opt access-level-modifIEr opt struct struct-name generic-parameter-clause opt type-inheritance-clause opt generic-where-clause opt struct-body 4 5 struct-name → IDentifIEr 6 7 struct-body → { struct-members opt } 8 9 struct-members → struct-member struct-members opt10 11 struct-member → declaration | compiler-control-statement
1 GRAMMAR OF A CLASS DECLaraTION 2 3 class-declaration → attributes opt access-level-modifIEr opt finalopt class class-name generic-parameter-clause opt type-inheritance-clause opt generic-where-clause opt class-body 4 5 class-declaration → attributes opt final access-level-modifIEr opt class class-name generic-parameter-clause opt type-inheritance-clause opt generic-where-clause opt class-body 6 7 class-name → IDentifIEr 8 9 class-body → { class-members opt }10 11 class-members → class-member class-members opt12 13 class-member → declaration | compiler-control-statement
1 GRAMMAR OF A PROTOCol DECLaraTION 2 3 protocol-declaration → attributes opt access-level-modifIEr opt protocol protocol-name type-inheritance-clause opt generic-where-clause opt protocol-body 4 5 protocol-name → IDentifIEr 6 7 protocol-body → { protocol-members opt } 8 9 protocol-members → protocol-member protocol-members opt10 11 protocol-member → protocol-member-declaration | compiler-control-statement12 13 protocol-member-declaration → protocol-property-declaration14 15 protocol-member-declaration → protocol-method-declaration16 17 protocol-member-declaration → protocol-initializer-declaration18 19 protocol-member-declaration → protocol-subscript-declaration20 21 protocol-member-declaration → protocol-associated-type-declaration22 23 protocol-member-declaration → typealias-declaration
1 GRAMMAR OF A PROTOCol PROPERTY DECLaraTION2 3 protocol-property-declaration → variable-declaration-head variable-name type-annotation getter-setter-keyword-block
1 GRAMMAR OF A PROTOCol METHOD DECLaraTION2 3 protocol-method-declaration → function-head function-name generic-parameter-clause opt function-signature generic-where-clause opt
1 GRAMMAR OF A PROTOCol INITIAliZER DECLaraTION2 3 protocol-initializer-declaration → initializer-head generic-parameter-clause opt parameter-clause throwsopt generic-where-clause opt4 5 protocol-initializer-declaration → initializer-head generic-parameter-clause opt parameter-clause rethrows generic-where-clause opt
1 GRAMMAR OF A PROTOCol SUBSCRIPT DECLaraTION2 3 protocol-subscript-declaration → subscript-head subscript-result generic-where-clause opt getter-setter-keyword-block
1 GRAMMAR OF A PROTOCol ASSOCIATED TYPE DECLaraTION2 3 protocol-associated-type-declaration → attributes opt access-level-modifIEr opt associatedtype typealias-name type-inheritance-clause opt typealias-assignment opt generic-where-clause opt
1 GRAMMAR OF AN INITIAliZER DECLaraTION 2 3 initializer-declaration → initializer-head generic-parameter-clause opt parameter-clause throwsopt generic-where-clause opt initializer-body 4 5 initializer-declaration → initializer-head generic-parameter-clause opt parameter-clause rethrows generic-where-clause opt initializer-body 6 7 initializer-head → attributes opt declaration-modifIErs opt init 8 9 initializer-head → attributes opt declaration-modifIErs opt init ?10 11 initializer-head → attributes opt declaration-modifIErs opt init !12 13 initializer-body → code-block
1 GRAMMAR OF A DEINITIAliZER DECLaraTION2 3 deinitializer-declaration → attributes opt deinit code-block
1 GRAMMAR OF AN EXTENSION DECLaraTION2 3 extension-declaration → attributes opt access-level-modifIEr opt extension type-IDentifIEr type-inheritance-clause opt generic-where-clause opt extension-body4 5 extension-body → { extension-members opt }6 7 extension-members → extension-member extension-members opt8 9 extension-member → declaration | compiler-control-statement
1 GRAMMAR OF A SUBSCRIPT DECLaraTION 2 3 subscript-declaration → subscript-head subscript-result generic-where-clause opt code-block 4 5 subscript-declaration → subscript-head subscript-result generic-where-clause opt getter-setter-block 6 7 subscript-declaration → subscript-head subscript-result generic-where-clause opt getter-setter-keyword-block 8 9 subscript-head → attributes opt declaration-modifIErs opt subscript generic-parameter-clause opt parameter-clause10 11 subscript-result → -> attributes opt type
1 GRAMMAR OF AN OPERATOR DECLaraTION 2 3 operator-declaration → prefix-operator-declaration | postfix-operator-declaration | infix-operator-declaration 4 5 prefix-operator-declaration → prefix operator operator 6 7 postfix-operator-declaration → postfix operator operator 8 9 infix-operator-declaration → infix operator operator infix-operator-group opt10 11 infix-operator-group → : precedence-group-name
1 GRAMMAR OF A PRECEDENCE GROUP DECLaraTION 2 3 precedence-group-declaration → precedencegroup precedence-group-name { precedence-group-attributes opt } 4 5 precedence-group-attributes → precedence-group-attribute precedence-group-attributes opt 6 7 precedence-group-attribute → precedence-group-relation 8 9 precedence-group-attribute → precedence-group-assignment10 11 precedence-group-attribute → precedence-group-associativity12 13 precedence-group-relation → higherThan : precedence-group-names14 15 precedence-group-relation → lowerThan : precedence-group-names16 17 precedence-group-assignment → assignment : boolean-literal18 19 precedence-group-associativity → associativity : left20 21 precedence-group-associativity → associativity : right22 23 precedence-group-associativity → associativity : none24 25 precedence-group-names → precedence-group-name | precedence-group-name,precedence-group-names26 27 precedence-group-name → IDentifIEr
1 GRAMMAR OF A DECLaraTION MODIFIER 2 3 declaration-modifIEr → class | convenIEnce | dynamic | final | infix | lazy | optional | overrIDe | postfix | prefix | required | static | uNowned | uNowned ( safe ) | uNowned ( unsafe ) | weak 4 5 declaration-modifIEr → access-level-modifIEr 6 7 declaration-modifIEr → mutation-modifIEr 8 9 declaration-modifIErs → declaration-modifIEr declaration-modifIErs opt10 11 access-level-modifIEr → private | private ( set )12 13 access-level-modifIEr → fileprivate | fileprivate ( set )14 15 access-level-modifIEr → internal | internal ( set )16 17 access-level-modifIEr → public | public ( set )18 19 access-level-modifIEr → open | open ( set )20 21 mutation-modifIEr → mutating | nonmutating属性
1 GRAMMAR OF AN ATTRIBUTE 2 3 attribute → @ attribute-name attribute-argument-clause opt 4 5 attribute-name → IDentifIEr 6 7 attribute-argument-clause → ( balanced-tokens opt ) 8 9 attributes → attribute attributes opt10 11 balanced-tokens → balanced-token balanced-tokens opt12 13 balanced-token → ( balanced-tokens opt )14 15 balanced-token → [ balanced-tokens opt ]16 17 balanced-token → { balanced-tokens opt }18 19 balanced-token → Any IDentifIEr,keyword,literal,or operator20 21 balanced-token → Any punctuation except (,),[,],{,or }模式
1 GRAMMAR OF A PATTERN 2 3 pattern → wildcard-pattern type-annotation opt 4 5 pattern → IDentifIEr-pattern type-annotation opt 6 7 pattern → value-binding-pattern 8 9 pattern → tuple-pattern type-annotation opt10 11 pattern → enum-case-pattern12 13 pattern → optional-pattern14 15 pattern → type-casting-pattern16 17 pattern → Expression-pattern
1 GRAMMAR OF A WILDCARD PATTERN2 3 wildcard-pattern → _
1 GRAMMAR OF AN IDENTIFIER PATTERN2 3 IDentifIEr-pattern → IDentifIEr
1 GRAMMAR OF A VALUE-BINDING PATTERN2 3 value-binding-pattern → var pattern | let pattern
1 GRAMMAR OF A TUPLE PATTERN2 3 tuple-pattern → ( tuple-pattern-element-List opt )4 5 tuple-pattern-element-List → tuple-pattern-element | tuple-pattern-element,tuple-pattern-element-List6 7 tuple-pattern-element → pattern | IDentifIEr : pattern
1 GRAMMAR OF AN ENUMERATION CASE PATTERN2 3 enum-case-pattern → type-IDentifIEr opt . enum-case-name tuple-pattern opt
1 GRAMMAR OF AN OPTIONAL PATTERN2 3 optional-pattern → IDentifIEr-pattern ?
1 GRAMMAR OF A TYPE CASTING PATTERN2 3 type-casting-pattern → is-pattern | as-pattern4 5 is-pattern → is type6 7 as-pattern → pattern as type
1 GRAMMAR OF AN Expression PATTERN2 3 Expression-pattern → Expression泛型和参数
1 GRAMMAR OF A GENERIC ParaMETER CLAUSE 2 3 generic-parameter-clause → < generic-parameter-list > 4 5 generic-parameter-list → generic-parameter | generic-parameter,generic-parameter-List 6 7 generic-parameter → type-name 8 9 generic-parameter → type-name : type-IDentifIEr10 11 generic-parameter → type-name : protocol-composition-type12 13 generic-where-clause → where requirement-List14 15 requirement-List → requirement | requirement,requirement-List16 17 requirement → conformance-requirement | same-type-requirement18 19 conformance-requirement → type-IDentifIEr : type-IDentifIEr20 21 conformance-requirement → type-IDentifIEr : protocol-composition-type22 23 same-type-requirement → type-IDentifIEr == type
1 GRAMMAR OF A GENERIC ARGUMENT CLAUSE2 3 generic-argument-clause → < generic-argument-List >4 5 generic-argument-List → generic-argument | generic-argument,generic-argument-List6 7 generic-argument → type总结
以上是内存溢出为你收集整理的Swift4.2语言参考(十) 语法汇总全部内容,希望文章能够帮你解决Swift4.2语言参考(十) 语法汇总所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)