the-sett/elm-syntax-dsl/4.0.1

NOTE: the latest version is 6.0.5

Elm.CodeGen

Elm.CodeGen is a DSL designed to make it easier to write Elm code that generates Elm code.

Build an Elm source file.

file : Module -> List Import -> List Declaration -> List String -> File

Assembles all the components of an Elm file; the module declaration, the comments, the imports and the top-level declarations.

Build a module declaration.

elm-syntax also permits effects modules, but with kernel code restrictions you cannot use these so they have been ommitted from the DSL.

normalModule : ModuleName -> List TopLevelExpose -> Module

NormalModule DefaultModuleData

portModule : ModuleName -> List TopLevelExpose -> Module

PortModule DefaultModuleData

Build an 'exposing' statement.

exposeAll : Exposing

All Range

exposeExplicit : List TopLevelExpose -> Exposing

Explicit (List (Node TopLevelExpose))

closedTypeExpose : String -> TopLevelExpose

TypeExpose ExposedType

funExpose : String -> TopLevelExpose

FunctionExpose String

openTypeExpose : String -> TopLevelExpose

TypeExpose ExposedType

typeOrAliasExpose : String -> TopLevelExpose

TypeOrAliasExpose String

Build an import statement.

importStmt : ModuleName -> Maybe ModuleName -> Maybe Exposing -> Import

Creates an Elm import statement; the name of the module, an optional alias name for the module, and an optional list of exposings from the module.

Incrementally build import and exposing statements.

This is useful during code generation where the exact imports and exports are not known in advance but depend on what code is actually generated. Each section of code generation can declare the imports and exposings that it needs and they can be combined and de-duplicated to produce a final list.

I have used the name Linkage to refer to the combination of a modules imports and exports. It describes how a module is linked to other modules.

type alias Linkage =
( List Import, List TopLevelExpose )

Linkage describes the lists of imports and exposings of a module and allows these to be built up incrementally as code generation progresses.

addExposing : TopLevelExpose -> Linkage -> Linkage

Adds an exposing to the list.

addImport : Import -> Linkage -> Linkage

Adds an import to the list.

combineLinkage : List Linkage -> Linkage

Simplifies the imports and exposings by removing any duplicates.

emptyLinkage : Linkage

Creates empty imports and exposings lists.

Build top-level declarations.

aliasDecl : Maybe String -> String -> List String -> TypeAnnotation -> Declaration

AliasDeclaration TypeAlias

Maybe String
-> String
-> List String
-> List ( String, List TypeAnnotation )
-> Declaration

CustomTypeDeclaration Type

Maybe String
-> Maybe TypeAnnotation
-> String
-> List Pattern
-> Expression
-> Declaration

FunctionDeclaration Function

Maybe String
-> Maybe TypeAnnotation
-> String
-> Expression
-> Declaration

A top-level value declaration or constant.

portDecl : String -> TypeAnnotation -> Declaration

PortDeclaration Signature

Build an expression.

access : Expression -> String -> Expression

RecordAccess (Node Expression) (Node String)

accessFun : String -> Expression

RecordAccessFunction String

apply : List Expression -> Expression

Application (List (Node Expression))

caseExpr : Expression -> List ( Pattern, Expression ) -> Expression

CaseExpression CaseBlock

char : Char -> Expression

CharLiteral Char

float : Float -> Expression

Floatable Float

fqFun : ModuleName -> String -> Expression

FunctionOrValue ModuleName String

fqVal : ModuleName -> String -> Expression

FunctionOrValue ModuleName String

Note this is the same as fqFun

fun : String -> Expression

Creates a FunctionOrValue with no qualifiying module.

glsl : String -> Expression

GLSLExpression String

hex : Int -> Expression

Hex Int

ifExpr : Expression -> Expression -> Expression -> Expression

IfBlock (Node Expression) (Node Expression) (Node Expression)

int : Int -> Expression

Integer Int

lambda : List Pattern -> Expression -> Expression

LambdaExpression Lambda

letExpr : List LetDeclaration -> Expression -> Expression

LetExpression LetBlock

list : List Expression -> Expression

ListExpr (List (Node Expression))

negate : Expression -> Expression

Negation (Node Expression)

op : String -> Expression

Operator String

opApply : String -> InfixDirection -> Expression -> Expression -> Expression

OperatorApplication String InfixDirection (Node Expression) (Node Expression)

parens : Expression -> Expression

ParenthesizedExpression (Node Expression)

prefixOp : String -> Expression

PrefixOperator String

record : List ( String, Expression ) -> Expression

RecordExpr (List (Node RecordSetter))

string : String -> Expression

Literal String

tuple : List Expression -> Expression

TupledExpression (List (Node Expression))

unit : Expression

UnitExpr

update : String -> List ( String, Expression ) -> Expression

RecordUpdateExpression (Node String) (List (Node RecordSetter))

val : String -> Expression

Creates a FunctionOrValue with no qualifiying module.

Note this is the same as fun.

letFunction : String -> List Pattern -> Expression -> LetDeclaration

A function declared inside a let block.

letDestructuring : Pattern -> Expression -> LetDeclaration

A pattern matching declared inside a let block.

letVal : String -> Expression -> LetDeclaration

A value declared inside a let block.

infixLeft : InfixDirection

Denotes an infix operator that is left associative.

infixRight : InfixDirection

Denotes an infix operator that is right associative.

infixNon : InfixDirection

Denotes an infix operator that is non-associative.

Helper functions for common expression patterns.

chain : Expression -> List Expression -> Expression

Joins multiple expressions together with the function chain operator >>. An expression a combined with a list of expressions [b, c, d] results in:

a >> b >> c >> d
pipe : Expression -> List Expression -> Expression

Joins multiple expressions together with the pipe operator |>. An expression a combined with a list of expressions [b, c, d] results in:

a |> b |> c |> d

Build a pattern matching expression.

allPattern : Pattern

AllPattern

asPattern : Pattern -> String -> Pattern

AsPattern (Node Pattern) (Node String)

charPattern : Char -> Pattern

CharPattern Char

floatPattern : Float -> Pattern

FloatPattern Float

fqNamedPattern : ModuleName -> String -> List Pattern -> Pattern

NamedPattern QualifiedNameRef (List (Node Pattern))

hexPattern : Int -> Pattern

HexPattern Int

intPattern : Int -> Pattern

IntPattern Int

listPattern : List Pattern -> Pattern

ListPattern (List (Node Pattern))

namedPattern : String -> List Pattern -> Pattern

NamedPattern QualifiedNameRef (List (Node Pattern))

parensPattern : Pattern -> Pattern

ParenthesizedPattern (Node Pattern)

recordPattern : List String -> Pattern

RecordPattern (List (Node String))

stringPattern : String -> Pattern

StringPattern String

tuplePattern : List Pattern -> Pattern

TuplePattern (List (Node Pattern))

unConsPattern : Pattern -> Pattern -> Pattern

UnConsPattern (Node Pattern) (Node Pattern)

unitPattern : Pattern

UnitPattern

varPattern : String -> Pattern

VarPattern String

Build a type annotation.

extRecordAnn : String -> List ( String, TypeAnnotation ) -> TypeAnnotation

GenericRecord (Node String) (Node RecordDefinition)

fqTyped : ModuleName -> String -> List TypeAnnotation -> TypeAnnotation

Typed (Node ( ModuleName, String )) (List (Node TypeAnnotation))

funAnn : TypeAnnotation -> TypeAnnotation -> TypeAnnotation

FunctionTypeAnnotation (Node TypeAnnotation) (Node TypeAnnotation)

recordAnn : List ( String, TypeAnnotation ) -> TypeAnnotation

Record RecordDefinition

tupleAnn : List TypeAnnotation -> TypeAnnotation

Tupled (List (Node TypeAnnotation))

typeVar : String -> TypeAnnotation

GenericType String

typed : String -> List TypeAnnotation -> TypeAnnotation

Typed (Node ( ModuleName, String )) (List (Node TypeAnnotation))

unitAnn : TypeAnnotation

Unit

boolAnn : TypeAnnotation

A Bool type annotation.

intAnn : TypeAnnotation

An Int type annotation.

floatAnn : TypeAnnotation

A Float type annotation.

stringAnn : TypeAnnotation

A String type annotation.

charAnn : TypeAnnotation

A Char type annotation.

listAnn : TypeAnnotation -> TypeAnnotation

Creates a List type annotation.

setAnn : TypeAnnotation -> TypeAnnotation

Creates a Set type annotation.

dictAnn : TypeAnnotation -> TypeAnnotation -> TypeAnnotation

Creates a Dict type annotation.

maybeAnn : TypeAnnotation -> TypeAnnotation

Creates a Maybe type annotation.

Build a type signature.

signature : String -> TypeAnnotation -> Signature

Creates a type signature.

Types describing parts of the Elm AST.

These types are all declared in elm-syntax but are re-exported here for convenience.

type alias ModuleName =
List String

A module name can consist of mulitple Stirngs separated with '.'.

type alias Module =
Module

The AST for an Elm module.

type alias File =
File

The AST for an Elm file.

type alias Declaration =
Declaration

The AST for a top-level Elm declaration; a function, a value, a type or a type alias.

type alias Import =
Import

The AST for an Elm import statement.

type alias TypeAnnotation =
TypeAnnotation

The AST for an Elm type annotation.

type alias Exposing =
Exposing

The AST for an Elm exposing statement.

type alias TopLevelExpose =
TopLevelExpose

The AST for a member of an Elm exposing statement.

type alias Expression =
Expression

The AST for an Elm expression.

type alias Pattern =
Pattern

The AST for a de-structuring Elm pattern matching expression.