import { infixFunctions, unaryFunctions } from "./operators.js"; export type Location = { line: number; column: number; offset: number; }; export type LocationRange = { source: string; start: Location; end: Location; }; export type ParseOptions = { grammarSource: string; addComment: (comment: ASTCommentNode) => void; }; export type InfixOperator = keyof typeof infixFunctions; export type UnaryOperator = keyof typeof unaryFunctions; export type TypeOperator = "*" | "/"; type N = { kind: T; location: LocationRange; } & V; type NodeProgram = N<"Program", { imports: NodeImport[]; statements: AnyStatementNode[]; result: AnyExpressionNode | null; symbols: { [k in string]: ASTNode; }; }>; type NodeBlock = N<"Block", { statements: AnyStatementNode[]; result: AnyExpressionNode; }>; type NodeImport = N<"Import", { path: NodeString; variable: NodeIdentifier; }>; type NodeArray = N<"Array", { elements: AnyExpressionNode[]; }>; type NodeDict = N<"Dict", { elements: AnyNodeDictEntry[]; }>; type NodeKeyValue = N<"KeyValue", { key: AnyExpressionNode; value: AnyExpressionNode; }>; export type AnyNodeDictEntry = NodeKeyValue | NodeIdentifier; type NodeUnitValue = N<"UnitValue", { value: NodeFloat; unit: string; }>; type NodeCall = N<"Call", { fn: AnyExpressionNode; args: AnyExpressionNode[]; }>; type NodeInfixCall = N<"InfixCall", { op: InfixOperator; args: [AnyExpressionNode, AnyExpressionNode]; }>; type NodeUnaryCall = N<"UnaryCall", { op: UnaryOperator; arg: AnyExpressionNode; }>; type NodePipe = N<"Pipe", { leftArg: AnyExpressionNode; fn: AnyExpressionNode; rightArgs: AnyExpressionNode[]; }>; type NodeDotLookup = N<"DotLookup", { arg: AnyExpressionNode; key: string; }>; type NodeBracketLookup = N<"BracketLookup", { arg: AnyExpressionNode; key: AnyExpressionNode; }>; type NodeFloat = N<"Float", { integer: number; fractional: string | null; exponent: number | null; }>; type NodeLambdaParameter = N<"LambdaParameter", { variable: NodeIdentifier; annotation: AnyExpressionNode | null; unitTypeSignature: NodeUnitTypeSignature | null; }>; type NodeIdentifier = N<"Identifier", { value: string; }>; type NodeUnitName = N<"UnitName", { value: string; }>; type NodeDecorator = N<"Decorator", { name: NodeIdentifier; args: AnyExpressionNode[]; }>; type LetOrDefun = { decorators: NodeDecorator[]; variable: NodeIdentifier; exported: boolean; }; type NodeLetStatement = N<"LetStatement", LetOrDefun & { unitTypeSignature: NodeUnitTypeSignature | null; value: AnyExpressionNode; }>; type NodeDefunStatement = N<"DefunStatement", LetOrDefun & { value: NamedNodeLambda; }>; type NodeLambda = N<"Lambda", { args: NodeLambdaParameter[]; body: AnyExpressionNode; name: string | null; returnUnitType: NodeUnitTypeSignature | null; }>; export type NamedNodeLambda = NodeLambda & Required>; type NodeTernary = N<"Ternary", { condition: AnyExpressionNode; trueExpression: AnyExpressionNode; falseExpression: AnyExpressionNode; syntax: "IfThenElse" | "C"; }>; type NodeUnitTypeSignature = N<"UnitTypeSignature", { body: AnyUnitTypeNode; }>; type NodeInfixUnitType = N<"InfixUnitType", { op: TypeOperator; args: [AnyUnitTypeNode, AnyUnitTypeNode]; }>; type NodeExponentialUnitType = N<"ExponentialUnitType", { base: AnyUnitTypeNode; exponent: NodeFloat; }>; type NodeString = N<"String", { value: string; }>; type NodeBoolean = N<"Boolean", { value: boolean; }>; export type ASTNode = NodeProgram | NodeImport | NodeBlock | NodeLetStatement | NodeDefunStatement | NodeLambda | NodeArray | NodeDict | NodeKeyValue | NodeUnitValue | NodeCall | NodeInfixCall | NodeUnaryCall | NodePipe | NodeDecorator | NodeDotLookup | NodeBracketLookup | NodeTernary | NodeUnitTypeSignature | NodeInfixUnitType | NodeExponentialUnitType | NodeUnitName | NodeIdentifier | NodeLambdaParameter | NodeFloat | NodeString | NodeBoolean; export type ASTCommentNode = { kind: "lineComment" | "blockComment"; value: string; location: LocationRange; }; export type Kind = ASTNode["kind"]; export type KindNode = Extract; export declare const statementKinds: ["LetStatement", "DefunStatement"]; export declare const expressionKinds: ["Block", "Lambda", "Array", "Dict", "UnitValue", "Call", "InfixCall", "UnaryCall", "Pipe", "DotLookup", "BracketLookup", "Ternary", "Identifier", "Float", "String", "Boolean"]; export declare const unitTypeKinds: ["UnitName", "Float", "InfixUnitType", "ExponentialUnitType"]; export type AnyStatementNode = KindNode<(typeof statementKinds)[number]>; export type AnyExpressionNode = KindNode<(typeof expressionKinds)[number]>; export type AnyUnitTypeNode = KindNode<(typeof unitTypeKinds)[number]>; export type AST = KindNode<"Program"> & { comments: ASTCommentNode[]; }; export {}; //# sourceMappingURL=types.d.ts.map