finos/morphir-elm/22.0.1

NOTE: the latest version is 22.0.2

Formerly Morgan-Stanley/morphir-elm. Search finds this package by either name.

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 : Bool
, packagePrefix : List String
, importNames : List ImportName
}
= ImportName String
| ImportRename String String
type Mod
= Sealed
| Final
| Case
| Val
| Package
| Implicit
| Private (Maybe String)
| Abstract
= 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
}
= ArgValue (Maybe Name) Value
= 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
| New Path Name (List ArgValue)
| Throw Value

Type that represents a Scala Value.

These are the supported Values:

  • Literal
    • Specifies a Scala literal
  • Variable
    • Specifies a Scala variable
  • Ref
    • Represents a Scala function reference
  • Select
    • Represents an operation with a target expression and a name, where the name is applied with a '.' to the target.
    • For example, '..obj.mymethod(param1, param2)' where 'mymethod' is the name and '..obj' is the target expression.
    • Any argument list needed, such as '(param1, param2)', is appended to the Select value.
  • Wildcard
  • Apply
    • Apply a Scala function
  • UnOp
  • BinOp
    • Scala binary operation
  • Lambda
  • Block
  • MatchCases
  • Match
  • IfElse
  • Tuple
  • StructuralValue
  • Unit
    • Return type of a Scala function which doesn't return anything
    • Unit is represented as '{}'
  • This
  • CommentedValue
  • ForComp
  • TypeAscripted
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 Bool
| CharacterLit Char
| StringLit String
| IntegerLit Int
| FloatLit Float
| DecimalLit Decimal
| NullLit
= Extract Pattern Value
| Bind Pattern Value
| Guard Value

Utilities