|
1 |
| -<!-- |
2 |
| -要翻译的文件:https://github.com/SwiftGGTeam/the-swift-programming-language-in-chinese/blob/swift-6-beta-translation/swift-6-beta.docc/ReferenceManual/AboutTheLanguageReference.md |
3 |
| -Swift 文档源文件地址:https://docs.swift.org/swift-book/documentation/the-swift-programming-language/aboutthelanguagereference |
4 |
| -翻译估计用时:⭐️ |
5 |
| ---> |
| 1 | +# 关于语言参考 |
6 | 2 |
|
7 |
| -# About the Language Reference |
| 3 | +理解 Swift 语法描述中使用的标注。 |
8 | 4 |
|
9 |
| -Read the notation that the formal grammar uses. |
| 5 | +本书的这一部分介绍了 Swift 编程语言的语法结构。这里描述的语法旨在帮助你更深入地理解 Swift 语言的特性,而不是让你直接实现相关的解析器或编译器。 |
10 | 6 |
|
11 |
| -This part of the book describes the formal grammar of the Swift programming language. |
12 |
| -The grammar described here is intended to help you understand the language in more |
13 |
| -detail, rather than to allow you to directly implement a parser or compiler. |
| 7 | +与其他语言相比,Swift 语言还是相对精简的,这是因为 Swift 代码里的很多常见类型、函数和运算符实际上是在 Swift 标准库中定义的。尽管它们并不是 Swift 语言本身的一部分,但它们在本书的讨论和代码示例中被广泛使用。 |
14 | 8 |
|
15 |
| -The Swift language is relatively small, because many common types, functions, and operators |
16 |
| -that appear virtually everywhere in Swift code |
17 |
| -are actually defined in the Swift standard library. Although these types, functions, |
18 |
| -and operators aren't part of the Swift language itself, |
19 |
| -they're used extensively in the discussions and code examples in this part of the book. |
| 9 | +## 如何阅读语法 |
20 | 10 |
|
21 |
| -## How to Read the Grammar |
| 11 | +用于描述 Swift 编程语言的语法结构标注需要遵循以下几条约定: |
22 | 12 |
|
23 |
| -The notation used to describe the formal grammar of the Swift programming language |
24 |
| -follows a few conventions: |
| 13 | +- 箭头(→)用于标记语法生成规则,可以理解为“可以由……组成”。 |
| 14 | +- 语法类别以 *斜体* 文本表示,并出现在语法生成规则的两边。 |
| 15 | +- 字面单词和标点符用 **`加粗等宽字体`** 表示,并仅出现在语法生成规则的右侧。 |
| 16 | +- 可选的语法生成规则由竖线(|)分隔。当可选的生成规则过长而难以阅读时,它们会被拆分为多行新的语法生成规则。 |
| 17 | +- 在少数情况下,普通字体文本用于描述语法生成规则右侧的内容。 |
| 18 | +- 可选的语法类别和字面量由后缀问号 *?* 标记。 |
25 | 19 |
|
26 |
| -- An arrow (→) is used to mark grammar productions and can be read as "can consist of." |
27 |
| -- Syntactic categories are indicated by *italic* text and appear on both sides |
28 |
| - of a grammar production rule. |
29 |
| -- Literal words and punctuation are indicated by **`boldface constant width`** text |
30 |
| - and appear only on the right-hand side of a grammar production rule. |
31 |
| -- Alternative grammar productions are separated by vertical |
32 |
| - bars (|). When alternative productions are too long to read easily, |
33 |
| - they're broken into multiple grammar production rules on new lines. |
34 |
| -- In a few cases, regular font text is used to describe the right-hand side |
35 |
| - of a grammar production rule. |
36 |
| -- Optional syntactic categories and literals are marked by a trailing |
37 |
| - question mark, *?*. |
38 |
| - |
39 |
| -As an example, the grammar of a getter-setter block is defined as follows: |
| 20 | +例如,getter-setter 代码块的语法定义如下: |
40 | 21 |
|
41 | 22 | > Grammar of a getter-setter block:
|
42 | 23 | >
|
43 | 24 | > *getter-setter-block* → **`{`** *getter-clause* *setter-clause*_?_ **`}`** | **`{`** *setter-clause* *getter-clause* **`}`**
|
44 | 25 |
|
45 |
| -This definition indicates that a getter-setter block can consist of a getter clause |
46 |
| -followed by an optional setter clause, enclosed in braces, |
47 |
| -*or* a setter clause followed by a getter clause, enclosed in braces. |
48 |
| -The grammar production above is equivalent to the following two productions, |
49 |
| -where the alternatives are spelled out explicitly: |
| 26 | +这个定义表明 getter-setter 代码块可以由一个 getter 子句后跟一个可选的 setter 子句构成,并用大括号括起来, *或者* 由一个 setter 子句后跟一个 getter 子句构成,并用大括号括起来。上面的语法生成规则等价于以下两个生成规则,其中备选项也被明确列出: |
50 | 27 |
|
51 | 28 | > Grammar of a getter-setter block:
|
52 | 29 | >
|
53 |
| -> |
54 |
| -> *getter-setter-block* → **`{`** *getter-clause* *setter-clause*_?_ **`}`** \ |
| 30 | +> *getter-setter-block* → **`{`** *getter-clause* *setter-clause*_?_ **`}`** |
55 | 31 | > *getter-setter-block* → **`{`** *setter-clause* *getter-clause* **`}`**
|
56 | 32 |
|
57 |
| -> Beta Software: |
58 |
| -> |
59 |
| -> This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software. |
60 |
| -> |
61 |
| -> Learn more about using [Apple's beta software](https://developer.apple.com/support/beta-software/). |
62 | 33 |
|
63 |
| -<!-- |
64 |
| -This source file is part of the Swift.org open source project |
65 | 34 |
|
66 |
| -Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors |
67 |
| -Licensed under Apache License v2.0 with Runtime Library Exception |
| 35 | +> 测试版软件: |
| 36 | +> |
| 37 | +> 本文档包含有关正在开发的 API 或技术的初步信息。此信息可能会发生变化,根据本文档实施的软件应使用最终操作系统软件进行测试。 |
| 38 | +> |
| 39 | +> 了解有关使用 [Apple 测试版软件](https://developer.apple.com/support/beta-software/) 的更多信息. |
68 | 40 |
|
69 |
| -See https://swift.org/LICENSE.txt for license information |
70 |
| -See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
71 |
| ---> |
0 commit comments