import type * as Ast from "./ast"; import { astNumToString, idText } from "./ast-helpers"; export declare const ppAstTypeId: typeof idText; export declare const ppAstTypeIdWithStorage: (type: Ast.TypeId, storageType: Ast.Id | undefined) => string; export declare const ppAstMapType: ({ keyType, keyStorageType, valueType, valueStorageType, }: Ast.MapType) => string; export declare const ppAstBouncedMessageType: ({ messageType, }: Ast.BouncedMessageType) => string; export declare const ppAstOptionalType: ({ typeArg }: Ast.OptionalType) => string; export declare const ppAstType: (input: Ast.Type) => string; export declare const unaryOperatorType: Record; export declare const checkPostfix: (operator: Ast.UnaryOperation) => boolean; /** * Description of precedence of certain type of AST node */ export type Precedence = { /** * Add parentheses around `code` if in this `parent` position we need brackets * @param check Position-checking function from parent * @param code Code to put parentheses around * @returns */ brace: (position: (childPrecedence: number) => boolean, code: string) => string; /** * Used in positions where grammar rule mentions itself * * Passed down when a position allows same unparenthesized operator * For example, on left side of addition we can use another addition without * parentheses: `1 + 2 + 3` means `(1 + 2) + 3`. Thus for left-associative * operators we pass `self` to their left argument printer. */ self: (childPrecedence: number) => boolean; /** * Used in positions where grammar rule mentions other rule * * Passed down when a position disallows same unparenthesized operator * For example, on the right side of subtraction we can't use another subtraction * without parentheses: `1 - (2 - 3)` is not the same as `(1 - 2) - 3`. Thus for * left-associative operators we pass `child` to their right argument printer. */ child: (childPrecedence: number) => boolean; }; /** * Given numeric value of precedence, where higher values stand for higher binding power, * create a helper object for precedence checking */ export declare const makePrecedence: (myPrecedence: number) => Precedence; export declare const lowestPrecedence: Precedence; export declare const conditionalPrecedence: Precedence; export declare const binaryPrecedence: Readonly>; export declare const prefixPrecedence: Precedence; export declare const postfixPrecedence: Precedence; /** * Expression printer takes an expression and a function from parent AST node printer that checks * whether expressions with given precedence should be parenthesized in parent context */ export type ExprPrinter = (expr: T) => (check: (childPrecedence: number) => boolean) => string; /** * Wrapper for AST nodes that should never be parenthesized, and thus do not require information * about the position they're printed in * * Takes a regular printer function and returns corresponding ExprPrinter that ignores all * position and precedence information */ export declare const ppLeaf: (printer: (t: T) => string) => ExprPrinter; export declare const ppExprArgs: (args: readonly Ast.Expression[]) => string; export declare const ppAstStructFieldInit: (param: Ast.StructFieldInitializer) => string; export declare const ppAstStructFieldValue: (param: Ast.StructFieldValue) => string; export declare const ppAstStructInstance: ({ type, args }: Ast.StructInstance) => string; export declare const ppAstStructValue: ({ type, args }: Ast.StructValue) => string; export declare const ppAstInitOf: ({ contract, args }: Ast.InitOf) => string; export declare const ppAstCodeOf: ({ contract }: Ast.CodeOf) => string; export declare const ppAstNumber: typeof astNumToString; export declare const ppAstBoolean: ({ value }: Ast.Boolean) => string; export declare const ppAstId: ({ text }: Ast.Id) => string; export declare const ppAstOptionalId: (node: Ast.OptionalId) => string; export declare const ppAstNull: (_expr: Ast.Null) => string; export declare const ppAstString: ({ value }: Ast.String) => string; export declare const ppAstAddress: ({ value }: Ast.Address) => string; export declare const ppAstCell: ({ value }: Ast.Cell) => string; export declare const ppAstSlice: ({ value }: Ast.Slice) => string; export declare const ppAstMapLiteral: ({ type, fields }: Ast.MapLiteral) => string; export declare const ppAstSetLiteral: ({ valueType, valueStorageType, fields, }: Ast.SetLiteral) => string; export declare const ppAstMapValue: (_: Ast.MapValue) => string; export declare const ppAstStaticCall: ({ function: func, args }: Ast.StaticCall) => string; export declare const ppAstMethodCall: ExprPrinter; export declare const ppAstFieldAccess: ExprPrinter; export declare const ppAstOpUnary: ExprPrinter; export declare const ppAstOpBinary: ExprPrinter; export declare const ppAstConditional: ExprPrinter; export declare const ppAstExpressionNested: (input: Ast.Expression) => (check: (childPrecedence: number) => boolean) => string; export declare const ppAstExpression: (expr: Ast.Expression) => string; export declare const ppAstWildcard: (_expr: Ast.Wildcard) => string; /** * An intermediate language that is only concerned of spacing and indentation */ type Context = { /** * Line of code with \n implied */ row: (s: string) => U; /** * Stacks lines after each other */ block: (rows: readonly U[]) => U; /** * Similar to `block`, but adjacent lines of groups get concatenated * [a, b] + [c, d] = [a, bc, d] */ concat: (rows: readonly U[]) => U; /** * Same as `indent`, but indents `rows` 1 level deeper and adds `{` and `}` */ braced: (rows: readonly U[]) => U; /** * Print a list of `items` with `print` */ list: (items: readonly T[], print: Printer) => readonly U[]; /** * Display `items` with `print` in groups distinguished by return value of `getTag` */ grouped: (options: { items: readonly T[]; /** * Items with the same tag are displayed without extra empty line between them * * Use NaN for tag whenever items should always be displayed with empty line, * because NaN !== NaN */ getTag: (t: T) => V; print: Printer; }) => readonly U[]; }; /** * Prints AST node of type `T` into an intermediate language of row of type `U` * * We enforce `U` to be a generic argument so that no implementation can (ab)use * the fact it's a string and generate some indentation without resorting to * methods of `Context`. */ type Printer = (item: T) => (ctx: Context) => U; export declare const ppAstModule: Printer; export declare const ppAstStruct: Printer; export declare const ppAstContract: Printer; export declare const ppAstPrimitiveTypeDecl: Printer; export declare const ppAstFunctionDef: Printer; export declare const ppAsmShuffle: ({ args, ret }: Ast.AsmShuffle) => string; export declare const ppAstAsmFunctionDef: Printer; export declare const ppAstNativeFunction: Printer; export declare const ppAstTrait: Printer; export declare const ppAstConstant: Printer; export declare const ppAstMessage: Printer; export declare const ppModuleItem: Printer; export declare const ppAstFieldDecl: Printer; export declare const ppAstReceiver: Printer; export declare const ppAstFunctionDecl: Printer; export declare const ppAstConstDecl: Printer; export declare const ppTraitBody: Printer; export declare const ppAstInitFunction: Printer; export declare const ppContractBody: Printer; export declare const ppAstImport: Printer; export declare const ppAstFunctionSignature: ({ name, attributes, return: retTy, params, }: Ast.FunctionDef | Ast.AsmFunctionDef | Ast.FunctionDecl) => string; export declare const ppAstFunctionAttribute: (attr: Ast.FunctionAttribute) => string; export declare const ppReceiverSubKind: (input: Ast.ReceiverSubKind) => string; export declare const ppAstReceiverKind: (input: Ast.ReceiverKind) => string; export declare const ppAstFuncId: (func: Ast.FuncId) => string; export declare const ppStatementBlock: Printer; export declare const ppAsmInstructionsBlock: Printer; export declare const ppAstStatementLet: Printer; export declare const ppAstStatementReturn: Printer; export declare const ppAstStatementExpression: Printer; export declare const ppAstStatementAssign: Printer; export declare const ppAstStatementAugmentedAssign: Printer; export declare const ppAstStatementCondition: Printer; export declare const ppAstStatementWhile: Printer; export declare const ppAstStatementRepeat: Printer; export declare const ppAstStatementUntil: Printer; export declare const ppAstStatementForEach: Printer; export declare const ppAstStatementTry: Printer; export declare const ppAstStatementDestruct: Printer; export declare const ppTypedParameter: Printer; export declare const ppAstStatementBlock: Printer; export declare const ppAstStatement: Printer; export declare const exprNode: (exprPrinter: (expr: T) => string) => Printer; export declare const ppAstNode: Printer; /** * Pretty-prints an AST node into a string representation. * @param node The AST node to format. * @returns A string that represents the formatted AST node. */ export declare const prettyPrint: (node: Ast.AstNode) => string; export {};