mproc_gen

moon add Milky2018/mproc_gen@0.1.0
Download zip
Author
Version
0.1.0
License
Apache-2.0
Last updated
2 months ago
Downloads
34

Dependencies

README

#Milky2018/mproc_gen

Attribute-agnostic generator runner support for MoonBit code generators.

mproc_gen exposes the runner-facing API shape:

  • GenerationPlan stores the explicit input files and output target.
  • parse_runner_cli parses positional input files plus the fixed -o <output> option.
  • ParsedSource stores one successfully parsed MoonBit input.
  • generate runs generation and writes the emitted source to the output target.
  • generate_to_string parses the input sources and runs the callback into a builder.
  • GenerationCallback emits generated MoonBit source into a runner-owned StringBuilder.
  • ParseFailure reports runner-level read or parse failures.
  • GenerationFailure reports callback-level failures with a message.

It does not interpret attributes, infer package context, or depend on mproc_attr.

#Minimal downstream callback

///|
test "minimal downstream callback" {
@fs.create_dir(".test-tmp") catch {
_ => ()
}
@fs.create_dir(".test-tmp/mproc_gen") catch {
_ => ()
}
let input_path = ".test-tmp/mproc_gen/readme_input.mbt"
@fs.write_string_to_file(input_path, "fn source() -> Unit { () }\n")
let plan = @mproc_gen.GenerationPlan::{
input_paths: [input_path],
output_path: ".test-tmp/mproc_gen/readme_output.g.mbt",
}
let generated = @mproc_gen.generate_to_string(plan, fn(sources, out) {
match sources[:] {
[source] => out.write_string("// generated from \{source.path}")
_ => abort("expected one parsed source")
}
}) catch {
@mproc_gen.ParseFailure(message) =>
abort("unexpected parse failure: \{message}")
@mproc_gen.GenerationFailure(message) =>
abort("unexpected generation failure: \{message}")
_ => abort("unexpected runner failure")
}
inspect(
generated,
content="// generated from .test-tmp/mproc_gen/readme_input.mbt",
)
}

#
GenerationCallback

type GenerationCallback = (Array[ParsedSource], StringBuilder) -> Unit raise GenerationFailure

A downstream generator callback that emits into the runner-owned builder.

#
GenerationFailure

pub(all) suberror GenerationFailure {
GenerationFailure(String)
} derive(
Debug
)

Callback-level failure reported by a downstream generator.

#
GenerationFailure::message

fn GenerationFailure::message(self : GenerationFailure) -> String

#
ParseFailure

pub(all) suberror ParseFailure {
ParseFailure(String)
} derive(
Debug
)

Runner-level failure caused by an input source that cannot be parsed.

#
ParseFailure::message

fn ParseFailure::message(self : ParseFailure) -> String

#
RunnerCliError

pub(all) suberror RunnerCliError {
RunnerCliError(String)
} derive(
Debug
)

CLI-level failure for the fixed runner command-line contract.

#
RunnerCliError::message

fn RunnerCliError::message(self : RunnerCliError) -> String

#
GenerationPlan

pub(all) struct GenerationPlan {
input_paths : Array[String]
output_path : String
}

The explicit inputs and output target for one generator run.

#
ParsedSource

pub(all) struct ParsedSource {
path : String
ast :
List
[
Impl
]
}

A successfully parsed MoonBit source input.

#
generate

fn generate(plan : GenerationPlan, callback : (Array[ParsedSource], StringBuilder) -> Unit raise GenerationFailure) -> Unit raise

Run generation and write the emitted source to the explicit output target.

#
generate_to_string

fn generate_to_string(plan : GenerationPlan, callback : (Array[ParsedSource], StringBuilder) -> Unit raise GenerationFailure) -> String raise

Parse the input sources and invoke the callback with a runner-owned builder.

#
parse_runner_cli

fn parse_runner_cli(argv : ArrayView[String]) -> GenerationPlan raise RunnerCliError

Parse the fixed runner CLI contract: positional inputs and one -o value.

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io