Compiler.Ast.Source

The Abstract Syntax Tree (AST) of Gren.

type alias Expression = Located Expression_
type Expression_
= CharLiteral Char
| StringLiteral String
| NumberLiteral Outcome
| Var ({ varType : VarType, name : String })
| VarQual ({ varType : VarType, qualifier : String, name : String })
| ArrayLiteral (Array Expression)
| Record (Array RecordField)
| Update ({ record : Expression, newValues : Array RecordField })
| Operator String
| Negate Expression
| Binops ({ left : Expression, operator : Located String, right : Expression })
| Lambda ({ patterns : Array Pattern, body : Expression })
| Call ({ fn : Expression, args : Array Expression })
| Let ({ defs : Array (Located Def), body : Expression })
| If ({ branches : Array IfBranch, elseBranch : Expression })
| When ({ expression : Expression, branches : Array WhenBranch })
| Accessor String
| Access ({ expression : Expression, accessor : String })
| Parens Expression
type VarType
= LowVar
| CapVar
type alias IfBranch = { test : Expression, body : Expression }
type alias WhenBranch = { pattern : Pattern, body : Expression }
type alias RecordField = { field : Located String, value : Expression }
type Def
= Define DefineRecord
| Destruct ({ pattern : Pattern, body : Expression })
type alias DefineRecord =
{ name : Located String
, args : Array Pattern
, body : Expression
, typeSignature : Maybe Type
}
type alias Pattern = Located Pattern_
type Pattern_
= PAnything String
| PVar String
| PRecord (Array PRecordField)
| PAlias ({ pattern : Pattern, name : Located String })
| PCtor ({ name : Located String, arg : Maybe Pattern })
| PCtorQual ({ varRegion : Region, module_ : String, name : String, arg : Maybe Pattern })
| PArray (Array Pattern)
| PChr Char
| PStr String
| PInt ({ value : Int, isHex : Bool })
type alias PRecordField = { field : Located String, pattern : Maybe Pattern }
type alias Type = Located Type_
type Type_
= TLambda ({ from : Type, to : Type })
| TVar String
| TType ({ name : Located String, args : Array Type })
| TTypeQual ({ varRegion : Region, qualifier : String, name : String, args : Array Type })
| TRecord ({ fields : Array TRecordField, extending : Maybe (Located String) })
| TParens Type
type alias TRecordField = { field : Located String, signature : Type }
type alias Alias =
{ name : Located String
, vars : Array (Located String)
, type_ : Type
}
type alias Union =
{ name : Located String
, vars : Array (Located String)
, variants : Array (Located UnionVariant)
}
type alias UnionVariant = { name : Located String, payload : Maybe Type }
type alias Value =
{ name : Located String
, signature : Maybe Type
, args : Array Pattern
, body : Expression
}
type alias Port = { name : Located String, signature : Type }
type alias Module =
{ name : Located String
, exports : Exposing
, docs : Maybe (Located String)
, imports : Array (Located Import)
, values : Array (ModuleDeclaration Value)
, unions : Array (ModuleDeclaration Union)
, aliases : Array (ModuleDeclaration Alias)
, binops : Array (Located Infix)
, effects : Effects
}
type alias ModuleDeclaration v = Located { docs : Maybe (Located String), value : v }
type Exposing
= Open
| Explicit (Array Exposed)
type Exposed
= ExposedLower (Located String)
| ExposedUpper ({ name : Located String, privacy : Privacy })
| ExposedOperator (Located String)
type Privacy
= Public
| Private
type alias Import =
{ module_ : Located String
, alias : Maybe String
, expose : Exposing
}
type Effects
= NoEffects
| Ports (Array (ModuleDeclaration Port))
| Manager Manager
type Manager
= Cmd (Located String)
| Sub (Located String)
| Fx ({ cmd : Located String, sub : Located String })
type alias Infix =
{ fn : String
, symbol : String
, associativity : BinopAssociativity
, precedence : Int
}
type BinopAssociativity
= OpALeft
| OpANone
| OpARight