thomasin / elm-frontmatter / Content.Decode.Syntax

These Syntax helpers are extensible wrappers around elm-syntax, made so you can build type and function declarations in parallel.

syntax : Content.Decode.Syntax.Syntax () ( ( Int, String ), List ( String, String ) )
syntax =
    Content.Decode.Syntax.tuple2
        ( Content.Decode.Syntax.tuple2 ( Content.Decode.Syntax.int, Content.Decode.Syntax.string )
        , Content.Decode.Syntax.list
            (Content.Decode.Syntax.tuple2 (Content.Decode.Syntax.string Content.Decode.Syntax.string))
        )


type alias Syntax context value =
{ typeAnnotation : context -> Elm.Syntax.TypeAnnotation.TypeAnnotation
, imports : context -> List Elm.Syntax.Import.Import
, expression : context -> value -> Elm.Syntax.Expression.Expression 
}

Syntax object. Fields take a context argument, so when you render your type annotation, imports or expressions you can pass down meta. Content.Decode.Decoders use this to pass down the input file path so that decoders know which file they are decoding.

noContext : { typeAnnotation : Elm.Syntax.TypeAnnotation.TypeAnnotation, imports : List Elm.Syntax.Import.Import, expression : value -> Elm.Syntax.Expression.Expression } -> Syntax context value

A very small helper to create a Syntax object that doesn't need to use or pass on any context.

string : Syntax context String

String An important note is that this will escape '"' and '', as it is meant for user provided strings. If you want to pass it hardcoded strings this might be a problem.

datetime : Syntax context Time.Posix

Datetime

int : Syntax context Basics.Int

Int

float : Syntax context Basics.Float

Float

bool : Syntax context Basics.Bool

Bool

list : Syntax context a -> Syntax context (List a)

List list string => List String

dict : Syntax context key -> Syntax context value -> Syntax context (List ( key, value ))

Dict dict string int => Dict.Dict String Int

tuple2 : ( Syntax context a, Syntax context b ) -> Syntax context ( a, b )

Two element tuple tuple2 ( string, int ) => ( String, Int )

tuple3 : ( Syntax context a, Syntax context b, Syntax context c ) -> Syntax context ( a, b, c )

Three element tuple tuple2 ( string, float, int ) => ( String, Float, Int )

node : a -> Elm.Syntax.Node.Node a

Small helper for building up Elm.Syntax expressions (zero-ed out node, empty range). There aren't many helpers in this module for building up custom types so I would feel bad for not at least offering this.