import AssignmentNode from "./ast/AssignmentNode"; import ASTVisitor from "./ast/ASTVisitor"; import ErrorNode from "./ast/ErrorNode"; import { AnonymousFunctionExpr, ArrayLookupExpr, AssertExpr, BinaryOpExpr, EchoExpr, FunctionCallExpr, GroupingExpr, LcEachExpr, LcForCExpr, LcForExpr, LcIfExpr, LcLetExpr, LetExpr, LiteralExpr, LookupExpr, MemberLookupExpr, RangeExpr, TernaryExpr, UnaryOpExpr, VectorExpr } from "./ast/expressions"; import ScadFile from "./ast/ScadFile"; import { BlockStmt, FunctionDeclarationStmt, IfElseStatement, IncludeStmt, ModuleDeclarationStmt, ModuleInstantiationStmt, NoopStmt, Statement, UseStmt } from "./ast/statements"; import FormattingConfiguration from "./FormattingConfiguration"; import Token from "./Token"; export default class ASTPrinter implements ASTVisitor { config: FormattingConfiguration; indentLevel: number; breakBetweenModuleInstantations: boolean; firstModuleInstantation: boolean; doNotAddNewlineAfterBlockStatement: boolean; /** * We store data that is global between all the copies of the ASTPrinter in an object so that it is passed by reference. */ deepGlobals: { didAddNewline: boolean; shouldAddNewlineAfterNextComment: boolean; newlineAfterNextCommentReason: string; }; constructor(config: FormattingConfiguration); visitErrorNode(n: ErrorNode): string; visitScadFile(n: ScadFile): string; visitAssignmentNode(n: AssignmentNode): string; visitUnaryOpExpr(n: UnaryOpExpr): string; visitBinaryOpExpr(n: BinaryOpExpr): string; visitTernaryExpr(n: TernaryExpr): string; visitArrayLookupExpr(n: ArrayLookupExpr): string; visitLiteralExpr(n: LiteralExpr): string; visitRangeExpr(n: RangeExpr): string; visitVectorExpr(n: VectorExpr): string; visitLookupExpr(n: LookupExpr): string; visitMemberLookupExpr(n: MemberLookupExpr): string; visitFunctionCallExpr(n: FunctionCallExpr): string; visitLetExpr(n: LetExpr): string; visitAssertExpr(n: AssertExpr): string; visitEchoExpr(n: EchoExpr): string; visitLcIfExpr(n: LcIfExpr): string; visitLcEachExpr(n: LcEachExpr): string; visitLcForExpr(n: LcForExpr): string; visitLcForCExpr(n: LcForCExpr): string; visitLcLetExpr(n: LcLetExpr): string; visitGroupingExpr(n: GroupingExpr): string; visitUseStmt(n: UseStmt): string; visitIncludeStmt(n: IncludeStmt): string; visitModuleInstantiationStmt(n: ModuleInstantiationStmt): string; visitModuleDeclarationStmt(n: ModuleDeclarationStmt): string; visitFunctionDeclarationStmt(n: FunctionDeclarationStmt): string; visitBlockStmt(n: BlockStmt): string; visitNoopStmt(n: NoopStmt): string; visitIfElseStatement(n: IfElseStatement): string; visitAnonymousFunctionExpr(n: AnonymousFunctionExpr): string; /** * Tries printing a ModuleInstantiationStmt without breaking it, if it exceeds 40 chars it breaks it, by printing it again. * @param stmt */ protected processStatementWithBreakIfNeeded(stmt: Statement): string; protected stringifyExtraTokens(token: Token): string; protected newLine(forced?: boolean, newlineReason?: string): string; /** * Schedules a newline to be added after the next comment, if present. * Otherwise it will be inserted immediately. */ protected newLineAfterNextComment(reason: string): void; protected makeIndent(): string; protected copy(): ASTPrinter; protected copyWithIndent(): ASTPrinter; protected copyWithBreakBetweenModuleInstantations(doBreak?: boolean): ASTPrinter; protected copyWithDoNotAddNewlineAfterBlockStatement(val?: boolean): ASTPrinter; protected saveDeepGlobals(): any; protected restoreDeepGlobals(dat: any): void; }