Elm to Morphir IR (the frontend) and Morphir IR to Elm generation with moonrockz/krueger
[pipeline]
backend = "elm"
[backends.elm]
profile = "model" # "model" (default) | "literal"
placeholders = "refuse" # "refuse" (default) | "debug-todo"
width = 120
elm_package = "finos/morphir-elm 22.0.2"
[backends.elm.mapping]
"morphir/SDK:basics#add" = { operator = "+" }
"morphir/SDK:list#map" = { function = "List.map" }
"morphir/SDK:decimal#decimal" = { type = "Decimal.Decimal", import = "MyCo.Decimal as Decimal" }
"morphir/SDK:basics#max" = {}
[backends.elm.packages]
"acme/common" = { package = "acme/common 1.0.0" }add : Int -> Int -> Int
add a b =
a + badd : Morphir.SDK.Basics.Int -> Morphir.SDK.Basics.Int -> Morphir.SDK.Basics.Int
add a b =
Morphir.SDK.Basics.add a belm.json
morphir.json
src/<Package>/<Module>.elm@morphir.entry { kind = "main", name = "run" }
@morphir.annotation { fqname = "acme/api:tags#stable" }
@morphir.external { platform = "js", name = "Math.max" }| Code | Cause |
|---|---|
| elm.tuple_arity | A tuple with fewer than two or more than three elements. Elm tuples have two or three. |
| elm.derived_type | A derived type. |
| elm.decimal_literal | A decimal literal. There is no decimal construction mapping yet. |
| elm.placeholder | A construct with no body while placeholders = "refuse", a custom type with no constructors, or an incomplete type definition. |
| elm.invalid_mapping | A mapping entry that is not valid, for example a bad key or a constructor that maps to an operator. |
| elm.print | krueger could not print the AST. The path names the IR declaration. This is a backend defect. |
| elm.int_literal | An integer lexeme outside the Int64 range. |
| elm.document_literal | A document literal. Elm has no document literal. |
| elm.literal_pattern | A float or decimal pattern. Elm rejects these patterns. |
| elm.unsupported_constraint | A typeclass constraint that has no Elm class, or that is not text or a list of text. |
| elm.name_collision | Two IR names in one module give the same Elm name. |
| elm.annotation_argument | A structured annotation argument that is not data. |
| elm.invalid_option | An unknown option key or a bad option value. |
| elm.cancelled | The caller cancelled the generation. |
pub fn compile_project(
sources : Array[ElmSource], // every .elm file: path relative to the source directory, and content
package_name : String, // the dotted package name, for example "My.Pkg"
exposed : Array[String], // the exposed modules relative to the package, as in morphir.json
output? : OutputModules = Parity, // Parity: the modules of morphir-elm; Referenced: also every module the output names
) -> @ir.IRFile raise ElmFailed| Code | Cause |
|---|---|
| elm.parse | A file does not parse. |
| elm.module_name | The module name does not match the file path, or does not start with the package name. |
| elm.import_cycle | The imports form a cycle. The problem is at the import that closes the cycle. |
| elm.exposed_module | The exposed list is empty, or an exposed module has no source file. |
| elm.unresolved_name | A name, or an entry of an exposing list, that does not resolve. |
| elm.ambiguous_name | A name used in the code that two imports give with different meanings. |
| elm.unsupported_module | An import of a module that is not a project, elm/core, platform or Morphir.SDK module. |
| elm.unsupported_value | A reference to an elm/core value or operator that has no Morphir SDK binding, or an operator that is not in the operator table (rule 13). |
| elm.unsupported | A port, an effect module, an infix declaration, top-level destructuring, a record pattern, a recursive destructuring in a let block, GLSL, an operator in the exposing list of a module, or a name from Debug, Platform, Platform.Cmd or Platform.Sub (for example Debug.log, Cmd or Program). |
| elm.unbound_type_variable | A type variable that the type alias or custom type does not declare. |
| elm.type | A type error that inference finds. The message is the inference problem (<code> at <logical path>: <message>), the path is the source of its module and the location is the source of its node, when it is known. |
| Operator | Function | Operator | Function | Operator | Function |
|---|---|---|---|---|---|
| \|\| | or | <= | lessThanOrEqual | / | divide |
| && | and | >= | greaterThanOrEqual | // | integerDivide |
| == | equal | ++ | append | ^ | power |
| /= | notEqual | + | add | << | composeLeft |
| < | lessThan | - | subtract | >> | composeRight |
| > | greaterThan | * | multiply | :: | list#cons |
moon test pkgs/morphir-elm/backend # unit and generation tests
moon test pkgs/morphir-elm/conformance # frontend parity with morphir-elm make and the IR round trip
mise run test:elm # elm make on the generated fixture projects
mise run elm:parity-refresh # regenerate the parity corpus after a project changeInstall
Download zipElm to Morphir IR (the frontend) and Morphir IR to Elm generation with moonrockz/krueger