Skip to content

Commit b097d6a

Browse files
committed
wip: Macro Declaration
1 parent ac13ed5 commit b097d6a

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

swift-6-beta.docc/ReferenceManual/Declarations.md

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,39 +2634,29 @@ subscript (<#parameters#>) -> <#return type#> {
26342634
> *下标头**属性*_?_ *声明修饰符*_?_ **`下标`** *泛型参数子句*_?_ *参数子句* \
26352635
> *下标结果***`->`** *属性*_?_ *类型*
26362636
2637-
## Macro Declaration
2637+
## 宏声明
26382638

2639-
A *macro declaration* introduces a new macro.
2640-
It begins with the `macro` keyword
2641-
and has the following form:
2639+
一个*宏声明*引入一个新的宏。它以 `macro` 关键字开始,具有以下形式:
26422640

26432641
```swift
26442642
macro <#name#> = <#macro implementation#>
26452643
```
26462644

2647-
The *macro implementation* is another macro,
2648-
and indicates the location of the code that performs this macro's expansion.
2649-
The code that performs macro expansion is a separate Swift program,
2650-
that uses the [SwiftSyntax][] module to interact with Swift code.
2651-
Call the `externalMacro(module:type:)` macro from the Swift standard library,
2652-
passing in the name of a type that contains the macro's implementation,
2653-
and the name of the module that contains that type.
2645+
*宏实现*是另一个宏,用于指示执行此宏扩展的代码位置。执行宏扩展的代码是一个独立的 Swift 程序,该程序使用 [SwiftSyntax][] 模块与 Swift 代码进行交互。调用 Swift 标准库中的 `externalMacro(module:type:)` 宏,并传入包含宏实现的类型名称以及包含该类型的模块名称。
26542646

26552647
[SwiftSyntax]: http://github.com/apple/swift-syntax/
26562648

2657-
Macros can be overloaded,
2658-
following the same model used by functions.
2659-
A macro declaration appears only at file scope.
2649+
宏可以被重载,遵循与函数相同的模型。宏声明仅在文件作用域内出现。
26602650

2661-
For an overview of macros in Swift, see <doc:Macros>.
2651+
有关 Swift 中宏的概述,请参见 <doc:Macros>
26622652

2663-
> Grammar of a macro declaration:
2653+
> 宏声明的语法:
26642654
>
2665-
> *macro-declaration**macro-head* *identifier* *generic-parameter-clause*_?_ *macro-signature* *macro-definition*_?_ *generic-where-clause* \
2666-
> *macro-head**attributes*_?_ *declaration-modifiers*_?_ **`macro`** \
2667-
> *macro-signature**parameter-clause* *macro-function-signature-result*_?_ \
2668-
> *macro-function-signature-result***`->`** *type* \
2669-
> *macro-definition***`=`** *expression*
2655+
> *宏声明**宏头* *标识符* *泛型参数子句*_?_ *宏签名* *宏定义*_?_ *泛型约束子句* \
2656+
> *宏头**属性*_?_ *声明修饰符*_?_ **``** \
2657+
> *宏签名**参数子句* *宏函数签名结果*_?_ \
2658+
> *宏函数签名结果***`->`** *类型* \
2659+
> *宏定义***`=`** *表达式*
26702660
26712661
## Operator Declaration
26722662

0 commit comments

Comments
 (0)