From 3acdfbca8c4a43e6dc64bf844a6f1a190beef796 Mon Sep 17 00:00:00 2001 From: Jie Liang Date: Wed, 27 Mar 2019 00:33:34 -0500 Subject: [PATCH] fix none text anchor --- source/chapter3/02_Lexical_Structure.md | 54 +++---- source/chapter3/03_Types.md | 48 +++--- source/chapter3/04_Expressions.md | 70 ++++----- source/chapter3/05_Statements.md | 142 +++++++++--------- source/chapter3/06_Declarations.md | 78 +++++----- source/chapter3/08_Patterns.md | 26 ++-- .../09_Generic_Parameters_and_Arguments.md | 18 +-- 7 files changed, 218 insertions(+), 218 deletions(-) diff --git a/source/chapter3/02_Lexical_Structure.md b/source/chapter3/02_Lexical_Structure.md index afc994f3..ffff9205 100755 --- a/source/chapter3/02_Lexical_Structure.md +++ b/source/chapter3/02_Lexical_Structure.md @@ -13,7 +13,7 @@ Swift 的*“词法结构(lexical structure)”* 描述了能构成该语言 > 空白语法 > -###### {#whitespace} +###### whitespace {#whitespace} > *空白* → [*空白项*](#whitespace-item) [*空白*](#whitespace)可选 > > *空白项* → [*断行符*](#line-break) @@ -25,7 +25,7 @@ Swift 的*“词法结构(lexical structure)”* 描述了能构成该语言 > *空白项* → U+0000,U+0009,U+000B,U+000C 或者 U+0020 > -###### {#line-break} +###### line-break {#line-break} > *断行符* → U+000A > > *断行符* → U+000D @@ -33,7 +33,7 @@ Swift 的*“词法结构(lexical structure)”* 描述了能构成该语言 > *断行符* → U+000D 接着是 U+000A > -###### {#comment} +###### comment {#comment} > *注释* → // [*注释内容 断行*](#comment-text line-break) > > *多行注释* → `/*` [*多行注释内容*](#multiline-commnet-text) `*/` @@ -64,7 +64,7 @@ Swift 的*“词法结构(lexical structure)”* 描述了能构成该语言 > 标识符语法 > -###### {#identifier} +###### identifier {#identifier} > *标识符* → [*头部标识符*](#identifier-head) [*标识符字符组*](#identifier-characters)可选 > > *标识符* → \`[*头部标识符*](#identifier-head) [*标识符字符组*](#identifier-characters)可选\` @@ -72,11 +72,11 @@ Swift 的*“词法结构(lexical structure)”* 描述了能构成该语言 > *标识符* → [*隐式参数名*](#implicit-parameter-name) > -###### {#identifier-list} +###### identifier-list {#identifier-list} > *标识符列表* → [*标识符*](#identifier) | [*标识符*](#identifier) **,** [*标识符列表*](#identifier-list) > -###### {#identifier-head} +###### identifier-head {#identifier-head} > *头部标识符* → 大写或小写字母 A - Z > > *头部标识符* → _ @@ -110,7 +110,7 @@ Swift 的*“词法结构(lexical structure)”* 描述了能构成该语言 > *头部标识符* → U+D0000–U+DFFFD 或者 U+E0000–U+EFFFD > -###### {#identifier-character} +###### identifier-character {#identifier-character} > *标识符字符* → 数值 0 - 9 > > *标识符字符* → U+0300–U+036F,U+1DC0–U+1DFF,U+20D0–U+20FF,或者 U+FE20–U+FE2F @@ -122,7 +122,7 @@ Swift 的*“词法结构(lexical structure)”* 描述了能构成该语言 > *标识符字符组* → [*标识符字符*](#identifier-character) [*标识符字符组*](#identifier-characters)可选 > -###### {#implicit-parameter-name} +###### implicit-parameter-name {#implicit-parameter-name} > *隐式参数名* → **$** [*十进制数字列表*](#decimal-digits) > @@ -161,7 +161,7 @@ true // 布尔值字面量 > *字面量* → [*数值字面量*](#numeric-literal) | [*字符串字面量*](#string-literal) | [*布尔值字面量*](#boolean-literal) | [*nil 字面量*](#nil-literal) > -###### {#numeric-literal} +###### numeric-literal {#numeric-literal} > *数值字面量* → **-**可选 [*整数字面量*](#integer-literal) | **-**可选 [*浮点数字面量*](#floating-point-literal) > > ###### boolean-literal {#boolean-literal} @@ -187,7 +187,7 @@ true // 布尔值字面量 > 整数字面量语法 > -###### {#integer-literal} +###### integer-literal {#integer-literal} > *整数字面量* → [*二进制字面量*](#binary-literal) > > *整数字面量* → [*八进制字面量*](#octal-literal) @@ -197,7 +197,7 @@ true // 布尔值字面量 > *整数字面量* → [*十六进制字面量*](#hexadecimal-literal) > -###### {#binary-literal} +###### binary-literal {#binary-literal} > *二进制字面量* → **0b** [*二进制数字*](#binary-digit) [*二进制字面量字符组*](#binary-literal-characters)可选 > > ###### binary-digit {#binary-digit} @@ -213,7 +213,7 @@ true // 布尔值字面量 > *二进制字面量字符组* → [*二进制字面量字符*](#binary-literal-character) [*二进制字面量字符组*](#binary-literal-characters)可选 > -###### {#octal-literal} +###### octal-literal {#octal-literal} > *八进制字面量* → **0o** [*八进字数字*](#octal-digit) [*八进制字符组*](#octal-literal-characters)可选 > > ###### octal-digit {#octal-digit} @@ -229,7 +229,7 @@ true // 布尔值字面量 > *八进制字符组* → [*八进制字符*](#octal-literal-character) [*八进制字符组*](#octal-literal-characters)可选 > -###### {#decimal-literal} +###### decimal-literal {#decimal-literal} > *十进制字面量* → [*十进制数字*](#decimal-digit) [*十进制字符组*](#decimal-literal-characters)可选 > > ###### decimal-digit {#decimal-digit} @@ -249,7 +249,7 @@ true // 布尔值字面量 > *十进制字符组* → [*十进制字符*](#decimal-literal-character) [*十进制字符组*](#decimal-literal-characters)可选 > -###### {#hexadecimal-literal} +###### hexadecimal-literal {#hexadecimal-literal} > *十六进制字面量* → **0x** [*十六进制数字*](#hexadecimal-digit) [*十六进制字面量字符组*](#hexadecimal-literal-characters)可选 > > ###### hexadecimal-digit {#hexadecimal-digit} @@ -283,13 +283,13 @@ true // 布尔值字面量 > 浮点数字面量语法 > -###### {#floating-point-literal} +###### floating-point-literal {#floating-point-literal} > *浮点数字面量* → [*十进制字面量*](#decimal-literal) [*十进制分数*](#decimal-fraction)可选 [*十进制指数*](#decimal-exponent)可选 > > *浮点数字面量* → [*十六进制字面量*](#hexadecimal-literal) [*十六进制分数*](#hexadecimal-fraction)可选 [*十六进制指数*](#hexadecimal-exponent) > -###### {#decimal-fraction} +###### decimal-fraction {#decimal-fraction} > *十进制分数* → **.** [*十进制字面量*](#decimal-literal) > > ###### decimal-exponent {#decimal-exponent} @@ -297,7 +297,7 @@ true // 布尔值字面量 > *十进制指数* → [*十进制指数 e*](#floating-point-e) [*正负号*](#sign)可选 [*十进制字面量*](#decimal-literal) > -###### {#hexadecimal-fraction} +###### hexadecimal-fraction {#hexadecimal-fraction} > *十六进制分数* → **.** [*十六进制数字*](#hexadecimal-digit) [*十六进制字面量字符组*](#hexadecimal-literal-characters)可选 > > ###### hexadecimal-exponent {#hexadecimal-exponent} @@ -305,7 +305,7 @@ true // 布尔值字面量 > *十六进制指数* → [*十六进制指数 p*](#floating-point-p) [*正负号*](#sign)可选 [*十进制字面量*](#decimal-literal) > -###### {#floating-point-e} +###### floating-point-e {#floating-point-e} > *十进制指数 e* → **e** | **E** > > ###### floating-point-p {#floating-point-p} @@ -378,11 +378,11 @@ let textB = "Hello world" > 字符串字面量语法 > -###### {#string-literal} +###### string-literal {#string-literal} > *字符串字面量* → [*静态字符串字面量*](#static-string-literal) | [*插值字符串字面量*](#interpolated-string-literal) > -###### {#static-string-literal} +###### static-string-literal {#static-string-literal} > *静态字符串字面量* → **"**[*引用文本*](#quoted-text)可选**"** > > ###### quoted-text {#quoted-text} @@ -396,7 +396,7 @@ let textB = "Hello world" > *引用文本项* → 除了 **"**、**\\**、U+000A、U+000D 以外的所有 Unicode 字符 > -###### {#interpolated-string-literal} +###### interpolated-string-literal {#interpolated-string-literal} > *插值字符串字面量* → **"**[*插值文本*](#interpolated-text)可选**"** > > ###### interpolated-text {#interpolated-text} @@ -408,7 +408,7 @@ let textB = "Hello world" > *插值文本项* → **\\****(**[*表达式*](./04_Expressions.md)**)** | [*引用文本项*](#quoted-text-item) > -###### {#escaped-character} +###### escaped-character {#escaped-character} > *转义字符* → **\\****0** | **\\****\\** | **\t** | **\n** | **\r** | **\\"** | **\\'** > > *转义字符* → **\u {** [*unicode 标量数字*](#unicode-scalar-digits) **}** @@ -450,13 +450,13 @@ Swift 标准库定义了许多可供使用的运算符,其中大部分在 [基 > 运算符语法 > -###### {#operator} +###### operator {#operator} > *运算符* → [*头部运算符*](#operator-head) [*运算符字符组*](#operator-characters)可选 > > *运算符* → [*头部点运算符*](#dot-operator-head) [*点运算符字符组*](#dot-operator-characters)可选 > -###### {#operator-head} +###### operator-head {#operator-head} > *头部运算符* → **/** | **=** | **-** | **+** | **!** | __*__ | **%** | **<** | **>** | **&** | **|** | **^** | **~** | **?** > > *头部运算符* → U+00A1–U+00A7 @@ -488,7 +488,7 @@ Swift 标准库定义了许多可供使用的运算符,其中大部分在 [基 > *头部运算符* → U+3008–U+3030 > -###### {#operator-character} +###### operator-character {#operator-character} > *运算符字符* → [*头部运算符*](#operator-head) > > *运算符字符* → U+0300–U+036F @@ -508,7 +508,7 @@ Swift 标准库定义了许多可供使用的运算符,其中大部分在 [基 > *运算符字符组* → [*运算符字符*](#operator-character) [*运算符字符组*](#operator-characters)可选 > -###### {#dot-operator-head} +###### dot-operator-head {#dot-operator-head} > *头部点运算符* → **..** > > ###### dot-operator-character {#dot-operator-character} @@ -520,7 +520,7 @@ Swift 标准库定义了许多可供使用的运算符,其中大部分在 [基 > *点运算符字符组* → [*点运算符字符*](#dot-operator-character) [*点运算符字符组*](#dot-operator-characters)可选 > -###### {#binary-operator} +###### binary-operator {#binary-operator} > *二元运算符* → [*运算符*](#operator) > > ###### prefix-operator {#prefix-operator} diff --git a/source/chapter3/03_Types.md b/source/chapter3/03_Types.md index e5627a56..49380784 100644 --- a/source/chapter3/03_Types.md +++ b/source/chapter3/03_Types.md @@ -27,7 +27,7 @@ Swift 语言存在两种类型:命名型类型和复合型类型。命名型 > 类型语法 > -###### {#type} +###### type {#type} > *类型* → [*数组类型*](#array-type) > > *类型* → [*字典类型*](#dictionary-type) @@ -67,7 +67,7 @@ func someFunction(a: Int) { /* ... */ } > 类型注解语法 > -###### {#type-annotation} +###### type-annotation {#type-annotation} > *类型注解* → **:** [*特性列表*](./07_Attributes.md#attributes)可选 **输入输出参数**可选 [*类型*](#type) > @@ -91,10 +91,10 @@ var someValue: ExampleModule.MyType > 类型标识符语法 > -###### {#type-identifier} +###### type-identifier {#type-identifier} > *类型标识符* → [*类型名称*](#type-name) [*泛型参数子句*](08_Generic_Parameters_and_Arguments.md#generic_argument_clause)可选 | [*类型名称*](#type-name) [*泛型参数子句*](08_Generic_Parameters_and_Arguments.md#generic_argument_clause)可选 **.** [*类型标识符*](#type-identifier) > -###### {#type-name} +###### type-name {#type-name} > *类型名称* → [*标识符*](./02_Lexical_Structure.md#identifier) > @@ -116,16 +116,16 @@ someTuple = (left: 5, right: 5) // 错误:命名类型不匹配 > 元组类型语法 > -###### {#tuple-type} +###### tuple-type {#tuple-type} > *元组类型* → **(** [*元组类型元素列表*](#tuple-type-element-list) 可选 **)** > -###### {#tuple-type-element-list} +###### tuple-type-element-list {#tuple-type-element-list} > *元组类型元素列表* → [*元组类型元素*](#tuple-type-element) | [*元组类型元素*](#tuple-type-element) **,** [*元组类型元素列表*](#tuple-type-element-list) > -###### {#tuple-type-element} +###### tuple-type-element {#tuple-type-element} > *元组类型元素* → [*元素名*](#element-name) [*类型注解*](#type-annotation) | [*类型*](#type) > -###### {#element-name} +###### element-name {#element-name} > *元素名* → [*标识符*](./02_Lexical_Structure.md#identifier) > @@ -209,23 +209,23 @@ func takesTwoFunctions(first: (Any) -> Void, second: (Any) -> Void) { > 函数类型语法 > -###### {#function-type} +###### function-type {#function-type} > *函数类型* → [*特性列表*](./07_Attributes.md#attributes)可选 [*函数类型子句*](#function-type-argument-clause) **throws**可选 **->** [*类型*](#type) > > *函数类型* → [*特性列表*](./07_Attributes.md#attributes)可选 [*函数类型子句*](#function-type-argument-clause) **rethrows­** **->** [*类型*](#type) > -###### {#function-type-argument-clause} +###### function-type-argument-clause {#function-type-argument-clause} > *函数类型子句* → (­)­ > > *函数类型子句* → ([*函数类型参数列表*](#function-type-argument-list)*...*­可选)­ > -###### {#function-type-argument-list} +###### function-type-argument-list {#function-type-argument-list} > *函数类型参数列表* → [*函数类型参数*](function-type-argument) | [*函数类型参数*](function-type-argument), [*函数类型参数列表*](#function-type-argument-list) > -###### {#function-type-argument} +###### function-type-argument {#function-type-argument} > *函数类型参数* → [*特性列表*](./07_Attributes.md#attributes)可选 **输入输出参数**可选 [*类型*](#type) | [*参数标签*](#argument-label) [*类型注解*](#type-annotation) > -###### {#argument-label} +###### argument-label {#argument-label} > *参数标签* → [*标识符*](./02_Lexical_Structure.md#identifier) > @@ -257,7 +257,7 @@ var array3D: [[[Int]]] = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] > 数组类型语法 > -###### {#array-type} +###### array-type {#array-type} > *数组类型* → **[** [*类型*](#type) **]** > @@ -285,7 +285,7 @@ let someDictionary: Dictionary = ["Alex": 31, "Paul": 39] > 字典类型语法 > -###### {#dictionary-type} +###### dictionary-type {#dictionary-type} > *字典类型* → **[** [*类型*](#type) **:** [*类型*](#type) **]** > @@ -316,7 +316,7 @@ optionalInteger! // 42 > 可选类型语法 > -###### {#optional-type} +###### optional-type {#optional-type} > *可选类型* → [*类型*](#type) **?** > @@ -350,7 +350,7 @@ let implicitlyUnwrappedArray: [Int]! // 正确 > 隐式解析可选类型语法 > -###### {#implicitly-unwrapped-optional-type} +###### implicitly-unwrapped-optional-type {#implicitly-unwrapped-optional-type} > *隐式解析可选类型* → [*类型*](#type) **!** > @@ -368,13 +368,13 @@ let implicitlyUnwrappedArray: [Int]! // 正确 > 协议合成类型语法 > -###### {#protocol-composition-type} +###### protocol-composition-type {#protocol-composition-type} > *协议合成类型* → [*协议标识符*](#protocol-identifier) & [*协议合成延续*](#protocol-composition-continuation) > -###### {#protocol-composition-continuation} +###### protocol-composition-continuation {#protocol-composition-continuation} > *协议合成延续* → [*协议标识符*](#protocol-identifier) | [*协议合成类型*](#protocol-composition-type) > -###### {#protocol-identifier} +###### protocol-identifier {#protocol-identifier} > *协议标识符* → [*类型标识符*](#type-identifier) > @@ -423,7 +423,7 @@ let anotherInstance = metatype.init(string: "some string") > 元类型语法 > -###### {#metatype-type} +###### metatype-type {#metatype-type} > *元类型* → [*类型*](#type) **.** **Type** | [*类型*](#type) **.** **Protocol** > @@ -438,13 +438,13 @@ let anotherInstance = metatype.init(string: "some string") > 类型继承子句语法 > -###### {#type_inheritance_clause} +###### type_inheritance_clause {#type_inheritance_clause} > *类型继承子句* → **:** [*类型继承列表*](#type-inheritance-list) > -###### {#type-inheritance-list} +###### type-inheritance-list {#type-inheritance-list} > *类型继承列表* → [*类型标识符*](#type-identifier) | [*类型标识符*](#type-identifier) **,** [*类型继承列表*](#type-inheritance-list) > -###### {#class-requirement} +###### class-requirement {#class-requirement} ## 类型推断 {#type_inference} diff --git a/source/chapter3/04_Expressions.md b/source/chapter3/04_Expressions.md index 7eebe85c..7e6d10b8 100644 --- a/source/chapter3/04_Expressions.md +++ b/source/chapter3/04_Expressions.md @@ -6,10 +6,10 @@ Swift 中存在四种表达式:前缀表达式,二元表达式,基本表 > 表达式语法 > -###### {#expression} +###### expression {#expression} > *表达式* → [*try 运算符*](#try-operator)可选 [*前缀表达式*](#prefix-expression) [*二元表达式列表*](#binary-expressions)可选 > -###### {#expression-list} +###### expression-list {#expression-list} > *表达式列表* → [*表达式*](#expression) | [*表达式*](#expression) **,** [*表达式列表*](#expression-list) > @@ -24,12 +24,12 @@ Swift 中存在四种表达式:前缀表达式,二元表达式,基本表 > 前缀表达式语法 > -###### {#prefix-expression} +###### prefix-expression {#prefix-expression} > *前缀表达式* → [*前缀运算符*](./02_Lexical_Structure.md#prefix-operator)可选 [*后缀表达式*](#postfix-expression) > > *前缀表达式* → [*输入输出表达式*](#in-out-expression) > -###### {#in-out-expression} +###### in-out-expression {#in-out-expression} > *输入输出表达式* → **&** [*标识符*](./02_Lexical_Structure.md#identifier) > @@ -66,7 +66,7 @@ sum = (try someThrowingFunction()) + anotherThrowingFunction() // 错误:try 关于 `try`、`try?` 和 `try!` 的更多信息,以及该如何使用的例子,请参阅 [错误处理](../chapter2/17_Error_Handling.md)。 > Try 表达式语法 > -###### {#try-operator} +###### try-operator {#try-operator} > *try 运算符* → **try** | **try?** | **try!** > @@ -85,7 +85,7 @@ sum = (try someThrowingFunction()) + anotherThrowingFunction() // 错误:try > 在解析时,一个二元表达式将作为一个扁平列表表示,然后根据运算符的优先级,再进一步进行组合。例如,`2 + 3 * 5` 首先被看作具有五个元素的列表,即 `2`、`+`、`3`、`*`、`5`,随后根据运算符优先级组合为 `(2 + (3 * 5))`。 > -###### {#binary-expression} +###### binary-expression {#binary-expression} > 二元表达式语法 > > *二元表达式* → [*二元运算符*](./02_Lexical_Structure.md#binary-operator) [*前缀表达式*](#prefix-expression) @@ -96,7 +96,7 @@ sum = (try someThrowingFunction()) + anotherThrowingFunction() // 错误:try > > *二元表达式* → [*类型转换运算符*](#type-casting-operator) > -###### {#binary-expressions} +###### binary-expressions {#binary-expressions} > *二元表达式列表* → [*二元表达式*](#binary-expression) [*二元表达式列表*](#binary-expressions)可选 > @@ -117,7 +117,7 @@ sum = (try someThrowingFunction()) + anotherThrowingFunction() // 错误:try > 赋值运算符语法 > -###### {#assignment-operator} +###### assignment-operator {#assignment-operator} > *赋值运算符* → **=** > @@ -133,7 +133,7 @@ sum = (try someThrowingFunction()) + anotherThrowingFunction() // 错误:try > 三元条件运算符语法 > -###### {#conditional-operator} +###### conditional-operator {#conditional-operator} > *三元条件运算符* → **?** [*表达式*](#expression) **:** > @@ -176,7 +176,7 @@ f(x as Any) 关于类型转换的更多内容和例子,请参阅 [类型转换](../chapter2/18_Type_Casting.md)。 -###### {#type-casting-operator} +###### type-casting-operator {#type-casting-operator} > 类型转换运算符语法 > > *类型转换运算符* → **is** [*类型*](./03_Types.md#type) @@ -193,7 +193,7 @@ f(x as Any) > 基本表达式语法 > -###### {#primary-expression} +###### primary-expression {#primary-expression} > *基本表达式* → [*标识符*](./02_Lexical_Structure.md#identifier) [*泛型实参子句*](./09_Generic_Parameters_and_Arguments.md#generic-argument-clause)可选 > > *基本表达式* → [*字面量表达式*](#literal-expression) @@ -354,17 +354,17 @@ struct Point { > Self 表达式语法 > -###### {#self-expression} +###### self-expression {#self-expression} > *self 表达式* → **self** | [*self 方法表达式*](#self-method-expression) | [*self 下标表达式*](#self-subscript-expression) | [*self 构造器表达式*](#self-initializer-expression) > > -###### {#self-method-expression} +###### self-method-expression {#self-method-expression} > *self 方法表达式* → **self** **.** [*标识符*](./02_Lexical_Structure.md#identifier) > -###### {#self-subscript-expression} +###### self-subscript-expression {#self-subscript-expression} > *self 下标表达式* → **self** **[** [*函数调用参数表*](#function-call-argument-list­) **]** > -###### {#self-initializer-expression} +###### self-initializer-expression {#self-initializer-expression} > *self 构造器表达式* → **self** **.** **init** > @@ -384,16 +384,16 @@ struct Point { > 父类表达式语法 > -###### {#superclass-expression} +###### superclass-expression {#superclass-expression} > *父类表达式* → [*父类方法表达式*](#superclass-method-expression) | [*父类下标表达式*](#superclass-subscript-expression) | [*父类构造器表达式*](#superclass-initializer-expression) > -###### {#superclass-method-expression} +###### superclass-method-expression {#superclass-method-expression} > *父类方法表达式* → **super** **.** [*标识符*](./02_Lexical_Structure.md#identifier) > -###### {#superclass-subscript-expression} +###### superclass-subscript-expression {#superclass-subscript-expression} > *父类下标表达式* → **super** [[*函数调用参数表*](#function-call-argument-list­) **]** > -###### {#superclass-initializer-expression} +###### superclass-initializer-expression {#superclass-initializer-expression} > *父类构造器表达式* → **super** **.** **init** > @@ -553,7 +553,7 @@ x = .AnotherValue > 隐式成员表达式语法 > -###### {#implicit-member-expression} +###### implicit-member-expression {#implicit-member-expression} > *隐式成员表达式* → **.** [*标识符*](./02_Lexical_Structure.md#identifier) > @@ -562,7 +562,7 @@ x = .AnotherValue > 圆括号表达式语法 > -###### {#parenthesized-expression} +###### parenthesized-expression {#parenthesized-expression} > *圆括号表达式* → **( [*表达式*](#expression) )** > @@ -583,13 +583,13 @@ x = .AnotherValue > 元组表达式语法 > -###### {#tuple-expression} +###### tuple-expression {#tuple-expression} > *元组表达式* → **( )** | **(**[*元组元素*](#tuple-element), [*元组元素列表*](#tuple-element-list) **)** > -###### {#tuple-element-list} +###### tuple-element-list {#tuple-element-list} > *元组元素列表* → [*元组元素*](#tuple-element) | [*元组元素*](#tuple-element) **,** [*元组元素列表*](#tuple-element-list) > -###### {#tuple-element} +###### tuple-element {#tuple-element} > *元组元素* → [*表达式*](#expression) | [*标识符*](identifier) **:** [*表达式*](#expression) > @@ -603,7 +603,7 @@ x = .AnotherValue > 通配符表达式语法 > -###### {#wildcard-expression} +###### wildcard-expression {#wildcard-expression} > *通配符表达式* → **_** > @@ -809,7 +809,7 @@ let anotherSelector = #selector(SomeClass.doSomething(_:) as (SomeClass) -> (Str > 选择器表达式语法 > -###### {#selector-expression} +###### selector-expression {#selector-expression} > *选择器表达式* → __#selector__ **(** [*表达式*](#expression) **)** > > *选择器表达式* → __#selector__ **(** [*getter:表达式*](#expression) **)** @@ -881,7 +881,7 @@ print(keyPath == c.getSomeKeyPath()) > 后缀表达式语法 > -###### {#postfix-expression} +###### postfix-expression {#postfix-expression} > *后缀表达式* → [*基本表达式*](#primary-expression) > > *后缀表达式* → [*后缀表达式*](#postfix-expression) [*后缀运算符*](02_Lexical_Structure.md#postfix-operator) @@ -1001,7 +1001,7 @@ let s3 = someValue.dynamicType.init(data: 7) // 有效 > 构造器表达式语法 > -###### {#initializer-expression} +###### initializer-expression {#initializer-expression} > *构造器表达式* → [*后缀表达式*](#postfix-expression) **.** **init** > > *构造器表达式* → [*后缀表达式*](#postfix-expression) **.** **init** **(** [*参数名称*](#argument-names) **)** @@ -1067,17 +1067,17 @@ let x = [10, 3, 20, 15, 4] > 显式成员表达式语法 > -###### {#explicit-member-expression} +###### explicit-member-expression {#explicit-member-expression} > *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*十进制数字*] (02_Lexical_Structure.md#decimal-digit) > > *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*标识符*](02_Lexical_Structure.md#identifier) [*泛型实参子句*](./09_Generic_Parameters_and_Arguments.md#generic-argument-clause)可选
> > *显式成员表达式* → [*后缀表达式*](#postfix-expression) **.** [*标识符*] (02_Lexical_Structure.md#identifier) **(** [*参数名称*](#argument-names) **)** > -###### {#argument-names} +###### argument-names {#argument-names} > *参数名称* → [*参数名*](#argument-name) [*参数名称*](#argument-names)可选
> -###### {#argument-name} +###### argument-name {#argument-name} > *参数名* → [*标识符*](./02_Lexical_Structure.md#identifier) **:** > @@ -1095,7 +1095,7 @@ let x = [10, 3, 20, 15, 4] > 后缀 self 表达式语法 > -###### {#postfix-self-expression} +###### postfix-self-expression {#postfix-self-expression} > *后缀 self 表达式* → [*后缀表达式*](#postfix-expression) **.** **self** > @@ -1112,7 +1112,7 @@ let x = [10, 3, 20, 15, 4] > 下标表达式语法 > -###### {#subscript-expression} +###### subscript-expression {#subscript-expression} > *下标表达式* → [*后缀表达式*](#postfix-expression) **[** [*表达式列表*](#expression-list) **]** > @@ -1138,7 +1138,7 @@ someDictionary["a"]![0] = 100 > 强制取值语法 > -###### {#forced-value-expression} +###### forced-value-expression {#forced-value-expression} > *强制取值表达式* → [*后缀表达式*](#postfix-expression) **!** > @@ -1190,6 +1190,6 @@ someDictionary["a"]?[0] = someFunctionWithSideEffects() > 可选链表达式语法 > -###### {#optional-chaining-expression} +###### optional-chaining-expression {#optional-chaining-expression} > *可选链表达式* → [*后缀表达式*](#postfix-expression) **?** > diff --git a/source/chapter3/05_Statements.md b/source/chapter3/05_Statements.md index 51259de0..8a0c6413 100755 --- a/source/chapter3/05_Statements.md +++ b/source/chapter3/05_Statements.md @@ -7,7 +7,7 @@ > 语句语法 > -###### {#statement} +###### statement {#statement} > *语句* → [*表达式*](./04_Expressions.md#expression) **;**可选 > > *语句* → [*声明*](./06_Declarations.md#declaration) **;**可选 @@ -26,7 +26,7 @@ > > *语句* → [*编译器控制语句*](#compiler-control-statement) > -###### {#statements} +###### statements {#statements} > *多条语句* → [*语句*](#statement) [*多条语句*](#statements)可选 > @@ -38,7 +38,7 @@ > 循环语句语法 > > -###### {#loop-statement} +###### loop-statement {#loop-statement} > *循环语句* → [*for-in 语句*](#for-in-statement) > > *循环语句* → [*while 语句*](#while-statement) @@ -62,7 +62,7 @@ for item in collection { > for-in 语句语法 > > -###### {#for-in-statement} +###### for-in-statement {#for-in-statement} > *for-in 语句* → **for** **case**可选 [*模式*](./08_Patterns.md#pattern) **in** [*表达式*](./04_Expressions.md#expression) [*where 子句*](#where-clause)可选 [*代码块*](05_Declarations.md#code-block) > @@ -89,21 +89,21 @@ while condition { > while 语句语法 > > -###### {#while-statement} +###### while-statement {#while-statement} > *while 语句* → **while** [*条件子句*](#condition-clause) [*代码块*](05_Declarations.md#code-block) > -###### {#condition-clause} +###### condition-clause {#condition-clause} > *条件子句* → [*表达式*](./04_Expressions.md#expression) | [*表达式*](./04_Expressions.md#expression) **,** [*条件列表*](#condition-list) > -###### {#condition} +###### condition {#condition} > *条件* → [*表达式*](./04_Expressions.md#expression) |[*可用性条件*](#availability-condition) | [*case 条件*](#case-condition) | [*可选绑定条件*](#optional-binding-condition) > > -###### {#case-condition} +###### case-condition {#case-condition} > *case 条件* → **case** [*模式*](./08_Patterns.md#pattern) [*构造器*](./06_Declarations.md#initializer) > -###### {#optional-binding-condition} +###### optional-binding-condition {#optional-binding-condition} > *可选绑定条件* → **let** [*模式*](./08_Patterns.md#pattern) [*构造器*](./06_Declarations.md#initializer) | **var** [*模式*](./08_Patterns.md#pattern) [*构造器*](./06_Declarations.md#initializer) > @@ -130,7 +130,7 @@ repeat { > repeat-while 语句语法 > > -###### {#repeat-while-statement} +###### repeat-while-statement {#repeat-while-statement} > *repeat-while 语句* → **repeat** [*代码块*](./06_Declarations.md#code-block) **while** [*表达式*](./04_Expressions.md#expression) > @@ -142,7 +142,7 @@ repeat { > 分支语句语法 > > -###### {#branch-statement} +###### branch-statement {#branch-statement} > *分支语句* → [*if 语句*](#if-statement) > > *分支语句* → [*guard 语句*](#guard-statement) @@ -190,10 +190,10 @@ if condition 1 { > if 语句语法 > > -###### {#if-statement} +###### if-statement {#if-statement} > *if 语句* → **if** [*条件子句*](#condition-clause) [*代码块*](05_Declarations.md#code-block) [*else 子句*](#else-clause)可选 > -###### {#else-clause} +###### else-clause {#else-clause} > *else 子句* → **else** [*代码块*](./06_Declarations.md#code-block) | **else** [*if 语句*](#if-statement) > @@ -224,7 +224,7 @@ guard condition else { > guard 语句语法 > > -###### {#guard-statement} +###### guard-statement {#guard-statement} > *guard 语句* → **guard** [*条件子句*](#condition-clause) **else** [*代码块*] (05_Declarations.md#code-block) > @@ -296,46 +296,46 @@ case .suppressed: > switch 语句语法 > > -###### {#switch-statement} +###### switch-statement {#switch-statement} > *switch 语句* → **switch** [*表达式*](./04_Expressions.md#expression) **{** [*switch-case 列表*](#switch-cases)可选 **}** > -###### {#switch-cases} +###### switch-cases {#switch-cases} > *switch case 列表* → [*switch-case*](#switch-case) [*switch-case 列表*](#switch-cases)可选 > -###### {#switch-case} +###### switch-case {#switch-case} > *switch case* → [*case 标签*](#case-label) [*多条语句*](#statements) | [*default 标签*](#default-label) [*多条语句*](#statements) | [*conditional-switch-case*](#conditional-switch-case-label) > -###### {#case-label} +###### case-label {#case-label} > *case 标签* → [*属性*](#switch-case-attributes-label)可选 **case** [*case 项列表*](#case-item-list) **:** > -###### {#case-item-list} +###### case-item-list {#case-item-list} > *case 项列表* → [*模式*](./08_Patterns.md#pattern) [*where 子句*](#where-clause)可选 | [*模式*](07_Patterns.md#pattern) [*where 子句*](#where-clause)可选 **,** [*case 项列表*](#case-item-list) > -###### {#default-label} +###### default-label {#default-label} > *default 标签* → [*属性*](#switch-case-attributes-label)可选 **default** **:** > > -###### {#where-clause} +###### where-clause {#where-clause} > *where-clause* → **where** [*where 表达式*](#where-expression) > -###### {#where-expression} +###### where-expression {#where-expression} > *where-expression* → [*表达式*](./04_Expressions.md#expression) > > -###### {#grammar_conditional-switch-case} +###### grammar_conditional-switch-case {#grammar_conditional-switch-case} > *conditional-switch-case* → [*switch-if-directive-clause*](#switch-case-attributes-label) [*switch-elseif-directive-clauses*](#switch-case-attributes-label) 可选 [*switch-else-directive-clause*](#switch-case-attributes-label) 可选 [*endif-directive*](#switch-case-attributes-label) > -###### {#grammar_switch-if-directive-clause} +###### grammar_switch-if-directive-clause {#grammar_switch-if-directive-clause} > *switch-if-directive 语句* → [*if-directive*](#switch-case-attributes-label) [*compilation-condition*](#switch-case-attributes-label) [*switch-cases*](#switch-case-attributes-label) 可选 > -###### {#grammar_switch-elseif-directive-clauses} +###### grammar_switch-elseif-directive-clauses {#grammar_switch-elseif-directive-clauses} > *switch-elseif-directive 语句(复数)* → [*elseif-directive-clause*](#switch-case-attributes-label) [*switch-elseif-directive-clauses*](#switch-case-attributes-label)可选 > -###### {#grammar_switch-elseif-directive-clause} +###### grammar_switch-elseif-directive-clause {#grammar_switch-elseif-directive-clause} > *switch-elseif-directive 语句* → [*elseif-directive*](#switch-case-attributes-label) [*compilation-condition*](#switch-case-attributes-label) [*switch-cases*](#switch-case-attributes-label)可选 > -###### {#grammar_switch-else-directive-clause} +###### grammar_switch-else-directive-clause {#grammar_switch-else-directive-clause} > *switch-else-directive 语句* → [*else-directive*](#switch-case-attributes-label) [*switch-cases*](#switch-case-attributes-label) 可选 > @@ -349,7 +349,7 @@ case .suppressed: > 带标签的语句语法 > > -###### {#labeled-statement} +###### labeled-statement {#labeled-statement} > *带标签的语句* → [*语句标签*](#statement-label) [*循环语句*](#grammar_loop-statement) > > *带标签的语句* → [*语句标签*](#statement-label) [*if 语句*](#if-statement) @@ -358,10 +358,10 @@ case .suppressed: > > > *带标签的语句* → [*语句标签*](#statement-label) [*do 语句*](#sdo-statement) > -###### {#statement-label} +###### statement-label {#statement-label} > *语句标签* → [*标签名称*](#label-name) **:** > -###### {#label-name} +###### label-name {#label-name} > *标签名称* → [*标识符*](./02_Lexical_Structure.md#identifier) > @@ -371,7 +371,7 @@ case .suppressed: > 控制转移语句语法 > > -###### {#control-transfer-statement} +###### control-transfer-statement {#control-transfer-statement} > *控制转移语句* → [*break 语句*](#break-statement) > > *控制转移语句* → [*continue 语句*](#continue-statement) @@ -402,7 +402,7 @@ case .suppressed: > break 语句语法 > > -###### {#break-statement} +###### break-statement {#break-statement} > *break 语句* → **break** [*标签名称*](#label-name)可选 > @@ -427,7 +427,7 @@ case .suppressed: > continue 语句语法 > > -###### {#continue-statement} +###### continue-statement {#continue-statement} > *continue 语句* → **continue** [*标签名称*](#label-name)可选 > @@ -441,7 +441,7 @@ case .suppressed: > fallthrough 语句语法 > > -###### {#fallthrough-statement} +###### fallthrough-statement {#fallthrough-statement} > *fallthrough 语句* → **fallthrough** > @@ -468,7 +468,7 @@ case .suppressed: > return 语句语法 > > -###### {#return-statement} +###### return-statement {#return-statement} > *return 语句* → **return** [*表达式*](./04_Expressions.md#expression)可选 > @@ -489,7 +489,7 @@ case .suppressed: > throw 语句语法 > > -###### {#throw-statement} +###### throw-statement {#throw-statement} > *throw 语句* → **throw** [*表达式*](./04_Expressions.md#expression) > @@ -525,7 +525,7 @@ f() > defer 语句语法 > > -###### {#defer-statement} +###### defer-statement {#defer-statement} > *延迟语句* → **defer** [*代码块*](./06_Declarations.md#code-block) > @@ -556,13 +556,13 @@ do { > do 语句语法 > > -###### {#do-statement} +###### do-statement {#do-statement} > *do 语句* → **do** [*代码块*](./06_Declarations.md#code-block) [*多条 catch 子句*](#catch-clauses)可选 > -###### {#catch-clauses} +###### catch-clauses {#catch-clauses} > *多条 catch 子句* → [*catch 子句*](#catch-clause) [*多条 catch 子句*](#catch-clauses)可选 > -###### {#catch-clause} +###### catch-clause {#catch-clause} > *catch 子句* → **catch** [*模式*](./08_Patterns.md#pattern)可选 [*where 子句*](#where-clause)可选 [*代码块*](05_Declarations.md#code-block) > @@ -572,7 +572,7 @@ do { > 编译器控制语句语法 > > -###### {#compiler-control-statement} +###### compiler-control-statement {#compiler-control-statement} > *编译器控制语句* → [*条件编译语句*](#grammar_conditional-compilation-block) > > *编译器控制语句* → [*线路控制语句*](#line-control-statement) @@ -651,23 +651,23 @@ statements to compile if both compilation conditions are false > 即使没有被编译,编译配置中的语句仍然会被解析。然而,唯一的例外是编译配置语句中包含语言版本检测函数:仅当 `Swift` 编译器版本和语言版本检测函数中指定的版本号匹配时,语句才会被解析。这种设定能确保旧的编译器不会尝试去解析新 Swift 版本的语法。 > -###### {#build-config-statement} +###### build-config-statement {#build-config-statement} > 条件编译代码块语法 > > -###### {#grammar_conditional-compilation-block} +###### grammar_conditional-compilation-block {#grammar_conditional-compilation-block} > *条件编译代码块* → [*if-directive 语句*](#grammar_if-directive-clause) [*elseif-directive 语句(复数)*](#grammar_elseif-directive-clauses)可选 [*else-directive 语句*](#grammar_else-directive-clause)可选 [*endif-directive*](#grammar_endif-directive) > -###### {#grammar_if-directive-clause} +###### grammar_if-directive-clause {#grammar_if-directive-clause} > *if-directive 语句* → [*if-directive*](#grammar_if-directive) [*编译条件*](#compilation-condition) [*语句(复数)*](#statements)可选 > -###### {#grammar_elseif-directive-clauses} +###### grammar_elseif-directive-clauses {#grammar_elseif-directive-clauses} > *elseif-directive 语句(复数)* → [*elseif-directive 语句*](#grammar_elseif-directive-clause) [*elseif-directive 语句(复数)*](#grammar_elseif-directive-clauses) > -###### {#grammar_elseif-directive-clauses} +###### grammar_elseif-directive-clauses {#grammar_elseif-directive-clauses} > *elseif-directive 语句* → [*elseif-directive*](#grammar_elseif-directive) [*编译条件*](#compilation-condition) [*语句(复数)*](#statements)可选 > -###### {#grammar_else-directive-clause} +###### grammar_else-directive-clause {#grammar_else-directive-clause} > *else-directive 语句* → [*else-directive*](#grammar_else-directive) [*语句(复数)*](#statements)可选 > @@ -681,7 +681,7 @@ statements to compile if both compilation conditions are false > *endif-directive* → **#endif** > -###### {#compilation-condition} +###### compilation-condition {#compilation-condition} > *编译条件* → [*平台条件*](#grammar_platform-condition) > > *编译条件* → [*标识符*](./02_Lexical_Structure.md#identifier) @@ -697,41 +697,41 @@ statements to compile if both compilation conditions are false > *编译条件* → [*编译条件*](#compilation-condition) **||** [*编译条件*](#compilation-condition) > -###### {#grammar_platform-condition} -###### {#grammar_platform-condition-os} +###### grammar_platform-condition {#grammar_platform-condition} +###### grammar_platform-condition-os {#grammar_platform-condition-os} > *平台条件* → **os ( [*操作系统*](#operating-system) )** > -###### {#grammar_platform-condition-arch} +###### grammar_platform-condition-arch {#grammar_platform-condition-arch} > *平台条件* → **arch ( [*架构*](#architecture) )** > -###### {#grammar_platform-condition-swift} +###### grammar_platform-condition-swift {#grammar_platform-condition-swift} > *平台条件* → **swift ( >= [*swift 版本*](#swift-version) )** | **swift ( < [*swift 版本*](#swift-version) )** > -###### {#grammar_platform-condition-compiler} +###### grammar_platform-condition-compiler {#grammar_platform-condition-compiler} > *平台条件* → **compiler ( >= [*swift 版本*](#swift-version) )** | **compiler ( < [*swift 版本*](#swift-version) )** > -###### {#grammar_platform-condition-canImport} +###### grammar_platform-condition-canImport {#grammar_platform-condition-canImport} > *平台条件* → **canImport ( [*模块名*](#grammar_module-name) )** > -###### {#grammar_platform-condition-targetEnvironment} +###### grammar_platform-condition-targetEnvironment {#grammar_platform-condition-targetEnvironment} > *平台条件* → **targetEnvironment ( [*环境*](#grammar_environment) )** > -###### {#operating-system} +###### operating-system {#operating-system} > *操作系统* → **macOS** | **iOS** | **watchOS** | **tvOS** > -###### {#architecture} +###### architecture {#architecture} > *架构* → **i386** | **x86_64** | **arm** | **arm64** > -###### {#swift-version} +###### swift-version {#swift-version} > *swift 版本* → [*十进制数字*](./02_Lexical_Structure.md#decimal-digit) ­**.** ­[*swift 版本延续*](#grammar_swift-version-continuation) 可选 > -###### {#grammar_swift-version-continuation} +###### grammar_swift-version-continuation {#grammar_swift-version-continuation} > *swift 版本延续* → **.** [*十进制数字*](./02_Lexical_Structure.md#decimal-digit) [*swift 版本延续*](#grammar_swift-version-continuation) 可选 > -###### {#grammar_module-name} +###### grammar_module-name {#grammar_module-name} > *模块名* → [*identifier*](./02_Lexical_Structure.md#identifier) > -###### {#grammar_environment} +###### grammar_environment {#grammar_environment} > *环境* → **模拟器** > @@ -750,7 +750,7 @@ statements to compile if both compilation conditions are false 第二种的行控制语句,`#sourceLocation()`,会将源代码的定位信息重置回默认的行号和文件名。 -###### {#line-control-statement} +###### line-control-statement {#line-control-statement} > 行控制语句语法 > > @@ -758,10 +758,10 @@ statements to compile if both compilation conditions are false > > *行控制语句* → **#sourceLocation()** > -###### {#line-number} +###### line-number {#line-number} > *行号* → 大于 0 的十进制整数 > -###### {#file-name} +###### file-name {#file-name} > *文件名* → [*静态字符串字面量*](./02_Lexical_Structure.md#static-string-literal) > @@ -779,12 +779,12 @@ statements to compile if both compilation conditions are false > 编译时诊断语句语法 > > -###### {#grammar_compile-time-diagnostic-statement} +###### grammar_compile-time-diagnostic-statement {#grammar_compile-time-diagnostic-statement} > *诊断语句* → **#error** **(** [*diagnostic-message*](#grammar_diagnostic-message) **)** > > *诊断语句* → **#warning** **(** [*diagnostic-message*](#grammar_diagnostic-message) **)** > -###### {#grammar_diagnostic-message} +###### grammar_diagnostic-message {#grammar_diagnostic-message} > *诊断语句* → [*静态字符串字面量*](./02_Lexical_Structure.md#static-string-literal) > @@ -810,19 +810,19 @@ if #available(platform name version, ..., *) { > 可用性条件语法 > > -###### {#availability-condition} +###### availability-condition {#availability-condition} > *可用性条件* → **#available** **(** [*可用性参数列表*](#availability-arguments) **)** > -###### {#availability-arguments} +###### availability-arguments {#availability-arguments} > *可用性参数列表* → [*可用性参数*](#availability-argument) | [*可用性参数*](#availability-argument) **,** [*可用性参数列表*](#availability-arguments) > -###### {#availability-argument} +###### availability-argument {#availability-argument} > *可用性参数* → [平台名称](#platform-name) [平台版本](#platform-version) > > *可用性条件* → __*__ > > -###### {#platform-name} +###### platform-name {#platform-name} > *平台名称* → **iOS** | **iOSApplicationExtension** > > *平台名称* → **OSX** | **macOSApplicationExtension** @@ -831,7 +831,7 @@ if #available(platform name version, ..., *) { > > *平台名称* → **tvOS** > -###### {#platform-version} +###### platform-version {#platform-version} > *平台版本* → [十进制数字](./02_Lexical_Structure.md#decimal-digits) > > *平台版本* → [十进制数字](./02_Lexical_Structure.md#decimal-digits) **.** [十进制数字](./02_Lexical_Structure.md#decimal-digits) diff --git a/source/chapter3/06_Declarations.md b/source/chapter3/06_Declarations.md index 2189cb36..4f538449 100755 --- a/source/chapter3/06_Declarations.md +++ b/source/chapter3/06_Declarations.md @@ -80,7 +80,7 @@ import 导入类型 模块.符号名 import 模块.子模块 ``` -###### {#grammer_of_an_import_declaration} +###### grammer_of_an_import_declaration {#grammer_of_an_import_declaration} > 导入声明语法 > > ###### import-declaration {#import-declaration} @@ -132,7 +132,7 @@ print("The second number is \(secondNumber).") 如果还想获得更多关于常量的信息或者想在使用中获得帮助,请参阅 [常量和变量](../chapter2/01_The_Basics.md#constants_and_variables) 和 [存储属性](../chapter2/10_Properties.md#stored_properties)。 -###### {#grammer_of_a_constant_declaration} +###### grammer_of_a_constant_declaration {#grammer_of_a_constant_declaration} > 常量声明语法 > > ###### constant-declaration {#constant-declaration} @@ -242,10 +242,10 @@ var 变量名称: 类型 = 表达式 { > 在一个类声明中,使用关键字 `static` 与同时使用 `class` 和 `final` 去标记一个声明的效果相同。 > -###### {#grammer_of_a_variable_declaration} +###### grammer_of_a_variable_declaration {#grammer_of_a_variable_declaration} > 变量声明语法 > -###### {#variable-declaration} +###### variable-declaration {#variable-declaration} > *变量声明* → [*变量声明头*](#variable-declaration-head) [*模式构造器列表*](#pattern-initializer-list) > > *变量声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*类型标注*](03_Types.md#type-annotation) [*代码块*](#code-block) @@ -259,7 +259,7 @@ var 变量名称: 类型 = 表达式 { > *变量声明* → [*变量声明头*](#variable-declaration-head) [*变量名称*](#variable-name) [*类型标注*](03_Types.md#type-annotation) [*构造器*](#initializer)可选 [*willSet-didSet 代码块*](#willSet-didSet-block) > -###### {#variable-declaration-head} +###### variable-declaration-head {#variable-declaration-head} > *变量声明头* → [*特性列表*](./07_Attributes.md#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **var** > > ###### variable-name {#variable-name} @@ -267,7 +267,7 @@ var 变量名称: 类型 = 表达式 { > *变量名称* → [*标识符*](./02_Lexical_Structure.md#identifier) > -###### {#getter-setter-block} +###### getter-setter-block {#getter-setter-block} > *getter-setter 代码块* → [*代码块*](#code-block) > > *getter-setter 代码块* → **{** [*getter 子句*](#getter-clause) [*setter 子句*](#setter-clause)可选 **}** @@ -287,7 +287,7 @@ var 变量名称: 类型 = 表达式 { > *setter 名称* → **(** [*标识符*](./02_Lexical_Structure.md#identifier) **)** > -###### {#getter-setter-keyword-block} +###### getter-setter-keyword-block {#getter-setter-keyword-block} > *getter-setter 关键字代码块* → **{** [*getter 关键字子句*](#getter-keyword-clause) [*setter 关键字子句*](#setter-keyword-clause)可选 **}** > > *getter-setter 关键字代码块* → **{** [*setter 关键字子句*](#setter-keyword-clause) [*getter 关键字子句*](#getter-keyword-clause) **}** @@ -301,7 +301,7 @@ var 变量名称: 类型 = 表达式 { > *setter 关键字子句* → [*特性列表*](./07_Attributes.md#attributes)可选 **set** > -###### {#willSet-didSet-block} +###### willSet-didSet-block {#willSet-didSet-block} > *willSet-didSet 代码块* → **{** [*willSet 子句*](#willSet-clause) [*didSet 子句*](#didSet-clause)可选 **}** > > *willSet-didSet 代码块* → **{** [*didSet 子句*](#didSet-clause) [*willSet 子句*](#willSet-clause)可选 **}** @@ -370,7 +370,7 @@ func sum(_ sequence: T) -> Int where T.Element == Int { 另请参阅 [协议关联类型声明](#protocol_associated_type_declaration)。 -###### {#grammer_of_a_type_alias_declaration} +###### grammer_of_a_type_alias_declaration {#grammer_of_a_type_alias_declaration} > 类型别名声明语法 > > @@ -570,14 +570,14 @@ Swift 定义了 `Never` 类型,它表示函数或者方法不会返回给它 你可以重写一个不归方法,但是新的方法必须保持原有的返回类型和没有返回的行为。 -###### {#grammer_of_a_function_declaration} +###### grammer_of_a_function_declaration {#grammer_of_a_function_declaration} > 函数声明语法 > -###### {#function-declaration} +###### function-declaration {#function-declaration} > *函数声明* → [*函数头*](#function-head) [*函数名*](#function-name) [*泛型形参子句*](08_Generic_Parameters_and_Arguments.md#generic-parameter-clause)可选 [*函数签名*](#function-signature) [*泛型 where 子句*](08_Generic_Parameters_and_Arguments.md#generic-where-clause) [*函数体*](#function-body)可选 > -###### {#function-head} +###### function-head {#function-head} > *函数头* → [*特性列表*](./07_Attributes.md#attributes)可选 [*声明修饰符列表*](#declaration-modifiers)可选 **func** > > ###### function-name {#function-name} @@ -731,7 +731,7 @@ enum GamePlayMode: String { 可以使用 `switch` 语句来检验枚举用例的值,正如 [使用 switch 语句匹配枚举值](../chapter2/08_Enumerations.md#matching_enumeration_values_with_a_switch_statement) 所述。枚举类型是模式匹配的,依靠 `switch` 语句 `case` 块中的枚举用例模式,正如 [枚举用例模式](./08_Patterns.md#enumeration_case_pattern) 所述。 -###### {#grammer_of_an_enumeration_declaration} +###### grammer_of_an_enumeration_declaration {#grammer_of_an_enumeration_declaration} > 枚举声明语法 > > @@ -837,7 +837,7 @@ struct 结构体名称: 采纳的协议 { 可以使用扩展声明来扩展结构体类型的行为,请参阅 [扩展声明](#extension_declaration)。 -###### {#grammer_of_a_structure_declaration} +###### grammer_of_a_structure_declaration {#grammer_of_a_structure_declaration} > 结构体声明语法 > > @@ -896,7 +896,7 @@ class 类名: 超类, 采纳的协议 { 可以使用扩展声明来扩展类的行为,请参阅 [扩展声明](#extension_declaration)。 -###### {#grammer_of_a_class_declaration} +###### grammer_of_a_class_declaration {#grammer_of_a_class_declaration} > 类声明语法 > > @@ -963,7 +963,7 @@ protocol SomeProtocol: AnyObject { 可以使用协议来声明作为代理的类或者结构体应该实现的方法,正如 [委托(代理)模式](../chapter2/21_Protocols.md#delegation) 中所述。 -###### {#grammer_of_a_protocol_declaration} +###### grammer_of_a_protocol_declaration {#grammer_of_a_protocol_declaration} > 协议声明语法 > > @@ -1017,7 +1017,7 @@ var 属性名: 类型 { get set } 另请参阅 [变量声明](#variable_declaration)。 -###### {#grammer_of_an_import_declaration} +###### grammer_of_an_import_declaration {#grammer_of_an_import_declaration} > 协议属性声明语法 > > ###### protocol-property-declaration {#protocol-property-declaration} @@ -1032,7 +1032,7 @@ var 属性名: 类型 { get set } 另请参阅 [函数声明](#function_declaration)。 -###### {#grammer_of_a_protocol_declaration} +###### grammer_of_a_protocol_declaration {#grammer_of_a_protocol_declaration} > 协议方法声明语法 > > ###### protocol-method-declaration {#protocol-method-declaration} @@ -1050,7 +1050,7 @@ var 属性名: 类型 { get set } 另请参阅 [构造器声明](#initializer_declaration)。 -###### {#grammer_of_a_protocol_initializer_declaration} +###### grammer_of_a_protocol_initializer_declaration {#grammer_of_a_protocol_initializer_declaration} > 协议构造器声明语法 > > ###### protocol-initializer-declaration {#protocol-initializer-declaration} @@ -1072,7 +1072,7 @@ subscript (参数列表) -> 返回类型 { get set } 另请参阅 [下标声明](#subscript_declaration)。 -###### {#grammer_of_a_protocol_subscript_declaration} +###### grammer_of_a_protocol_subscript_declaration {#grammer_of_a_protocol_subscript_declaration} > 协议下标声明语法 > > ###### protocol-subscript-declaration {#protocol-subscript-declaration} @@ -1103,7 +1103,7 @@ protocol SubProtocolB: SomeProtocol where SomeType: Equatable { } 另请参阅 [类型别名声明](#type_alias_declaration)。 -###### {#grammer_of_a_protocol_associated_type_declaration} +###### grammer_of_a_protocol_associated_type_declaration {#grammer_of_a_protocol_associated_type_declaration} > 协议关联类型声明语法 > > ###### protocol-associated-type-declaration {#protocol-associated-type-declaration} @@ -1194,7 +1194,7 @@ if let actualInstance = SomeStruct(input: "Hello") { 更多关于可失败构造器的信息和例子,请参阅 [可失败构造器](../chapter2/14_Initialization.md#failable_initializers)。 -###### {#grammer_of_an_initializer_declaration} +###### grammer_of_an_initializer_declaration {#grammer_of_an_initializer_declaration} > 构造器声明语法 > > ###### initializer-declaration {#initializer-declaration} @@ -1233,7 +1233,7 @@ deinit { 关于如何在类声明中使用析构器的例子,请参阅 [析构过程](../chapter2/15_Deinitialization.md)。 -###### {#grammer_of_a_deinitializer_declaration} +###### grammer_of_a_deinitializer_declaration {#grammer_of_a_deinitializer_declaration} > 析构器声明语法 > > ###### deinitializer-declaration {#deinitializer-declaration} @@ -1416,7 +1416,7 @@ extension Array: Loggable where Element: MarkedLoggable { } // 报错: redundant conformance of 'Array' to protocol 'Loggable' ``` -###### {#grammer_of_an_extension_declaration} +###### grammer_of_an_extension_declaration {#grammer_of_an_extension_declaration} > 扩展声明语法 > > @@ -1464,7 +1464,7 @@ subscript (参数列表) -> 返回类型 { 更多关于下标的信息和例子,请参阅 [下标](../chapter2/12_Subscripts.md)。 -###### {#grammer_of_a_subscript_declaration} +###### grammer_of_a_subscript_declaration {#grammer_of_a_subscript_declaration} > 下标声明语法 > > @@ -1524,13 +1524,13 @@ postfix operator 运算符名称 {} 声明了一个新的运算符以后,需要实现一个跟这个运算符同名的函数来实现这个运算符。如果是实现一个前缀或者后缀运算符,也必须使用相符的 `prefix` 或者 `postfix` 声明修饰符标记函数声明。如果是实现中缀运算符,则不需要使用 `infix` 声明修饰符标记函数声明。关于如何实现一个新的运算符的例子,请参阅 [自定义运算符](../chapter2/26_Advanced_Operators.md#custom_operators)。 -###### {#grammer_of_an_operator_declaration} +###### grammer_of_an_operator_declaration {#grammer_of_an_operator_declaration} > 运算符声明语法 > -###### {#operator-declaration} +###### operator-declaration {#operator-declaration} > *运算符声明* → [*前缀运算符声明*](#prefix-operator-declaration) | [*后缀运算符声明*](#postfix-operator-declaration) | [*中缀运算符声明*](#infix-operator-declaration) > -###### {#prefix-operator-declaration} +###### prefix-operator-declaration {#prefix-operator-declaration} > *前缀运算符声明* → **prefix** **运算符** [*运算符*](./02_Lexical_Structure.md#operator) **{** **}** > > ###### postfix-operator-declaration {#postfix-operator-declaration} @@ -1541,7 +1541,7 @@ postfix operator 运算符名称 {} > > *中缀运算符声明* → **infix** **运算符** [*运算符*](./02_Lexical_Structure.md#operator) **{** [*中缀运算符属性*](#infix-operator-attributes)可选 **}** > -###### {#infix-operator-group} +###### infix-operator-group {#infix-operator-group} > *中缀运算符组* → [*优先级组名称*](#precedence-group-name) > @@ -1571,16 +1571,16 @@ Swift 定义了大量的优先级组来与标准库的运算符配合使用, 优先级组的赋值性表示在包含可选链操作时的运算符优先级。当设为 true 时,与优先级组对应的运算符在可选链操作中使用和标准库中赋值运算符同样的分组规则,当设为 false 或者不设置,该优先级组的运算符与不赋值的运算符遵循同样的可选链规则。 -###### {#grammer_of_a_precedence_group_declaration} +###### grammer_of_a_precedence_group_declaration {#grammer_of_a_precedence_group_declaration} > 优先级组声明语法 > -###### {#precedence-group-declaration} +###### precedence-group-declaration {#precedence-group-declaration} > *优先级组声明* → **precedence**[*优先级组名称*](#precedence-group-name){[*多优先级组属性*](#precedence-group-attributes)可选 } > -###### {#precedence-group-attributes} +###### precedence-group-attributes {#precedence-group-attributes} > *优先级组属性* → [*优先级组属性*](#precedence-group-attribute)[*多优先级组属性*](#precedence-group-attributes)可选 **{** **}** > -###### {#precedence-group-attribute} +###### precedence-group-attribute {#precedence-group-attribute} > *优先级组属性* → [*优先级组关系*](#precedence-group-relation) > > *优先级组属性* → [*优先级组赋值性*](#precedence-group-assignment) @@ -1597,17 +1597,17 @@ Swift 定义了大量的优先级组来与标准库的运算符配合使用, > > *优先级组赋值* → **assignment:**[*布尔字面值*](./02_Lexical_Structure.md#boolean-literal) > -###### {#precedence-group-associativity} +###### precedence-group-associativity {#precedence-group-associativity} > *优先级组结合性* → **associativity:left** > > *优先级组结合性* → **associativity:right** > > *优先级组结合性* → **associativity:none** > -###### {#precedence-group-names} +###### precedence-group-names {#precedence-group-names} > *多优先级组名称* → [*优先级组名称*](#precedence-group-name) | [*优先级组名称*](#precedence-group-name) | [*优先级组名称*](#precedence-group-name) > -###### {#precedence-group-name} +###### precedence-group-name {#precedence-group-name} > *优先级组名称* →[*标识符*](./02_Lexical_Structure.md#identifier) > @@ -1671,10 +1671,10 @@ Swift 提供了三个级别的访问控制:`public`、`internal` 和 `private` 以上访问级别修饰符都可以选择带上一个参数,该参数由一对圆括号和其中的 `set` 关键字组成(例如,`private(set)`)。使用这种形式的访问级别修饰符来限制某个属性或下标的 setter 的访问级别低于其本身的访问级别,正如 [Getter 和 Setter](../chapter2/25_Access_Control.md#getters_and_setters) 中所讨论的。 -###### {#grammer_of_a_declaration_modifier} +###### grammer_of_a_declaration_modifier {#grammer_of_a_declaration_modifier} > 声明修饰符的语法 > -###### {#declaration-modifier} +###### declaration-modifier {#declaration-modifier} > *声明修饰符* → **class** | **convenience**| **dynamic** | **final** | **infix** | **lazy** | **mutating** | **nonmutating** | **optional** | **override** | **postfix** | **prefix** | **required** | **static** | **unowned** | **unowned ( safe )** | **unowned ( unsafe )** | **weak** > > 声明修饰符 → [*访问级别修饰符*](#access-level-modifier) @@ -1683,7 +1683,7 @@ Swift 提供了三个级别的访问控制:`public`、`internal` 和 `private` > > *声明修饰符列表* → [*声明修饰符*](#declaration-modifier) [*声明修饰符列表*](#declaration-modifiers)可选 > -###### {#access-level-modifier} +###### access-level-modifier {#access-level-modifier} > 访问级别修饰符 → **internal** | **internal ( set )** > > 访问级别修饰符 → **private** | **private ( set )** diff --git a/source/chapter3/08_Patterns.md b/source/chapter3/08_Patterns.md index e44017b1..00e631a6 100755 --- a/source/chapter3/08_Patterns.md +++ b/source/chapter3/08_Patterns.md @@ -10,7 +10,7 @@ Swift 中的模式分为两类:一种能成功匹配任何类型的值,另 > 模式语法 > -###### {#pattern} +###### pattern {#pattern} > *模式* → [*通配符模式*](#wildcard_pattern) [*类型标注*](03_Types.md#type-annotation)可选 > > *模式* → [*标识符模式*](#identifier_pattern) [*类型标注*](03_Types.md#type-annotation)可选 @@ -40,7 +40,7 @@ for _ in 1...3 { > 通配符模式语法 > -###### {#wildcard-pattern} +###### wildcard-pattern {#wildcard-pattern} > *通配符模式* → **_** > @@ -57,7 +57,7 @@ let someValue = 42 > 标识符模式语法 > -###### {#identifier-pattern} +###### identifier-pattern {#identifier-pattern} > *标识符模式* → [*标识符*](./02_Lexical_Structure.md#identifier) > @@ -80,7 +80,7 @@ case let (x, y): > 值绑定模式语法 > -###### {#value-binding-pattern} +###### value-binding-pattern {#value-binding-pattern} > *值绑定模式* → **var** [*模式*](#pattern) | **let** [*模式*](#pattern) > @@ -109,13 +109,13 @@ let (a): Int = 2 // a: Int = 2 > 元组模式语法 > -###### {#tuple-pattern} +###### tuple-pattern {#tuple-pattern} > *元组模式* → **(** [*元组模式元素列表*](#tuple-pattern-element-list)可选 **)** > -###### {#tuple-pattern-element-list} +###### tuple-pattern-element-list {#tuple-pattern-element-list} > *元组模式元素列表* → [*元组模式元素*](#tuple-pattern-element) | [*元组模式元素*](#tuple-pattern-element) **,** [*元组模式元素列表*](#tuple-pattern-element-list) > -###### {#tuple-pattern-element} +###### tuple-pattern-element {#tuple-pattern-element} > *元组模式元素* → [*模式*](#pattern) > @@ -126,7 +126,7 @@ let (a): Int = 2 // a: Int = 2 > 枚举用例模式语法 > -###### {#enum-case-pattern} +###### enum-case-pattern {#enum-case-pattern} > *枚举用例模式* → [*类型标识*](./03_Types.md#type-identifier)可选 **.** [*枚举用例名*](./06_Declarations.md#enum-case-name) [*元组模式*](#tuple-pattern)可选 > @@ -163,7 +163,7 @@ for case let number? in arrayOfOptinalInts { > 可选模式语法 > -###### {#optional-pattern} +###### optional-pattern {#optional-pattern} > *可选模式* → [*标识符模式*](./03_Types.md#type-identifier) **?** > @@ -183,13 +183,13 @@ for case let number? in arrayOfOptinalInts { > 类型转换模式语法 > -###### {#type-casting-pattern} +###### type-casting-pattern {#type-casting-pattern} > *类型转换模式* → [*is 模式*](#is-pattern) | [*as 模式*](#as-pattern) > -###### {#is-pattern} +###### is-pattern {#is-pattern} > *is 模式* → **is** [*类型*](./03_Types.md#type) > -###### {#as-pattern} +###### as-pattern {#as-pattern} > *as 模式* → [*模式*](#pattern) **as** [*类型*](03_Types.md#type) > @@ -231,6 +231,6 @@ default: > 表达式模式语法 > -###### {#expression-pattern} +###### expression-pattern {#expression-pattern} > *表达式模式* → [*表达式*](./04_Expressions.md#expression) > diff --git a/source/chapter3/09_Generic_Parameters_and_Arguments.md b/source/chapter3/09_Generic_Parameters_and_Arguments.md index 70a72307..0d0e5acc 100755 --- a/source/chapter3/09_Generic_Parameters_and_Arguments.md +++ b/source/chapter3/09_Generic_Parameters_and_Arguments.md @@ -56,13 +56,13 @@ simpleMax(3.14159, 2.71828) // T 被推断为 Double 类型 > 泛型形参子句语法 > -###### {#generic-parameter-clause} +###### generic-parameter-clause {#generic-parameter-clause} > *泛型形参子句* → **<** [*泛型形参列表*](#generic-parameter-list) [*约束子句*](#requirement-clause)可选 **>** > -###### {#generic-parameter-list} +###### generic-parameter-list {#generic-parameter-list} > *泛型形参列表* → [*泛形形参*](#generic-parameter) | [*泛形形参*](#generic-parameter) **,** [*泛型形参列表*](#generic-parameter-list) > -###### {#generic-parameter} +###### generic-parameter {#generic-parameter} > *泛形形参* → [*类型名称*](./03_Types.md#type-name) > > *泛形形参* → [*类型名称*](./03_Types.md#type-name) **:** [*类型标识符*](./03_Types.md#type-identifier) @@ -73,10 +73,10 @@ simpleMax(3.14159, 2.71828) // T 被推断为 Double 类型 > > *约束子句* → **where** [*约束列表*](#requirement-list) > -###### {#requirement-list} +###### requirement-list {#requirement-list} > *约束列表* → [*约束*](#requirement) | [*约束*](#requirement) **,** [*约束列表*](#requirement-list) > -###### {#requirement} +###### requirement {#requirement} > *约束* → [*一致性约束*](#conformance-requirement) | [*同类型约束*](#same-type-requirement) > > ###### conformance-requirement {#conformance-requirement} @@ -85,7 +85,7 @@ simpleMax(3.14159, 2.71828) // T 被推断为 Double 类型 > > *一致性约束* → [*类型标识符*](./03_Types.md#type-identifier) **:** [*协议合成类型*](./03_Types.md#protocol-composition-type) > -###### {#same-type-requirement} +###### same-type-requirement {#same-type-requirement} > *同类型约束* → [*类型标识符*](./03_Types.md#type-identifier) **==** [*类型*](./03_Types.md#type) > @@ -116,12 +116,12 @@ let arrayOfArrays: Array> = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] > 泛型实参子句语法 > -###### {#generic-argument-clause} +###### generic-argument-clause {#generic-argument-clause} > *泛型实参子句* → **<** [*泛型实参列表*](#generic-argument-list) **>** > -###### {#generic-argument-list} +###### generic-argument-list {#generic-argument-list} > *泛型实参列表* → [*泛型实参*](#generic-argument) | [*泛型实参*](#generic-argument) **,** [*泛型实参列表*](#generic-argument-list) > -###### {#generic-argument} +###### generic-argument {#generic-argument} > *泛型实参* → [*类型*](./03_Types.md#type) >