Documentation
¶
Index ¶
- func Compact(node Node) string
- func EffectNames(effects []EffectAnnotation) []string
- func FormatEffects(effects []EffectAnnotation) string
- func Print(node Node) string
- func PrintProgram(prog *Program) string
- type AlgebraicType
- type Annotation
- type Array
- type ArrayType
- type AssertStmt
- type BinaryOp
- type Binder
- type Block
- type Case
- type ConsPattern
- type Constructor
- type ConstructorField
- type ConstructorPattern
- type ContractKind
- type DeriveKind
- type EffectAnnotation
- type Error
- type Expr
- type Field
- type FieldPattern
- type File
- type ForallExpr
- type FuncCall
- type FuncDecl
- type FuncLit
- type FuncType
- type Identifier
- type If
- type Import
- type ImportDecl
- type Instance
- type Interpolation
- type Lambda
- type Let
- type LetRec
- type List
- type ListPattern
- type ListType
- type Literal
- type LiteralKind
- type Match
- type Method
- type Module
- type ModuleDecl
- type Node
- type Param
- type Pattern
- type Pos
- type Program
- type Property
- type PropertyDecl
- type QuasiQuote
- type Record
- type RecordAccess
- type RecordField
- type RecordPattern
- type RecordType
- type RecordUpdate
- type Recv
- type Send
- type SimpleType
- type Span
- type Stmt
- type TestCase
- type TestDecl
- type Tuple
- type TuplePattern
- type TupleType
- type Type
- type TypeAlias
- type TypeApp
- type TypeClass
- type TypeDecl
- type TypeDef
- type TypeVar
- type UnaryOp
- type WildcardPattern
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EffectNames ¶
func EffectNames(effects []EffectAnnotation) []string
EffectNames extracts just the effect names from annotations (for backward compatibility)
func FormatEffects ¶
func FormatEffects(effects []EffectAnnotation) string
FormatEffects formats a slice of effect annotations for display
func Print ¶
Print produces a deterministic JSON representation of an AST node. This is used for golden snapshot testing.
Design decisions: - Omits instance-specific metadata: SIDs, byte offsets, detailed positions - Normalizes file paths to "test://unit" for reproducibility - Includes "type" field for each node to identify node type - Uses JSON marshaling with custom handling for Node interface
func PrintProgram ¶
PrintProgram produces a deterministic JSON representation of a Program. Note: Program doesn't implement Node, so we handle it separately.
Types ¶
type AlgebraicType ¶
type AlgebraicType struct {
Constructors []*Constructor
Pos Pos
}
AlgebraicType represents sum types
type Annotation ¶
type Annotation struct {
Name string // e.g., "route", "verify"
Args []Expr // Positional arguments (string literals, int literals, etc.)
Pos Pos
}
Annotation represents a parsed @name(...) annotation on a declaration.
type Array ¶
Array represents an array literal #[1, 2, 3] Arrays provide O(1) indexed access unlike linked lists
type AssertStmt ¶
AssertStmt represents an assertion: assert expr
func (*AssertStmt) Position ¶
func (a *AssertStmt) Position() Pos
func (*AssertStmt) String ¶
func (a *AssertStmt) String() string
type Block ¶
Block represents a sequence of expressions separated by semicolons The last expression is the return value, others are evaluated for effects
type ConsPattern ¶
ConsPattern matches list cons
func (*ConsPattern) Position ¶
func (c *ConsPattern) Position() Pos
func (*ConsPattern) String ¶
func (c *ConsPattern) String() string
type Constructor ¶
type Constructor struct {
Name string
Fields []*ConstructorField
Pos Pos
}
type ConstructorField ¶
type ConstructorField struct {
Name string // Field name (empty for positional fields)
Type Type // Field type
Pos Pos
}
ConstructorField represents a field in an ADT constructor. Supports both named fields (x: int) and positional fields (int).
type ConstructorPattern ¶
ConstructorPattern matches algebraic type constructors
func (*ConstructorPattern) Position ¶
func (c *ConstructorPattern) Position() Pos
func (*ConstructorPattern) String ¶
func (c *ConstructorPattern) String() string
type ContractKind ¶
type ContractKind int
ContractKind distinguishes between property tests and contract clauses. This enables reuse of the Property struct for both forall-style tests and requires/ensures contracts (M-VERIFY).
const ( PropertyKind ContractKind = iota // Existing forall property-based tests RequiresKind // Precondition contract EnsuresKind // Postcondition contract InvariantKind // Type/module invariant contract )
func (ContractKind) String ¶
func (k ContractKind) String() string
String returns the string representation of a ContractKind
type DeriveKind ¶
type DeriveKind int
DeriveKind represents which type classes can be automatically derived
const ( DeriveNone DeriveKind = iota DeriveEq // deriving (Eq) - automatic equality )
func (DeriveKind) String ¶
func (d DeriveKind) String() string
String returns the string representation of a DeriveKind
type EffectAnnotation ¶
type EffectAnnotation struct {
Name string // Effect name (e.g., "IO", "FS", "Net") or row variable (e.g., "e")
IsRowVar bool // True if this is an effect row variable (lowercase identifier)
Budget *int // Optional budget limit / max (nil = unlimited)
Min *int // Optional minimum usage requirement (nil = no minimum) (M-DX25 M4)
Pos Pos
}
EffectAnnotation represents an effect with optional budget constraints Syntax: IO or IO @limit=5 or IO @min=1 or IO @min=1 @limit=5 Row variables: lowercase identifiers like 'e' in ! {e} for effect polymorphism
func (*EffectAnnotation) String ¶
func (e *EffectAnnotation) String() string
String formats the effect annotation for display
type Expr ¶
type Expr interface {
Node
// contains filtered or unexported methods
}
Expression nodes
type FieldPattern ¶
type File ¶
type File struct {
Module *ModuleDecl // Optional module declaration
Imports []*ImportDecl // Import declarations
Decls []Node // Top-level declarations (deprecated, use Funcs/Statements)
Funcs []*FuncDecl // Function declarations
Statements []Node // Top-level statements/expressions
Path string // File path for validation
Pos Pos
}
File represents a complete AILANG source file
type ForallExpr ¶
type ForallExpr struct {
Var string // Bound variable name
Lo Expr // Lower bound (inclusive)
Hi Expr // Upper bound (exclusive)
Body Expr // Quantified body (boolean predicate)
Pos Pos
}
ForallExpr represents a bounded universal quantifier: forall i: lo..hi => body Used in contract clauses (requires/ensures) for element-wise properties. Only integer quantifiers are supported.
func (*ForallExpr) Position ¶
func (f *ForallExpr) Position() Pos
func (*ForallExpr) String ¶
func (f *ForallExpr) String() string
type FuncCall ¶
FuncCall represents a function application.
Usage example:
call := &ast.FuncCall{
Func: &ast.Identifier{Name: "factorial", Pos: pos},
Args: []ast.Expr{
&ast.Literal{Kind: ast.IntLit, Value: int64(5), Pos: pos},
},
Pos: p.curToken.Pos,
}
Common parser pattern:
// Parse: factorial(5)
func := p.parseExpression(CALL) // parses "factorial"
p.nextToken() // move to LPAREN
args := p.parseCallArguments() // parses "(5)"
return &ast.FuncCall{Func: func, Args: args, Pos: startPos}
type FuncDecl ¶
type FuncDecl struct {
Name string
TypeParams []string // Generic type parameters
Params []*Param
ReturnType Type
Effects []EffectAnnotation // Effect annotations with optional budgets
Tests []*TestCase
Properties []*Property
Body Expr // nil for extern functions
IsPure bool
IsExport bool // Export flag
IsExtern bool // Extern flag - function implemented in Go, no body
VerifyDepth *int // Per-function SMT verification depth override (nil = use global default)
Annotations []*Annotation // Generic annotations (e.g., @route, @verify)
Pos Pos
Span Span // For SID calculation
SID string // Stable ID (calculated post-parse)
Origin string // "func_decl" for metadata
}
FuncDecl represents a function declaration.
Usage example:
funcDecl := &ast.FuncDecl{
Name: "factorial",
TypeParams: []string{},
Params: []*ast.Param{
{Name: "n", Type: intType, Pos: pos},
},
ReturnType: intType,
Effects: []EffectAnnotation{},
Tests: []*ast.TestCase{},
Properties: []*ast.Property{},
Body: bodyExpr,
IsPure: true,
IsExport: false,
Pos: p.curToken.Pos,
}
Common parser pattern:
// Parse: func factorial(n: int) -> int { ... }
p.nextToken() // skip "func"
name := p.curToken.Literal
p.nextToken() // move to LPAREN
params := p.parseFunctionParams()
returnType := p.parseReturnType()
effects := p.parseEffects()
body := p.parseExpression(LOWEST)
return &ast.FuncDecl{
Name: name, Params: params,
ReturnType: returnType, Effects: effects,
Body: body, Pos: startPos,
}
func (*FuncDecl) GetAnnotation ¶
func (f *FuncDecl) GetAnnotation(name string) *Annotation
GetAnnotation returns the first annotation with the given name, or nil.
type FuncLit ¶
type FuncLit struct {
Params []*Param
ReturnType Type // Optional return type annotation
Effects []EffectAnnotation // Effect annotations with optional budgets
Body Expr
Pos Pos
}
FuncLit represents an anonymous function literal (func expression) Syntax: func(x: int, y: int) -> int { x + y } This desugars to Lambda in the elaboration phase
type FuncType ¶
type FuncType struct {
Params []Type
Return Type
Effects []EffectAnnotation // Effect annotations with optional budgets
Pos Pos
}
FuncType represents function types
type Identifier ¶
Identifier represents a variable or function name.
Usage example:
ident := &ast.Identifier{
Name: "factorial",
Pos: p.curToken.Pos,
}
Common pattern in parser:
if p.curTokenIs(lexer.IDENT) {
return &ast.Identifier{Name: p.curToken.Literal, Pos: p.curToken.Pos}
}
Type assertions:
ident, ok := expr.(*ast.Identifier)
if ok {
fmt.Println("Variable name:", ident.Name)
}
func (*Identifier) Position ¶
func (i *Identifier) Position() Pos
func (*Identifier) String ¶
func (i *Identifier) String() string
type ImportDecl ¶
type ImportDecl struct {
Path string // Module path to import
Symbols []string // Selective imports (empty = whole module)
ModuleAlias string // Module alias: "import std/list as List" -> "List"
SymbolAliases map[string]string // Symbol aliases: original -> alias (e.g., "length" -> "stringLength")
IsPackage bool // True if import uses pkg/ prefix (external package)
PackageName string // Package name (vendor/name) extracted from pkg/ import path
IsRelative bool // True if import uses ./ prefix (intra-package sibling)
RelativePath string // Relative portion after ./ (e.g., "plan" from "./plan")
Pos Pos
Span Span
}
ImportDecl represents an import declaration
func (*ImportDecl) Position ¶
func (i *ImportDecl) Position() Pos
func (*ImportDecl) String ¶
func (i *ImportDecl) String() string
type Interpolation ¶
type Lambda ¶
type Lambda struct {
Params []*Param
Body Expr
Effects []EffectAnnotation // Effect annotations with optional budgets
Pos Pos
}
Lambda represents a lambda expression.
Usage example:
lambda := &ast.Lambda{
Params: []*ast.Param{
{Name: "x", Type: nil, Pos: pos1},
{Name: "y", Type: nil, Pos: pos2},
},
Body: bodyExpr,
Effects: []EffectAnnotation{{Name: "IO"}},
Pos: p.curToken.Pos,
}
Common parser pattern:
// Parse: \x y. x + y
p.nextToken() // skip \
params := p.parseParams()
p.expectToken(lexer.DOT)
body := p.parseExpression(LOWEST)
return &ast.Lambda{Params: params, Body: body, Pos: startPos}
type LetRec ¶
type LetRec struct {
Name string
Type Type // Optional type annotation
Value Expr
Body Expr
Pos Pos
}
LetRec represents a recursive let binding Syntax: letrec name = value in body The name is in scope in the value expression (for recursion)
type List ¶
List represents a list literal.
Usage example:
list := &ast.List{
Elements: []ast.Expr{
&ast.Literal{Kind: ast.IntLit, Value: int64(1), Pos: pos},
&ast.Literal{Kind: ast.IntLit, Value: int64(2), Pos: pos},
&ast.Literal{Kind: ast.IntLit, Value: int64(3), Pos: pos},
},
Pos: p.curToken.Pos,
}
Common parser pattern:
// Parse: [1, 2, 3]
p.nextToken() // skip [
elements := []ast.Expr{}
for !p.curTokenIs(lexer.RBRACKET) {
elements = append(elements, p.parseExpression(LOWEST))
if p.peekTokenIs(lexer.COMMA) {
p.nextToken() // move to comma
p.nextToken() // move past comma
}
}
p.nextToken() // skip ]
return &ast.List{Elements: elements, Pos: startPos}
type ListPattern ¶
ListPattern matches list literals
func (*ListPattern) Position ¶
func (l *ListPattern) Position() Pos
func (*ListPattern) String ¶
func (l *ListPattern) String() string
type Literal ¶
type Literal struct {
Kind LiteralKind
Value interface{}
Pos Pos
}
Literal represents a literal value.
⚠️ CRITICAL GOTCHA: Lexer returns int64 for integers, NOT int!
Usage example:
lit := &ast.Literal{
Kind: ast.IntLit,
Value: int64(42), // ⚠️ Must be int64, not int!
Pos: p.curToken.Pos,
}
Type assertions (CORRECT):
lit := expr.(*ast.Literal)
if lit.Kind == ast.IntLit {
val := lit.Value.(int64) // ✅ CORRECT - int64
fmt.Println("Integer:", val)
}
Type assertions (WRONG):
val := lit.Value.(int) // ❌ WRONG - will panic! Lexer returns int64
Common parser pattern:
case lexer.INT:
val, _ := strconv.ParseInt(p.curToken.Literal, 10, 64)
return &ast.Literal{Kind: ast.IntLit, Value: val, Pos: p.curToken.Pos}
type LiteralKind ¶
type LiteralKind int
const ( IntLit LiteralKind = iota FloatLit StringLit BoolLit UnitLit )
type ModuleDecl ¶
ModuleDecl represents a module declaration
func (*ModuleDecl) Position ¶
func (m *ModuleDecl) Position() Pos
func (*ModuleDecl) String ¶
func (m *ModuleDecl) String() string
type Pattern ¶
type Pattern interface {
Node
// contains filtered or unexported methods
}
Pattern nodes for pattern matching
type Program ¶
type Program struct {
File *File // New: Use File instead of Module
Module *Module // Legacy: Keep for compatibility
}
Program represents the entire program
type Property ¶
type Property struct {
Name string
Kind ContractKind // Type of property/contract (M-VERIFY)
Binders []*Binder // forall bindings (empty for requires/ensures)
Expr Expr // Boolean predicate
Pos Pos
}
type PropertyDecl ¶
PropertyDecl represents a top-level property block: property "name" { forall(...) => expr }
func (*PropertyDecl) Position ¶
func (p *PropertyDecl) Position() Pos
func (*PropertyDecl) String ¶
func (p *PropertyDecl) String() string
type QuasiQuote ¶
type QuasiQuote struct {
Kind string // sql, html, regex, json, shell, url
Template string
Interpolations []*Interpolation
Pos Pos
}
QuasiQuote represents typed quasiquotes
func (*QuasiQuote) Position ¶
func (q *QuasiQuote) Position() Pos
func (*QuasiQuote) String ¶
func (q *QuasiQuote) String() string
type RecordAccess ¶
RecordAccess represents field access
func (*RecordAccess) Position ¶
func (r *RecordAccess) Position() Pos
func (*RecordAccess) String ¶
func (r *RecordAccess) String() string
type RecordField ¶
type RecordPattern ¶
type RecordPattern struct {
Fields []*FieldPattern
Rest bool // Has rest pattern ...
Pos Pos
}
RecordPattern matches records
func (*RecordPattern) Position ¶
func (r *RecordPattern) Position() Pos
func (*RecordPattern) String ¶
func (r *RecordPattern) String() string
type RecordType ¶
type RecordType struct {
Fields []*RecordField
Row *TypeVar // Row variable for open records (e.g., {a: T | r})
Pos Pos
}
RecordType represents record types If Row is non-nil, this is an open record type {a: T | r}
func (*RecordType) Position ¶
func (r *RecordType) Position() Pos
func (*RecordType) String ¶
func (r *RecordType) String() string
type RecordUpdate ¶
type RecordUpdate struct {
Base Expr // The base record expression
Fields []*Field // Fields to update
Pos Pos
}
RecordUpdate represents functional record update: {base | field: value, ...}
func (*RecordUpdate) Position ¶
func (r *RecordUpdate) Position() Pos
func (*RecordUpdate) String ¶
func (r *RecordUpdate) String() string
type SimpleType ¶
SimpleType represents basic types
func (*SimpleType) Position ¶
func (s *SimpleType) Position() Pos
func (*SimpleType) String ¶
func (s *SimpleType) String() string
type Stmt ¶
type Stmt interface {
Node
// contains filtered or unexported methods
}
Statement nodes (though AILANG is expression-based)
type TuplePattern ¶
TuplePattern matches tuples
func (*TuplePattern) Position ¶
func (t *TuplePattern) Position() Pos
func (*TuplePattern) String ¶
func (t *TuplePattern) String() string
type TypeAlias ¶
TypeAlias represents type aliases (not sum types) Used to distinguish `type Names = [string]` from `type Color = Red | Green`
type TypeApp ¶
type TypeApp struct {
Constructor string // Type constructor name (e.g., "Option", "Result")
Args []Type // Type arguments (e.g., [int], [T, E])
Pos Pos
}
TypeApp represents type application (generic types) Example: Option[int], Result[T, E], Map[string, int] M-TAPP-FIX: Added to preserve type arguments in annotations
type TypeClass ¶
type TypeClass struct {
Name string
TypeParam string
Superclass string // Optional superclass
Methods []*Method
Pos Pos
}
TypeClass represents a type class declaration
type TypeDecl ¶
type TypeDecl struct {
Name string
TypeParams []string
Definition TypeDef
Deriving []DeriveKind // Type classes to auto-derive (e.g., [DeriveEq])
Exported bool // True if type was declared with 'export'
Pos Pos
}
TypeDecl represents a type declaration
type WildcardPattern ¶
type WildcardPattern struct {
Pos Pos
}
WildcardPattern matches anything
func (*WildcardPattern) Position ¶
func (w *WildcardPattern) Position() Pos
func (*WildcardPattern) String ¶
func (w *WildcardPattern) String() string