Sign in

    gleam-parser-morphir

    Optional Morphir target profile for moonrockz/gleam-parser

    gleam
    parser
    morphir
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    4 days ago
    Downloads
    20

    #Morphir target profile

    See the README with tested examples for installation, configuration, external functions and types, composition, and releases.

    Release history is in CHANGELOG.md.

    #Morphir target profile for gleam-parser

    This optional MoonBit module adds the morphir target to the core parser. It has its own release identity, moonrockz/gleam-parser-morphir@0.1.0, and requires core parser 0.5.0. Installing the core does not install this module.

    Install it with moon add moonrockz/gleam-parser-morphir. In moon.pkg, import:

    import { "moonrockz/gleam-parser" @gleam, "moonrockz/gleam-parser-morphir" @morphir, }

    #Parse a Morphir external function

    Enable the profile explicitly. @external retains the target, module, symbol, and source location. It does not restrict the definition to Morphir.

    ///|
    test "mr: retain a Morphir function binding" {
    let dialect = @gleam.Dialect::gleam_1_19().with_profile(@morphir.profile())
    let config = { ..@gleam.Config::default(), dialect, }
    let source = "@external(morphir, \"morphir/sdk/list\", \"length\")\npub fn length(xs: List(a)) -> Int\n"
    let result = @gleam.parse_text(source, config~)
    assert_eq(result.has_errors(), false)
    guard result.module_.definitions[0].definition is Function(function) else {
    fail("expected a function")
    }
    let target = dialect.targets.resolve("morphir").unwrap()
    let binding = function.external_for(target).unwrap()
    assert_eq(binding.module_, "morphir/sdk/list")
    assert_eq(binding.function, "length")
    assert_eq(result.module_.definitions[0].target, None)
    assert_eq(@gleam.format_parsed(result), source)
    assert_eq(
    @gleam.decode_extended(@gleam.encode_extended(result)).parsed,
    result.parsed(),
    )
    }

    #Retain a target restriction and an external type

    Use @target(morphir) for a definition's target restriction. Parsing retains all definitions. A consumer decides which target to translate later.

    ///|
    test "mr: external types and restrictions stay distinct" {
    let dialect = @gleam.Dialect::gleam_1_19().with_profile(@morphir.profile())
    let config = { ..@gleam.Config::default(), dialect, }
    let result = @gleam.parse_text(
    "@target(morphir)\n@external(morphir, \"example/domain\", \"CustomerId\")\npub type CustomerId\n",
    config~,
    )
    assert_eq(result.has_errors(), false)
    assert_eq(
    result.module_.definitions[0].target.map(t => t.name()),
    Some("morphir"),
    )
    guard result.module_.definitions[0].definition is CustomType(type_) else {
    fail("expected an external type")
    }
    assert_eq(type_.externals.all()[0].external.function, "CustomerId")
    assert_eq(
    @gleam.parse_text("@target(morphir) pub const x = 1").has_errors(),
    true,
    )
    assert_eq(dialect.knows_target("go"), false)
    }

    #Compose with another provider

    Other modules use the same public APIs. Conflicting registrations raise ProfileError; no registration silently overrides another.

    ///|
    test "mr: compose a separately defined target" {
    let scala = @gleam.Profile(
    "example/scala@1",
    [@gleam.Target::extension("scala")][:],
    )
    let dialect = @gleam.Dialect::gleam_1_19()
    .with_profile(@morphir.profile())
    .with_profile(scala)
    assert_eq(dialect.knows_target("morphir"), true)
    assert_eq(dialect.knows_target("scala"), true)
    let available = @gleam.Profiles([@morphir.profile(), scala][:])
    let config = @gleam.Config::from_toml(
    "[parser]\nprofiles = [\"moonrockz/gleam-parser-morphir@0.1.0\", \"example/scala@1\"]\n",
    profiles=available,
    ).to_config(@gleam.Config::default())
    assert_eq(config.dialect, dialect)
    }

    This module supplies no Morphir backend, symbol resolution, or foreign-call execution. Module and symbol strings are opaque. Use extended JSON to retain Morphir metadata. Compiler-compatible export raises NonStandardTarget. See the core target profile cookbook and migration guide.

    #Release this module

    Publish the required core version first. Run the Release Morphir profile workflow on the commit to release. Verify the module version on mooncakes.io, then create the morphir-v0.1.0 GitHub release at the same commit. Future profile releases update this module's manifest, version(), profile identity, and notes independently of the core version.

    profile

    Construct the optional Morphir profile through the public core API. It registers only morphir. Standard targets stay available; other extension targets stay unregistered. Importing this module does not enable the profile. Pass it to Dialect::with_profile explicitly. The registration supplies syntax and AST metadata, not a Morphir backend. Module and symbol strings are opaque references interpreted by consumers.

    test {
    let dialect = @gleam.Dialect::gleam_1_19().with_profile(@morphir.profile())
    let config = { ..@gleam.Config::default(), dialect, }
    let result = @gleam.parse_text(
    "@target(morphir) pub const answer = 42",
    config~,
    )
    assert_eq(result.has_errors(), false)
    assert_eq(dialect.knows_target("scala"), false)
    }

    version

    fn version() -> String

    Return the Morphir profile's release version. It is independent of the core parser version. This module requires core parser 0.5.0 or later.

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io