@ ampress/ast 类型
这个软件包为AST(Abstract Clicular Tree)节点和代码生成作者提供了常见的界面,在Ampression中使用了不同语言特有的AST软件包.
接口
IAst节点
Amplex AST系统中所有AST节点的基础接口.
interface IAstNode {
/**
* Writes the AST node to the given writer.
* @param writer The writer to write to
*/
write(writer: IWriter): void;
}
IWriter 编辑器
用于处理适当缩进和格式化的代码生成作者的接口.
interface IWriter {
/**
* Writes text to the output buffer with proper indentation
* @param text The text to write
*/
write(text: string): void;
/**
* Writes an AST node to the output buffer
* @param node The AST node to write
*/
writeNode(node: IAstNode): void;
/**
* Writes text followed by a newline if the last line wasn't a newline
* @param text Optional text to write before the newline
*/
writeLine(text?: string): void;
/**
* Writes a newline to the output buffer
*/
newLine(): void;
/**
* Writes a newline if the last line wasn't a newline
*/
writeNewLineIfLastLineNot(): void;
/**
* Increases the indentation level
*/
indent(): void;
/**
* Decreases the indentation level
*/
dedent(): void;
/**
* Returns the current contents of the output buffer
*/
toString(): string;
}
使用量
此软件包被语言特定 AST 软件包使用, 如 @amplication/csharp-ast 财务报告和审定财务报表 @amplication/java-ast 确保不同语言之间一致的AST节点和编剧执行.
特定语言包中的实例用法 :
import { IAstNode, IWriter } from '@amplication/ast-types';
export class MyAstNode implements IAstNode {
write(writer: IWriter): void {
writer.write('// My AST node implementation');
}
}
发展
大楼
nx build ast-types
测试
nx test ast-types
线性
nx lint ast-types