/** * AST node types for Elo expressions */ export type Expr = Literal | NullLiteral | StringLiteral | Variable | BinaryOp | UnaryOp | DateLiteral | DateTimeLiteral | DurationLiteral | TemporalKeyword | FunctionCall | MemberAccess | LetExpr | IfExpr | Lambda | ObjectLiteral | ArrayLiteral | Alternative | Apply | DataPath | TypeDef | GuardExpr | DoCall; /** * do call (Relatr plugins v1) * * Parsed form: do 'cap.name' * Only valid inside plugin-program round bindings (not score). */ export interface DoCall { type: "do_call"; capName: string; argsExpr: Expr; } export declare function doCall(capName: string, argsExpr: Expr): DoCall; /** * Literal value (number or boolean) */ export interface Literal { type: "literal"; value: number | boolean; } /** * Null literal */ export interface NullLiteral { type: "null"; } /** * String literal (single-quoted) */ export interface StringLiteral { type: "string"; value: string; } /** * Date literal (ISO8601 date string) */ export interface DateLiteral { type: "date"; value: string; } /** * DateTime literal (ISO8601 datetime string) */ export interface DateTimeLiteral { type: "datetime"; value: string; } /** * Duration literal (ISO8601 duration) */ export interface DurationLiteral { type: "duration"; value: string; } /** * Temporal keyword (NOW, TODAY, TOMORROW, YESTERDAY, and period boundaries) */ export interface TemporalKeyword { type: "temporal_keyword"; keyword: "NOW" | "TODAY" | "TOMORROW" | "YESTERDAY" | "SOD" | "EOD" | "SOW" | "EOW" | "SOM" | "EOM" | "SOQ" | "EOQ" | "SOY" | "EOY" | "BOT" | "EOT"; } /** * Variable reference */ export interface Variable { type: "variable"; name: string; } /** * Binary operation */ export interface BinaryOp { type: "binary"; operator: "+" | "-" | "*" | "/" | "%" | "^" | "<" | ">" | "<=" | ">=" | "==" | "!=" | "&&" | "||"; left: Expr; right: Expr; } /** * Unary operation */ export interface UnaryOp { type: "unary"; operator: "-" | "+" | "!"; operand: Expr; } /** * Function call */ export interface FunctionCall { type: "function_call"; name: string; args: Expr[]; } /** * Function application (calling an expression that evaluates to a function) */ export interface Apply { type: "apply"; fn: Expr; args: Expr[]; } /** * Member access (dot notation) */ export interface MemberAccess { type: "member_access"; object: Expr; property: string; } /** * Variable binding in a let expression */ export interface LetBinding { name: string; value: Expr; } /** * Let expression: let x = 1, y = 2 in body */ export interface LetExpr { type: "let"; bindings: LetBinding[]; body: Expr; } /** * If expression: if condition then consequent else alternative */ export interface IfExpr { type: "if"; condition: Expr; then: Expr; else: Expr; } /** * Lambda expression: fn( params ~> body ) */ export interface Lambda { type: "lambda"; params: string[]; body: Expr; } /** * Helper functions to create AST nodes */ export declare function literal(value: number | boolean): Literal; export declare function nullLiteral(): NullLiteral; export declare function stringLiteral(value: string): StringLiteral; export declare function dateLiteral(value: string): DateLiteral; export declare function dateTimeLiteral(value: string): DateTimeLiteral; export declare function durationLiteral(value: string): DurationLiteral; export declare function variable(name: string): Variable; export declare function binary(operator: BinaryOp["operator"], left: Expr, right: Expr): BinaryOp; export declare function unary(operator: UnaryOp["operator"], operand: Expr): UnaryOp; export declare function temporalKeyword(keyword: TemporalKeyword["keyword"]): TemporalKeyword; export declare function functionCall(name: string, args: Expr[]): FunctionCall; export declare function apply(fn: Expr, args: Expr[]): Apply; export declare function memberAccess(object: Expr, property: string): MemberAccess; /** * Creates a let expression, desugaring multiple bindings into nested let expressions. * `let a = 1, b = 2 in body` becomes `let a = 1 in let b = 2 in body` * This ensures that later bindings can reference earlier ones. */ export declare function letExpr(bindings: LetBinding[], body: Expr): LetExpr; /** * Creates an if expression: if condition then consequent else alternative */ export declare function ifExpr(condition: Expr, thenBranch: Expr, elseBranch: Expr): IfExpr; /** * Creates a lambda expression: fn( params ~> body ) */ export declare function lambda(params: string[], body: Expr): Lambda; /** * Object property (key-value pair) */ export interface ObjectProperty { key: string; value: Expr; } /** * Object literal: {key: value, ...} */ export interface ObjectLiteral { type: "object"; properties: ObjectProperty[]; } /** * Creates an object literal: {key: value, ...} */ export declare function objectLiteral(properties: ObjectProperty[]): ObjectLiteral; /** * Array literal: [expr, expr, ...] */ export interface ArrayLiteral { type: "array"; elements: Expr[]; } /** * Creates an array literal: [expr, expr, ...] */ export declare function arrayLiteral(elements: Expr[]): ArrayLiteral; /** * Alternative expression: a | b | c * Evaluates alternatives left-to-right, returns first non-null value. */ export interface Alternative { type: "alternative"; alternatives: Expr[]; } /** * Creates an alternative expression: a | b | c */ export declare function alternative(alternatives: Expr[]): Alternative; /** * DataPath literal: .x.y.z or .items.0.name * A path for navigating data structures, inspired by JSONPath. * Segments can be property names (strings) or array indices (numbers). */ export interface DataPath { type: "datapath"; segments: (string | number)[]; } /** * Creates a datapath literal: .x.y.z */ export declare function dataPath(segments: (string | number)[]): DataPath; /** * Type expression for type definitions * Used in `let Person = { name: String, age: Int }` style declarations */ export type TypeExpr = TypeRef | TypeSchema | SubtypeConstraint | ArrayType | UnionType; /** * Reference to a base type: String, Int, Bool, Datetime, Any */ export interface TypeRef { kind: "type_ref"; name: string; } /** * Object type schema: { name: String, age: Int } * extras controls handling of extra attributes: * - undefined/'closed': extra attributes are not allowed (default) * - 'ignored': extra attributes are allowed but not included in output * - TypeExpr: extra attributes are allowed and must match this type */ export interface TypeSchema { kind: "type_schema"; properties: TypeSchemaProperty[]; extras?: "closed" | "ignored" | TypeExpr; } /** * A single constraint with optional label */ export interface Constraint { label?: string; condition: Expr; } /** * Subtype constraint: Int(i | i > 0) or Int(i | positive: i > 0, even: i % 2 == 0) * A base type with one or more predicate constraints */ export interface SubtypeConstraint { kind: "subtype_constraint"; baseType: TypeExpr; variable: string; constraints: Constraint[]; } /** * Array type: [Int], [String], [{ name: String }] */ export interface ArrayType { kind: "array_type"; elementType: TypeExpr; } /** * Union type: Int|String, String|Int|Bool * Tries each type in order, returns first successful parse */ export interface UnionType { kind: "union_type"; types: TypeExpr[]; } /** * Property in a type schema */ export interface TypeSchemaProperty { key: string; typeExpr: TypeExpr; optional?: boolean; } /** * Type definition: let Person = { name: String, age: Int } * Binds a type name (uppercase) to a type expression. * The body can use the type via pipe: data |> Person */ export interface TypeDef { type: "typedef"; name: string; typeExpr: TypeExpr; body: Expr; } /** * Creates a type reference: String, Int, etc. */ export declare function typeRef(name: string): TypeRef; /** * Creates a type schema: { name: String, age: Int } */ export declare function typeSchema(properties: TypeSchemaProperty[], extras?: "closed" | "ignored" | TypeExpr): TypeSchema; /** * Creates a type definition expression */ export declare function typeDef(name: string, typeExpr: TypeExpr, body: Expr): TypeDef; /** * Creates a subtype constraint: Int(i | i > 0) or Int(i | positive: i > 0, even: i % 2 == 0) */ export declare function subtypeConstraint(baseType: TypeExpr, variable: string, constraints: Constraint[]): SubtypeConstraint; /** * Creates an array type: [Int] */ export declare function arrayType(elementType: TypeExpr): ArrayType; /** * Creates a union type: Int|String */ export declare function unionType(types: TypeExpr[]): UnionType; /** * Guard expression: guard [label:] condition in body * Used for preconditions (guard) and postconditions (check). * Throws at runtime if condition is false, unless guards are stripped. */ export interface GuardExpr { type: "guard"; constraints: Constraint[]; body: Expr; guardType: "guard" | "check"; } /** * Creates a guard expression * Multiple guards get nested: guard a in guard b in body */ export declare function guardExpr(constraints: Constraint[], body: Expr, guardType?: "guard" | "check"): GuardExpr; //# sourceMappingURL=ast.d.ts.map