Skip to main content

Crate xirang_macro

Crate xirang_macro 

Source
Expand description

Face field normalisation for the authoring macros. 为作者侧宏归一化注册面字段。

A macro_rules! matcher can only fail with “no rules expected ...”, and it cannot reorder fields, cannot compare field names, and cannot attach a span to a message of its own. This front end receives the author’s tokens with their spans, so it accepts , or ; separators, a forgotten separator and any field order, and still reports an unknown or repeated field on the exact token that carries it. macro_rules! 匹配失败只会说 “no rules expected ...”,既不能重排字段、不能 比较字段名,也无法把自己的消息挂到具体 token 上。本前端拿到的是带 span 的作者 token,因此接受 ,/;、漏写分隔符与任意顺序,并把“未知字段/重复字段“精确报在 出问题的那个 token 上。

Splitting is shared with the build-time reader (split_face_fields): the compiler and the build step must read one declaration the same way, so they use the same tolerant splitter. 切分逻辑与构建期读取器共用(split_face_fields):编译器与构建步骤必须对同一份 声明读出一致的字段,因此两者使用同一个宽容切分器。

The normalised declaration goes back through __xirang_object!, the exported entry point of the runtime crate, so the collector mode the caller chose survives the round trip. This front end is only reached when __control_object!’s single arm has already declined the declaration — a field out of order, ; separators, a misspelled name — so a well-formed face expands exactly as it did before. 归一化后的声明经 __xirang_object!(运行时 crate 的公开入口)回到宏阶梯, 调用方选择的 collector 模式因此得以保留。只有当 __control_object! 那唯一一条 arm 不接受时(字段顺序不同、用 ; 分隔、字段名拼错)才会走到本前端,因此合法注册面的展开 与从前完全一致。

The proc-macro entry points plus normalise stay on this page; the mirror emitter lives in mirror and the field/argument parsing helpers in front_end. 过程宏入口与 normalise 留在本页;镜像发射器位于 mirror,字段 / 参数解析辅助 函数位于 front_end。

Macros§

contracts
Check trait implementations and return their registration labels. 检查 trait 实现并返回注册标签。
face_fields
Rewrite one face declaration’s field list into its accepted order, with tolerant separators and spanned diagnostics. 把一条注册面声明的字段列表改写成它接受的顺序,容忍分隔符差异并给出带 span 的诊断。
face_rule_or
The registry_rule a face gets when it does not write one. 注册面没有写 registry_rule 时得到什么。
face_trait_labels_or
Labels for the traits a face declares, derived from the paths it wrote. 注册面声明实现的 trait 标签,从其写下的路径派生。

Attribute Macros§

soil
Register a native Rust Soil const without an editor-only mirror. 注册原生 Rust Soil 常量,不生成编辑器专用镜像。