Elm.CodeGen is a DSL designed to make it easier to write Elm code that generates Elm code.
elm-syntax also permits effects modules, but with kernel code restrictions you cannot use these so
they have been ommitted from the DSL.
NormalModule DefaultModuleData
PortModule DefaultModuleData
All Range
Explicit (List (Node TopLevelExpose))
TypeExpose ExposedType
FunctionExpose String
TypeExpose ExposedType
TypeOrAliasExpose String
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.
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.
Linkage describes the lists of imports and exposings of a module and allows these to be built up incrementally as code generation progresses.
Adds an exposing to the list.
Adds an import to the list.
Simplifies the imports and exposings by removing any duplicates.
Creates empty imports and exposings lists.
A structured representation of an Elm comment on a file or declaration.
A comment type for doc comments on top-level declarations.
A comment type for file comments at the head of a .elm file.
Creates an empty documenting comment that will go on a declaration.
Creates an empty comment that will go on a module file.
Adds some markdown to a comment.
Adds a code block to a comment.
Adds a set of doc tags to a comment.
Doc tags will never be merged into a single line, but if they are too long to fit the page width, the pretty printer can break them into separate lines.
Adds a set of doc tags taking from a description of what a module exposes, into a comment.
Doc tags will never be merged into a single line, but if they are too long to fit the page width, the pretty printer can break them into separate lines.
AliasDeclaration TypeAlias
CustomTypeDeclaration Type
FunctionDeclaration Function
A top-level value declaration or constant.
PortDeclaration Signature
Represents all of the binary operators allowed in Elm.
Creates a binary operator in its prefix form, as a bracketed expression.
binOp equalsYields:
(=)Applies a binary operator to left and right expressions. This takes the
expression in the order that is usual; that being expr op expr.
applyBinOp (int 2) plus (int 3)Yields:
2 + 3There is only one unary operator in Elm, and that is the minus sign prefixed onto some numeric expression.
applyUnaryMinus (int 5)Yields:
-5RecordAccess (Node Expression) (Node String)
RecordAccessFunction String
Application (List (Node Expression))
Apply a named constructor to a list of arguments.
CaseExpression CaseBlock
CharLiteral Char
Floatable Float
Apply a named constructor fully qualified with a module name, to a list of arguments.
FunctionOrValue ModuleName String
FunctionOrValue ModuleName String
Note this is the same as fqFun
Creates a FunctionOrValue with no qualifiying module.
GLSLExpression String
Hex Int
IfBlock (Node Expression) (Node Expression) (Node Expression)
Integer Int
LambdaExpression Lambda
LetExpression LetBlock
ListExpr (List (Node Expression))
Negation (Node Expression)
ParenthesizedExpression (Node Expression)
RecordExpr (List (Node RecordSetter))
Literal String
TupledExpression (List (Node Expression))
UnitExpr
RecordUpdateExpression (Node String) (List (Node RecordSetter))
Creates a FunctionOrValue with no qualifiying module.
Note this is the same as fun.
A function declared inside a let block.
A pattern matching declared inside a let block.
A value declared inside a let block.
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 >> dJoins multiple expressions together with the pipe operator |>. An
expression a combined with a list of expressions [b, c, d] results in:
a |> b |> c |> dAllPattern
AsPattern (Node Pattern) (Node String)
CharPattern Char
FloatPattern Float
NamedPattern QualifiedNameRef (List (Node Pattern))
HexPattern Int
IntPattern Int
ListPattern (List (Node Pattern))
NamedPattern QualifiedNameRef (List (Node Pattern))
ParenthesizedPattern (Node Pattern)
RecordPattern (List (Node String))
StringPattern String
TuplePattern (List (Node Pattern))
UnConsPattern (Node Pattern) (Node Pattern)
UnitPattern
VarPattern String
GenericRecord (Node String) (Node RecordDefinition)
Typed (Node ( ModuleName, String )) (List (Node TypeAnnotation))
FunctionTypeAnnotation (Node TypeAnnotation) (Node TypeAnnotation)
Record RecordDefinition
Tupled (List (Node TypeAnnotation))
GenericType String
Typed (Node ( ModuleName, String )) (List (Node TypeAnnotation))
Unit
A Bool type annotation.
An Int type annotation.
A Float type annotation.
A String type annotation.
A Char type annotation.
Creates a List type annotation.
Creates a Set type annotation.
Creates a Dict type annotation.
Creates a Maybe type annotation.
Creates a type signature.
These types are all declared in elm-syntax but are re-exported here for convenience.
A module name can consist of mulitple Stirngs separated with '.'.
The AST for an Elm module.
The AST for an Elm file.
The AST for a top-level Elm declaration; a function, a value, a type or a type alias.
The AST for an Elm import statement.
The AST for an Elm type annotation.
The AST for an Elm exposing statement.
The AST for a member of an Elm exposing statement.
The AST for an Elm expression.
The AST for a de-structuring Elm pattern matching expression.
The AST for an Elm let declaration.
Assembles all the components of an Elm file; the module declaration, the comments, the imports and the top-level declarations.