finos / morphir-elm / Morphir.Scala.AST

Scala's abstract-syntax tree. This is a custom built AST that focuses on the subset of Scala features that our generator uses. It's a relatively large portion of the language but it's not aiming to be complete.

Abstract Syntax Tree


type alias Name =
String


type alias Path =
List Name


type alias Documented a =
{ doc : Maybe String
, value : a 
}


type alias Annotated a =
{ annotations : List String
, value : a 
}

withAnnotation : List String -> a -> Annotated a

Wrap in Annotated with an annotation value.

withoutAnnotation : a -> Annotated a

Wrap in Annotated without any annotation values.


type alias CompilationUnit =
{ dirPath : List String
, fileName : String
, packageDecl : PackageDecl
, imports : List ImportDecl
, typeDecls : List (Documented (Annotated TypeDecl)) 
}


type alias PackageDecl =
List String


type alias ImportDecl =
{ isAbsolute : Basics.Bool
, packagePrefix : List String
, importNames : List ImportName 
}


type ImportName


type Mod
    = Sealed
    | Final
    | Case
    | Val
    | Package
    | Implicit
    | Private (Maybe String)
    | Abstract


type TypeDecl
    = Trait ({ modifiers : List Mod, name : Name, typeArgs : List Type, extends : List Type, members : List (Annotated MemberDecl) })
    | Class ({ modifiers : List Mod, name : Name, typeArgs : List Type, ctorArgs : List (List ArgDecl), extends : List Type, members : List (Annotated MemberDecl), body : List Value })
    | Object ({ modifiers : List Mod, name : Name, extends : List Type, members : List (Annotated MemberDecl), body : Maybe Value })


type alias ArgDecl =
{ modifiers : List Mod
, tpe : Type
, name : Name
, defaultValue : Maybe Value 
}


type ArgValue
    = ArgValue (Maybe Name) Value


type MemberDecl
    = TypeAlias ({ alias : Name, typeArgs : List Type, tpe : Type })
    | ValueDecl ({ modifiers : List Mod, pattern : Pattern, valueType : Maybe Type, value : Value })
    | FunctionDecl ({ modifiers : List Mod, name : Name, typeArgs : List Type, args : List (List ArgDecl), returnType : Maybe Type, body : Maybe Value })
    | MemberTypeDecl TypeDecl


type Type
    = TypeVar Name
    | TypeRef Path Name
    | TypeOfValue Path
    | TypeApply Type (List Type)
    | TypeParametrized Type (List Type) Type
    | TupleType (List Type)
    | StructuralType (List MemberDecl)
    | FunctionType Type Type
    | CommentedType Type String


type Value
    = Literal Lit
    | Variable Name
    | Ref Path Name
    | Select Value Name
    | Wildcard
    | Apply Value (List ArgValue)
    | UnOp String Value
    | BinOp Value String Value
    | Lambda (List ( Name, Maybe Type )) Value
    | Block (List MemberDecl) Value
    | MatchCases (List ( Pattern, Value ))
    | Match Value Value
    | IfElse Value Value Value
    | Tuple (List Value)
    | StructuralValue (List ( Name, Value ))
    | Unit
    | This
    | CommentedValue Value String
    | ForComp (List Generator) Value
    | TypeAscripted Value Type

Type that represents a Scala Value.

These are the supported Values:


type Pattern
    = WildcardMatch
    | NamedMatch Name
    | AliasedMatch Name Pattern
    | LiteralMatch Lit
    | UnapplyMatch Path Name (List Pattern)
    | TupleMatch (List Pattern)
    | EmptyListMatch
    | HeadTailMatch Pattern Pattern
    | CommentedPattern Pattern String


type Lit
    = BooleanLit Basics.Bool
    | CharacterLit Char
    | StringLit String
    | IntegerLit Basics.Int
    | FloatLit Basics.Float
    | DecimalLit Decimal


type Generator
    = Extract Pattern Value
    | Bind Pattern Value
    | Guard Value

Utilities

nameOfTypeDecl : TypeDecl -> Name