// Lux AST — Self-hosted Abstract Syntax Tree definitions // // Direct translation of src/ast.rs into Lux ADTs. // These types represent the parsed structure of a Lux program. // // Naming conventions to avoid collisions: // Ex = Expr variant, Pat = Pattern, Te = TypeExpr // Td = TypeDef, Vf = VariantFields, Op = Operator // Decl = Declaration, St = Statement // === Source Location === type Span = | Span(Int, Int) // === Identifiers === type Ident = | Ident(String, Span) // === Visibility === type Visibility = | Public | Private // === Schema Evolution === type Version = | Version(Int, Span) type VersionConstraint = | VcExact(Version) | VcAtLeast(Version) | VcLatest(Span) // === Behavioral Types === type BehavioralProperty = | BpPure | BpTotal | BpIdempotent | BpDeterministic | BpCommutative // === Trait Bound (needed before WhereClause) === type TraitBound = | TraitBound(Ident, List, Span) // === Trait Constraint (needed before WhereClause) === type TraitConstraint = | TraitConstraint(Ident, List, Span) // === Where Clauses === type WhereClause = | WcProperty(Ident, BehavioralProperty, Span) | WcResult(Expr, Span) | WcTrait(TraitConstraint) // === Module Path === type ModulePath = | ModulePath(List, Span) // === Import === // path, alias, items, wildcard, span type ImportDecl = | ImportDecl(ModulePath, Option, Option>, Bool, Span) // === Program === type Program = | Program(List, List) // === Declarations === type Declaration = | DeclFunction(FunctionDecl) | DeclEffect(EffectDecl) | DeclType(TypeDecl) | DeclHandler(HandlerDecl) | DeclLet(LetDecl) | DeclTrait(TraitDecl) | DeclImpl(ImplDecl) // === Parameter === type Parameter = | Parameter(Ident, TypeExpr, Span) // === Effect Operation === type EffectOp = | EffectOp(Ident, List, TypeExpr, Span) // === Record Field === type RecordField = | RecordField(Ident, TypeExpr, Span) // === Variant Fields === type VariantFields = | VfUnit | VfTuple(List) | VfRecord(List) // === Variant === type Variant = | Variant(Ident, VariantFields, Span) // === Migration === type Migration = | Migration(Version, Expr, Span) // === Handler Impl === // op_name, params, resume, body, span type HandlerImpl = | HandlerImpl(Ident, List, Option, Expr, Span) // === Impl Method === // name, params, return_type, body, span type ImplMethod = | ImplMethod(Ident, List, Option, Expr, Span) // === Trait Method === // name, type_params, params, return_type, default_impl, span type TraitMethod = | TraitMethod(Ident, List, List, TypeExpr, Option, Span) // === Type Expressions === type TypeExpr = | TeNamed(Ident) | TeApp(TypeExpr, List) | TeFunction(List, TypeExpr, List) | TeTuple(List) | TeRecord(List) | TeUnit | TeVersioned(TypeExpr, VersionConstraint) // === Literal === type LiteralKind = | LitInt(Int) | LitFloat(String) | LitString(String) | LitChar(Char) | LitBool(Bool) | LitUnit type Literal = | Literal(LiteralKind, Span) // === Binary Operators === type BinaryOp = | OpAdd | OpSub | OpMul | OpDiv | OpMod | OpEq | OpNe | OpLt | OpLe | OpGt | OpGe | OpAnd | OpOr | OpPipe | OpConcat // === Unary Operators === type UnaryOp = | OpNeg | OpNot // === Statements === type Statement = | StExpr(Expr) | StLet(Ident, Option, Expr, Span) // === Match Arms === type MatchArm = | MatchArm(Pattern, Option, Expr, Span) // === Patterns === type Pattern = | PatWildcard(Span) | PatVar(Ident) | PatLiteral(Literal) | PatConstructor(Ident, List, Span) | PatRecord(List<(Ident, Pattern)>, Span) | PatTuple(List, Span) // === Function Declaration === // visibility, doc, name, type_params, params, return_type, effects, properties, where_clauses, body, span type FunctionDecl = | FunctionDecl(Visibility, Option, Ident, List, List, TypeExpr, List, List, List, Expr, Span) // === Effect Declaration === // doc, name, type_params, operations, span type EffectDecl = | EffectDecl(Option, Ident, List, List, Span) // === Type Declaration === // visibility, doc, name, type_params, version, definition, migrations, span type TypeDecl = | TypeDecl(Visibility, Option, Ident, List, Option, TypeDef, List, Span) // === Handler Declaration === // name, params, effect, implementations, span type HandlerDecl = | HandlerDecl(Ident, List, Ident, List, Span) // === Let Declaration === // visibility, doc, name, typ, value, span type LetDecl = | LetDecl(Visibility, Option, Ident, Option, Expr, Span) // === Trait Declaration === // visibility, doc, name, type_params, super_traits, methods, span type TraitDecl = | TraitDecl(Visibility, Option, Ident, List, List, List, Span) // === Impl Declaration === // type_params, constraints, trait_name, trait_args, target_type, methods, span type ImplDecl = | ImplDecl(List, List, Ident, List, TypeExpr, List, Span) // === Expressions === type Expr = | ExLiteral(Literal) | ExVar(Ident) | ExBinaryOp(BinaryOp, Expr, Expr, Span) | ExUnaryOp(UnaryOp, Expr, Span) | ExCall(Expr, List, Span) | ExEffectOp(Ident, Ident, List, Span) | ExField(Expr, Ident, Span) | ExTupleIndex(Expr, Int, Span) | ExLambda(List, Option, List, Expr, Span) | ExLet(Ident, Option, Expr, Expr, Span) | ExIf(Expr, Expr, Expr, Span) | ExMatch(Expr, List, Span) | ExBlock(List, Expr, Span) | ExRecord(Option, List<(Ident, Expr)>, Span) | ExTuple(List, Span) | ExList(List, Span) | ExRun(Expr, List<(Ident, Expr)>, Span) | ExResume(Expr, Span)