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
String
List Name
{ doc : Maybe String
, value : 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.
{ dirPath : List String
, fileName : String
, packageDecl : PackageDecl
, imports : List ImportDecl
, typeDecls : List (Documented (Annotated TypeDecl))
}
List String
{ isAbsolute : Basics.Bool
, packagePrefix : List String
, importNames : List 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 })
{ 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:
- 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
- UnOp
- BinOp
- 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 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