Sign in

    ast_printer

    A pretty printer for MoonBit AST - converts parsed AST back to source code

    parser
    printer
    ast
    source-code
    Download zip
    Author
    Version
    0.2.4
    License
    Apache-2.0
    Last updated
    5 months ago
    Downloads
    53

    Dependencies

    #MoonBit AST Printer

    A pretty printer for MoonBit AST that converts parsed AST back to source code.

    #Installation

    { "deps": { "mizchi/ast_printer": "0.1.0" } }

    #Usage

    let source = "fn hello() -> String { \"hello\" }"
    let parsed = @moonbitlang/parser.parse_string(source)

    // Print back to source code (returns None if parse errors)
    let result : String? = @mizchi/ast_printer.print_code(parsed)

    // Or print AST directly
    let (impls, _) = parsed
    let code : String = @mizchi/ast_printer.print_impls(impls)

    #API

    • print_code(parsed) - Convenience function that takes parse result, returns String?
    • print_impls(impls) - Print top-level implementations to string
    • print_expr(buf, expr) - Print expression to StringBuilder
    • print_type(buf, ty) - Print type to StringBuilder
    • print_pattern(buf, pat) - Print pattern to StringBuilder
    • print_constant(buf, c) - Print constant to StringBuilder

    Print parsed code back to a string. This is a convenience function that takes the result of parse_string directly. Returns None if there are parse errors.
    fn print_constant(buf : StringBuilder, c :
    Constant
    ) -> Unit

    Print a constant value.
    fn print_expr(buf : StringBuilder, expr :
    Expr
    , indent? : Int) -> Unit

    Print an expression.

    Print a list of top-level implementations to a string.
    fn print_pattern(buf : StringBuilder, pat :
    Pattern
    ) -> Unit

    Print a pattern.
    fn print_type(buf : StringBuilder, ty :
    Type
    ) -> Unit

    Print a type expression.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io