vigoo/moonbit_codegen/doc does not have a README file

    CodegenError

    pub(all) suberror CodegenError {
    CodegenError(String)
    } derive(Eq,
    Debug
    )

    Error raised by generation (e.g. a raw body that fails to parse). Match the payload: catch { CodegenError(message) => ... }.

    AbstractTypeDecl

    pub(all) struct AbstractTypeDecl {
    name : String
    type_params : Array[String]
    vis : Visibility
    } derive(Eq,
    Debug
    )

    Abstract type: pub type Handle.

    AliasDecl

    pub(all) struct AliasDecl {
    name : String
    type_params : Array[String]
    target : TypeExpr
    vis : Visibility
    } derive(Eq,
    Debug
    )

    A type alias declaration: [vis] typealias Target as Name / pub type Name = Target.

    Attribute

    pub struct Attribute {
    name : String
    payload : String?
    } derive(Eq,
    Debug
    )

    An attribute, e.g. #derive(Debug, Eq) or a bare #deprecated.

    Attribute::bare

    fn Attribute::bare(name : String) -> Attribute

    Bare attribute #<name> with no payload.

    Attribute::derive_from

    fn Attribute::derive_from(traits : Array[String]) -> Attribute?

    #derive(...) from trait names; None for an empty list.

    Attribute::with_payload

    fn Attribute::with_payload(name : String, payload : String) -> Attribute

    Attribute with parenthesized payload #<name>(<payload>).

    Decl

    pub(all) enum Decl {
    Struct(StructDecl)
    Enum(EnumDecl)
    Suberror(SuberrorDecl)
    Newtype(NewtypeDecl)
    AbstractType(AbstractTypeDecl)
    Alias(AliasDecl)
    Trait(TraitDecl)
    Impl(ImplDecl)
    Extend(ExtendDecl)
    Fn(FnDecl)
    Let(LetDecl)
    Test(TestDecl)
    Using(UsingDecl)
    Raw(String)
    } derive(Eq,
    Debug
    )

    Any top-level MoonBit declaration representable in a SourceFile.

    DocComment

    pub struct DocComment {
    // private fields
    } derive(Eq,
    Debug
    )

    A doc comment as raw lines — no /// prefixes, "" for blank lines. Renderers apply the MoonBit convention (/// text, blank ///) and the leading-space rule themselves.

    DocComment::copy_lines

    fn DocComment::copy_lines(self : DocComment) -> Array[String]

    Return a defensive copy of the raw doc comment lines.

    DocComment::empty

    fn DocComment::empty() -> DocComment

    An empty doc comment (renders nothing).

    DocComment::is_empty

    fn DocComment::is_empty(self : DocComment) -> Bool

    True when the doc comment has no lines.

    DocComment::new

    fn DocComment::new(lines : Array[String]) -> DocComment

    Construct a DocComment from raw lines (without /// prefixes).

    EnumDecl

    pub(all) struct EnumDecl {
    name : String
    type_params : Array[String]
    vis : Visibility
    variants : Array[EnumVariant]
    derives : Array[String]
    non_exhaustive : Bool
    } derive(Eq,
    Debug
    )

    An enum declaration: [vis] enum Name[T] { variants... }.

    EnumVariant

    pub(all) struct EnumVariant {
    name : String
    payload : Array[(String?, TypeExpr)]
    doc : DocComment
    } derive(Eq,
    Debug
    )

    An enum (or suberror) variant: unit when payload is empty, otherwise one labelled or positional argument per entry.

    ErrorSpec

    pub(all) enum ErrorSpec {
    NoRaise
    DefaultRaise
    TypedRaise(TypeExpr)
    ExplicitNoraise
    } derive(Eq,
    Debug
    )

    Error specification on a function, method, trait method, impl, or function type.

    ExtendDecl

    pub(all) struct ExtendDecl {
    vis : Visibility
    type_name : TypeExpr
    trait_ : TypeExpr
    methods : Array[String]
    } derive(Eq,
    Debug
    )

    [vis] extend <type_name> with <trait_>::{methods} — exposes trait methods for dot-call syntax.

    FnDecl

    pub(all) struct FnDecl {
    self_type : String?
    name : String
    type_params : Array[TypeParam]
    params : Array[FnParam]
    return_type : TypeExpr?
    is_async : Bool
    error : ErrorSpec
    vis : Visibility
    body : String
    } derive(Eq,
    Debug
    )

    A top-level function or a method (self_type is Some).

    body is raw MoonBit statement source; "" renders an empty body.

    FnParam

    pub(all) struct FnParam {
    name : String
    ty : TypeExpr?
    kind : ParamKind
    } derive(Eq,
    Debug
    )

    A single parameter on a function, method, trait method, or impl.

    FnParam::defaulted

    fn FnParam::defaulted(name : String, ty : TypeExpr, default_src : String) -> FnParam

    Labelled parameter with a default value expression name~ : T = <default_src>.

    FnParam::discard

    fn FnParam::discard(ty : TypeExpr) -> FnParam

    _ : T discarded positional parameter.

    FnParam::labelled

    fn FnParam::labelled(name : String, ty : TypeExpr) -> FnParam

    Required labelled parameter name~ : T.

    FnParam::optional

    fn FnParam::optional(name : String, ty : TypeExpr) -> FnParam

    Optional labelled parameter name? : T (callee receives T?).

    FnParam::positional

    fn FnParam::positional(name : String, ty : TypeExpr) -> FnParam

    Positional parameter name : T.

    ImplDecl

    pub(all) struct ImplDecl {
    vis : Visibility
    type_params : Array[TypeParam]
    method_type_params : Array[TypeParam]
    self_type : TypeExpr
    trait_ : TypeExpr
    method_name : String
    params : Array[FnParam]
    return_type : TypeExpr?
    error : ErrorSpec
    body : String
    } derive(Eq,
    Debug
    )

    [vis] impl[type_params] <trait_> for <self_type> with fn <method>(...) { body }.

    Item

    pub struct Item {
    doc : DocComment
    decl : Decl
    // private fields
    } derive(Eq,
    Debug
    )

    One top-level item: doc comment, attributes and the declaration itself.

    Item::copy_attrs

    fn Item::copy_attrs(self : Item) -> Array[Attribute]

    Return a defensive copy of the item's attributes.

    Item::new

    fn Item::new(doc? : DocComment, attrs? : Array[Attribute], decl : Decl) -> Item

    Construct a top-level Item with optional doc comment and attributes.

    LetDecl

    pub(all) struct LetDecl {
    name : String
    ty : TypeExpr?
    value : String
    is_const : Bool
    vis : Visibility
    } derive(Eq,
    Debug
    )

    A top-level let or const binding.

    NewtypeDecl

    pub(all) struct NewtypeDecl {
    name : String
    type_params : Array[String]
    vis : Visibility
    fields : Array[TypeExpr]
    derives : Array[String]
    } derive(Eq,
    Debug
    )

    Tuple struct / newtype: pub(all) struct Id(String).

    ParamKind

    pub(all) enum ParamKind {
    Positional
    DiscardPositional
    Labelled
    QuestionOptional
    Default(String)
    } derive(Eq,
    Debug
    )

    Parameter passing style.

    • Positional — name : T
    • DiscardPositional — _ : T
    • Labelled — name~ : T
    • QuestionOptional — name? : T (argument becomes T?)
    • Default(src) — name~ : T = <src> where src is raw expression source

    SourceFile

    pub struct SourceFile {
    // private fields
    } derive(Eq,
    Debug
    )

    A source file: leading header comments plus ordered items. Renderers turn it into text; fmt.render_file is the MoonBit renderer.

    SourceFile::copy_items

    fn SourceFile::copy_items(self : SourceFile) -> Array[Item]

    Return a defensive copy of the top-level items in emission order.

    SourceFile::header_lines

    fn SourceFile::header_lines(self : SourceFile) -> Array[String]

    Return a defensive copy of the leading header lines.

    SourceFile::length

    fn SourceFile::length(self : SourceFile) -> Int

    Number of top-level items currently in the file.

    SourceFile::new

    fn SourceFile::new() -> SourceFile

    Create an empty SourceFile with no header comments.

    SourceFile::push

    fn SourceFile::push(self : SourceFile, item : Item) -> Unit

    Append a top-level item to the file.

    SourceFile::with_header

    fn SourceFile::with_header(header : Array[String]) -> SourceFile

    Create an empty SourceFile with leading // header lines.

    StructDecl

    pub(all) struct StructDecl {
    name : String
    type_params : Array[String]
    vis : Visibility
    fields : Array[StructField]
    derives : Array[String]
    } derive(Eq,
    Debug
    )

    A struct declaration: [vis] struct Name[T] { fields... }.

    StructField

    pub(all) struct StructField {
    name : String
    ty : TypeExpr
    mut_ : Bool
    vis : Visibility
    doc : DocComment
    attrs : Array[Attribute]
    } derive(Eq,
    Debug
    )

    A struct field.

    SuberrorDecl

    pub(all) struct SuberrorDecl {
    name : String
    vis : Visibility
    variants : Array[EnumVariant]
    derives : Array[String]
    } derive(Eq,
    Debug
    )

    suberror Name { ... } (or unit suberror Name when variants is empty).

    TestDecl

    pub(all) struct TestDecl {
    name : String?
    is_async : Bool
    body : String
    } derive(Eq,
    Debug
    )

    A top-level test or async test block.

    TraitDecl

    pub(all) struct TraitDecl {
    name : String
    vis : Visibility
    supers : Array[TypeExpr]
    methods : Array[TraitMethod]
    } derive(Eq,
    Debug
    )

    A trait declaration: [vis] trait Name : Super1 + Super2 { methods... }.

    TraitMethod

    pub(all) struct TraitMethod {
    name : String
    type_params : Array[TypeParam]
    params : Array[FnParam]
    return_type : TypeExpr?
    is_async : Bool
    error : ErrorSpec
    has_default : Bool
    attrs : Array[Attribute]
    } derive(Eq,
    Debug
    )

    A trait method declaration. Set has_default: true to emit = _.

    TypeExpr

    pub(all) enum TypeExpr {
    Name(String)
    Qualified(pkg~ : String, name~ : String)
    Applied(base~ : TypeExpr, args~ : Array[TypeExpr])
    Option(TypeExpr)
    Tuple(Array[TypeExpr])
    Arrow(args~ : Array[TypeExpr], ret~ : TypeExpr, error~ : ErrorSpec, is_async~ : Bool)
    Object(TypeExpr)
    Raw(String)
    } derive(Eq,
    Debug
    )

    A small type-expression tree. Raw is the escape hatch for anything the tree does not cover.

    TypeExpr::array

    fn TypeExpr::array(inner : TypeExpr) -> TypeExpr

    Array[T].

    TypeExpr::map

    fn TypeExpr::map(value : TypeExpr) -> TypeExpr

    Map[String, T].

    TypeExpr::object

    fn TypeExpr::object(trait_ : TypeExpr) -> TypeExpr

    &Trait trait object type.

    TypeExpr::optional

    fn TypeExpr::optional(inner : TypeExpr) -> TypeExpr

    T?.

    TypeExpr::qualified

    fn TypeExpr::qualified(pkg : String, name : String) -> TypeExpr

    @pkg.Type style reference.

    TypeParam

    pub(all) struct TypeParam {
    name : String
    constraints : Array[TypeExpr]
    } derive(Eq,
    Debug
    )

    A quantified type parameter with optional trait constraints (T or T : TraitA + TraitB).

    TypeParam::bounded

    fn TypeParam::bounded(name : String, constraints : Array[TypeExpr]) -> TypeParam

    Type parameter constrained by one or more traits (T : A + B).

    TypeParam::plain

    fn TypeParam::plain(name : String) -> TypeParam

    Unconstrained type parameter T.

    UsingDecl

    pub(all) struct UsingDecl {
    pkg : String
    entries : Array[String]
    vis : Visibility
    } derive(Eq,
    Debug
    )

    pub using @pkg {entries} facade re-export. Entry syntax: "name" (value), "type Name", "trait Name".

    Visibility

    pub(all) enum Visibility {
    Private
    Priv
    Pub
    PubAll
    PubOpen
    PubReadonly
    } derive(Eq,
    Debug
    )

    Declaration visibility.
    • Private: default / implicit (no visibility modifier)
    • Priv: explicit priv
    • Pub: pub
    • PubAll: pub(all)
    • PubOpen: pub(open)
    • PubReadonly: pub(readonly)

    enum_item

    fn enum_item(doc : DocComment, decl : EnumDecl) -> Item

    Shorthand: enum item (#derive and #non_exhaustive are synthesized by the renderer from decl).

    item

    fn item(doc : DocComment, decl : Decl) -> Item

    Shorthand: plain item with a doc comment and no extra attributes.

    item_with_attrs

    fn item_with_attrs(doc : DocComment, attrs : Array[Attribute], decl : Decl) -> Item

    Shorthand: item with a doc comment and explicit attributes (#deprecated, #alias, #cfg, #warnings, …).

    struct_item

    fn struct_item(doc : DocComment, decl : StructDecl) -> Item

    Shorthand: struct item (#derive is synthesized by the renderer from decl.derives).

    suberror_item

    fn suberror_item(doc : DocComment, decl : SuberrorDecl) -> Item

    Shorthand: suberror item (#derive is synthesized by the renderer from decl.derives).