//#region src/nodes.d.ts declare const NodeTypeCatalog: { readonly block: 0; readonly binaryExpr: 1; readonly assignmentExpr: 2; readonly logicalExpr: 3; readonly unaryExpr: 4; readonly numericLiteral: 5; readonly call: 6; readonly memberAccess: 7; readonly indexAccess: 8; readonly return: 10; readonly if: 11; readonly let: 12; readonly const: 13; readonly for: 14; readonly while: 15; readonly continue: 16; readonly break: 17; readonly forOf: 18; readonly arrayExpr: 100; readonly preUpdate: 101; readonly postUpdate: 102; readonly stringLiteral: 103; readonly objectExpr: 104; readonly conditionalExpr: 105; }; type NodeTypeCatalog = typeof NodeTypeCatalog; /** * Represents a return statement */ type Return = readonly [type: NodeTypeCatalog['return'], expr: Expression] | readonly [type: NodeTypeCatalog['return']]; /** * Represents an if statement */ type If = readonly [type: NodeTypeCatalog['if'], cond: Expression, then: Statement] | readonly [type: NodeTypeCatalog['if'], cond: Expression, then: Statement, alt: Statement]; /** * Represents a block of statements */ type Block = readonly [type: NodeTypeCatalog['block'], Statement[]]; /** * Represents a let statement */ type Let = readonly [type: NodeTypeCatalog['let'], identifier: string] | readonly [type: NodeTypeCatalog['let'], identifier: string, value: Expression]; /** * Represents a const statement */ type Const = readonly [type: NodeTypeCatalog['const'], identifier: string] | readonly [type: NodeTypeCatalog['const'], identifier: string, value: Expression]; type For = readonly [type: NodeTypeCatalog['for'], init: Statement | null, condition: Expression | null, update: Statement | null, body: Statement]; type While = readonly [type: NodeTypeCatalog['while'], condition: Expression, body: Statement]; type Continue = readonly [type: NodeTypeCatalog['continue']]; type Break = readonly [type: NodeTypeCatalog['break']]; type ForOf = readonly [type: NodeTypeCatalog['forOf'], left: Const | Let, right: Expression, body: Statement]; /** * A union type of all statements */ type Statement = Return | If | Block | Let | Const | Expression | For | While | Continue | Break | ForOf; type BinaryOperator = '==' | '!=' | '===' | '!==' | '<' | '<=' | '>' | '>=' | '<<' | '>>' | '>>>' | '+' | '-' | '*' | '/' | '%' | '|' | '^' | '&' | 'in' | 'instanceof' | '**'; type BinaryExpression = readonly [type: NodeTypeCatalog['binaryExpr'], lhs: Expression, op: BinaryOperator, rhs: Expression]; type AssignmentOperator = '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '<<=' | '>>=' | '|=' | '^=' | '&=' | '**=' | '||=' | '&&=' | '>>>=' | '??='; type AssignmentExpression = readonly [type: NodeTypeCatalog['assignmentExpr'], lhs: Expression, op: AssignmentOperator, rhs: Expression]; type LogicalOperator = '&&' | '||' | '??'; type LogicalExpression = readonly [type: NodeTypeCatalog['logicalExpr'], lhs: Expression, op: LogicalOperator, rhs: Expression]; type UnaryOperator = '-' | '+' | '!' | '~' | 'typeof' | 'void' | 'delete'; type UnaryExpression = readonly [type: NodeTypeCatalog['unaryExpr'], op: UnaryOperator, inner: Expression]; type ObjectExpression = readonly [type: NodeTypeCatalog['objectExpr'], Record]; type ArrayExpression = readonly [type: NodeTypeCatalog['arrayExpr'], values: Expression[]]; type ConditionalExpression = readonly [type: NodeTypeCatalog['conditionalExpr'], test: Expression, consequent: Expression, alternative: Expression]; type MemberAccess = readonly [type: NodeTypeCatalog['memberAccess'], object: Expression, member: string]; type IndexAccess = readonly [type: NodeTypeCatalog['indexAccess'], object: Expression, property: Expression]; type Call = readonly [type: NodeTypeCatalog['call'], identifier: Expression, args: Expression[]]; type PostUpdate = readonly [type: NodeTypeCatalog['postUpdate'], operator: '++' | '--', argument: Expression]; type PreUpdate = readonly [type: NodeTypeCatalog['preUpdate'], operator: '++' | '--', argument: Expression]; /** A numeric literal */ type Num = readonly [type: NodeTypeCatalog['numericLiteral'], string]; /** A string literal */ type Str = readonly [type: NodeTypeCatalog['stringLiteral'], string]; type Literal = Num | Str | boolean; /** Identifiers are just strings, since string literals are rare in WGSL, and identifiers are everywhere. */ type Expression = string | BinaryExpression | AssignmentExpression | LogicalExpression | UnaryExpression | ObjectExpression | MemberAccess | IndexAccess | ArrayExpression | ConditionalExpression | PreUpdate | PostUpdate | Call | Literal; type AnyNode = Statement | Expression; declare const FuncParameterType: { readonly identifier: "i"; readonly destructuredObject: "d"; }; type FuncParameter = { type: typeof FuncParameterType.identifier; name: string; } | { type: typeof FuncParameterType.destructuredObject; props: { name: string; alias: string; }[]; }; //#endregion export { AnyNode, ArrayExpression, AssignmentExpression, AssignmentOperator, BinaryExpression, BinaryOperator, Block, Break, Call, ConditionalExpression, Const, Continue, Expression, For, ForOf, FuncParameter, FuncParameterType, If, IndexAccess, Let, Literal, LogicalExpression, LogicalOperator, MemberAccess, NodeTypeCatalog, Num, ObjectExpression, PostUpdate, PreUpdate, Return, Statement, Str, UnaryExpression, UnaryOperator, While };