名称: AST操作 描述: 抽象语法树设计、遍历、转换和操作模式的专家技能 类别: 编译器基础设施 允许的工具:
- 读取
- 写入
- 编辑
- Glob
- Grep
- Bash
AST操作技能
概述
抽象语法树设计、遍历、转换和操作模式的专家技能。
能力
- 设计类型化的AST节点层次结构
- 实现访问者和转换器模式
- 构建AST重写系统
- 实现AST差异比较和补丁
- 生成AST美化打印器和格式化器
- 支持AST序列化(JSON,二进制)
- 在AST结构上实现模式匹配
- 设计跨度/位置跟踪系统
目标流程
- ast-design.js
- semantic-analysis.js
- ir-design.js
- code-generation-llvm.js
- lsp-server-implementation.js
- macro-system-implementation.js
依赖项
无(核心技能)
使用指南
- 节点设计:设计具有明确所有权语义的不可变AST节点
- 位置跟踪:从一开始就在所有节点上包含源跨度
- 访问者模式:实现访问者模式以进行可扩展遍历
- 转换:使用转换器模式进行AST到AST的转换
- 序列化:支持人类可读(JSON)和高效(二进制)序列化
输出模式
{
"type": "object",
"properties": {
"nodeTypes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"fields": { "type": "array" },
"parent": { "type": "string" }
}
}
},
"visitors": {
"type": "array",
"items": { "type": "string" }
},
"transformers": {
"type": "array",
"items": { "type": "string" }
},
"generatedFiles": {
"type": "array",
"items": { "type": "string" }
}
}
}