知识卡片
宏用固定词构成小语言
声明式 DSL 可把像 Give、from、to 的关键词和金额或账户标识符混排。匹配成功后生成普通方法调用,拼错关键词在编译期就会失败。原书的账户例子仅演示句法及方法调用,透支处理留在示例范围之外。领域校验有多强,取决于文法和生成代码实际实施的约束。
相关卡片 [[领域语言缩小表达范围]]、[[首条匹配决定展开]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
- · 文法及分支遮蔽
原书出处 · 1 处
- Declarative macros 文法及分支遮蔽 · 查看原书依据
Now check out the exchange macro in listing 2.13, which presents users with a mini-DSL. As you can see, this macro allows us to use natural language, understandable to outsiders, to describe actions.
参考来源
- 位置:《Write Powerful Rust Macros》第02章《Declarative macros》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-2.xhtml#p116)
- 结论依据:exchange 示例展示可读语句、固定词与片段,随后提醒覆盖重叠分支。
- 原始内容:Now check out the exchange macro in listing 2.13, which presents users with a mini-DSL. As you can see, this macro allows us to use natural language, understandable to outsiders, to describe actions.