elm-in-elm / compiler / Elm.AST.Frontend

Frontend AST is the first stage after parsing from source code, and has the closest resemblance to the Elm source code. Eg. all the comments etc. are still there.


type alias ProjectFields =
{ modules : Dict Elm.Data.ModuleName.ModuleName (Elm.Data.Module.Module LocatedExpr) }

"What does this compiler stage need to store abotut the whole project?

(See Elm.Data.Project.)

In this case, a dict of all the compiled Elm modules that hold frontend AST expressions.


type alias LocatedExpr =
Elm.Data.Located.Located Expr

The main type of this module. Expression with location metadata.

Note the underlying Expr custom type recurses on this LocatedExpr type, so that the children also each have their location metadata.

If you want expressions without location metadata, look at unwrap.


type Expr
    = Int Basics.Int
    | Float Basics.Float
    | Char Char
    | String String
    | Bool Basics.Bool
    | Var ({ module_ : Maybe Elm.Data.ModuleName.ModuleName, name : Elm.Data.VarName.VarName })
    | Argument Elm.Data.VarName.VarName
    | Plus LocatedExpr LocatedExpr
    | Cons LocatedExpr LocatedExpr
    | ListConcat LocatedExpr LocatedExpr
    | Lambda ({ arguments : List Elm.Data.VarName.VarName, body : LocatedExpr })
    | Call ({ fn : LocatedExpr, argument : LocatedExpr })
    | If ({ test : LocatedExpr, then_ : LocatedExpr, else_ : LocatedExpr })
    | Let ({ bindings : List (Elm.Data.Binding.Binding LocatedExpr), body : LocatedExpr })
    | List (List LocatedExpr)
    | Unit
    | Tuple LocatedExpr LocatedExpr
    | Tuple3 LocatedExpr LocatedExpr LocatedExpr

unwrap : LocatedExpr -> Unwrapped.Expr

Discard the location metadata.

transform : (Expr -> Expr) -> Expr -> Expr

Transform the expression using the provided function.

Start at the children, repeatedly apply on them until they stop changing, then go up.

recurse : (Expr -> Expr) -> Expr -> Expr

A helper for the Transform library. Runs the given function recursively on all children.