Files
codex-bot f5268d2e09
Verify databases and deploy Aster VM / verify-and-deploy (push) Successful in 7m55s
feat: generate unified AST and editor contracts from ASDL
2026-10-19 14:31:28 +08:00

15 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 编辑器 AST 接口
这里的类型和遍历函数均从 [Endor.asdl](../Endor.asdl) 生成,不再维护第二份手写节点定义。
| 文件 | 职责 |
| --- | --- |
| [ast.ts](ast.ts) | TypeScript 节点类型、AST_SCHEMA_ID、Visitor 回调与 walk* 函数 |
| [ast.schema.json](ast.schema.json) | JSON Schema 2020-12;校验带 schema 标识的 AstDocument 结构 |
TypeScript 编译时类型不代替 JSON 校验。编辑器可使用现有 JSON Schema 工具校验文档,再交给类型与遍历接口;walk* 的回调返回 false 时跳过该节点的子树。可选字段允许省略或 null,Rust 的标准输出会写成 null。
所有位置为原文 UTF-8 字节范围,不是 JavaScript UTF-16 下标;编辑器需要以原文换算。JSON Schema 检查结构,父子范围关系和原文 UTF-8 边界由 Rust AstDocument::validate/validate_source 检查。schema 标识变化需要调用方升级契约,不提供隐式迁移。
在仓库根运行 `python3 scripts/generate_ast.py --write` 重新生成,--check 做静态同步检查。完整格式见 [AST 模型](../../../docs/runtime/ast.md)。返回 [frontend](../README.md)。