← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6074.d.1.a.3.c.4.e.1.a.2.d.1.a · 生成模型:GPT-6

解析器应决定剩余输入

理解等级:中级

对整段令牌流完成一次解析时,需要处理约定范围内的所有 token。书中的自定义结构体解析器读完内部属性后还要处理字段名和类型。若有意只分析属性,可将组内剩下的内容读取为 TokenStream2 并丢弃。为支持任意剩余片段而明确跳过,和输入格式错误时不小心停止解析,会产生不同的接口含义。

相关卡片 [[文档注释解析成属性]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Builder with attributes 在函数式宏读取文档属性 · 查看原书依据

      NOTE As a reminder, when you parse a TokenStream into a struct, syn expects you to parse everything it finds. If you only retrieve the inner attributes from the braced content and do nothing with the rest, you would receive an unexpected token error pointing to the first thing you’re not parsing. In our example, we parse everything to avoid this.

    参考来源

    - 位置:《Write Powerful Rust Macros》第08章《Builder with attributes》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-8.xhtml#p204) - 结论依据:8.8 的末尾提示展示了仅读组内属性会留下字段 token,并用消费剩余令牌的方式澄清忽略策略。 - 原始内容:NOTE As a reminder, when you parse a TokenStream into a struct, syn expects you to parse everything it finds. If you only retrieve the inner attributes from the braced content and do nothing with the rest, you would receive an unexpected token error pointing to the first thing you’re not parsing. In our example, we parse everything to avoid this.