Kex.AST
module Kex.AST
Parses Kex source code into a structured AST at runtime.
Returns Result<Program, ParseError> — the AST includes module definitions, function signatures, type/record definitions, traits, make blocks, and doc-comments extracted from # lines.
parse
parse(source: String) -> Result<Program, ParseError>
parse(source: String, filename: String) -> Result<Program, ParseError>
Parses a Kex source string into a structured AST.
parseType
parseType(source: String) -> Result<TypeRef, ParseError>
Parses a type expression string into a TypeRef.
parseExpression
parseExpression(source: String) -> Result<Expression, ParseError>
Parses a single expression string into an Expression AST node.
typeRefText
typeRefText(_) -> String
patternRefText
patternRefText(_) -> String
patternFieldText
patternFieldText(name, _, _) -> String
referenceText
referenceText(_) -> String
record Location
Fields
record Program
Fields
record ParseError
Fields
type TypeRef
Structured representation of type expressions.
Variants
NamedType(String, [TypeRef])FunctionType([TypeRef], TypeRef)TupleType([TypeRef])ListType(TypeRef)MapType(TypeRef, TypeRef)UnionType([TypeRef])IntersectionType([TypeRef])RecordType([(String, TypeRef)])NullableType(TypeRef)BlockType(TypeRef)AtomType(String)TypeQuery(String, Expression)TypeVar(String)AnyTypeNoneType
type PatternRef
Structured representation of patterns.
Variants
BindPattern(String)LiteralPattern(String)ConstructorPattern(String, [PatternRef])TuplePattern([PatternRef])ListPattern([PatternRef], PatternRef?)RecordPattern(String?, [PatternField])RangePattern(PatternRef, PatternRef)ThisPattern(PatternRef)WildcardPattern
record PatternField
Fields
nameStringpatternPatternRef?stringKeyBool
type Expression
Structured representation of expression AST nodes.
Variants
LitInt(Int)LitFloat(Float)LitChar(Int)LitString(String)InterpolatedString([String], [Expression])LitBool(Bool)LitAtom(String)LitNoneIdentifier(String)ThisBinaryOp(Expression, String, Expression)UnaryOp(String, Expression)Call(Expression, [Expression], [NamedArgument], Expression?)TaggedLiteral(String, [String], [Expression])MethodCall(Expression, String, [Expression], [NamedArgument], Expression?, Bool, Bool, TypeRef?)If(Expression, PatternRef?, [Expression], [ElseIf], [Expression]?)Match(Expression, String?, [MatchArm])Receive(String?, [MatchArm], Expression?, Expression?)ListLit([Expression], Expression?)MapLit([MapItem])RecordLit(String, [RecordField])TupleLit([Expression])Block([Expression])Lambda([LambdaParam], [Expression], TypeRef?, RescueInfo?)Let(PatternRef, TypeRef?, Expression)Var(String, TypeRef?, Expression)Assign(String, Expression)Return(Expression)BreakNextSpawn([Expression])Try(Expression)Spread(Expression)TrailingIf(Expression, Expression)ThenElse(Expression, Expression, Expression)ShorthandLambda(String, [Expression], Bool)CurryPlaceholderCurry(String, String?, Bool, [[Expression]])Using(String, String?, [String], [String], [Expression])With(String, Expression, [Expression])GeneratedDeclaration(Expression, GeneratedTemplate)ErrorExpression(String)Trying([Expression], RescueInfo)While(Expression, [Expression])Loop([String], [Expression])RangeLit(Expression, Expression)
record NamedArgument
Fields
nameStringvalueExpression
record MatchArm
Fields
patterns[PatternRef]guardExpression?bodyExpression
record LambdaParam
Fields
record RescueInfo
Fields
arms[MatchArm]catchAllNameString?catchAllBody[Expression]inlineReturnExpression?
record ElseIf
Fields
conditionExpressionbody[Expression]
type MapItem
Variants
MapEntry(Expression, Expression)MapSpread(Expression)
record RecordField
Fields
nameStringvalueExpression
type GeneratedTemplate
A declaration template whose name (and, for a make block, target) is computed by a compiled do expression.
Variants
GeneratedNode(Node)GeneratedMake(GeneratedMakeInfo)
record GeneratedMakeInfo
Fields
isFinalBoolimplements[TypeRef]body[CompiledItem]locationLocation
record MainInfo
Fields
docString?params[ParamInfo]body[Expression]rescueInfoRescueInfo?locationLocation
record ParamInfo
Fields
nameString?patternPatternRef?typeTypeRef?hasDefaultBool
record ClauseInfo
Fields
params[ParamInfo]body[Expression]returnTypeTypeRef?rescueInfoRescueInfo?hasParamListBool
record FunctionInfo
Fields
record AnnotationInfo
Fields
record VariantInfo
Fields
record TypeInfo
Fields
record FieldInfo
Fields
record RecordInfo
Fields
record TraitInfo
Fields
record MakeInfo
Fields
record PragmaInfo
Fields
record ModuleInfo
Fields
record ConstantInfo
Fields
record VisibilityInfo
Fields
record UsingInfo
Fields
record ExportInfo
Fields
type CompiledItem
Variants
CompiledNode(Node)CompiledExpression(Expression)
record CompiledInfo
Fields
items[CompiledItem]locationLocation
type Node
Variants
ModuleDef(ModuleInfo)FunctionDef(FunctionInfo)TypeAnnotation(AnnotationInfo)TypeDef(TypeInfo)RecordDef(RecordInfo)TraitDef(TraitInfo)MakeDef(MakeInfo)PragmaDef(PragmaInfo)ConstantDef(ConstantInfo)MainDef(MainInfo)Visibility(VisibilityInfo)UsingDef(UsingInfo)ExportDef(ExportInfo)Compiled(CompiledInfo)
type TypeRef | PatternRef
Source-like conversion through the standard .to(String) spelling.
to
to(_) -> String?