A MoonBit AST printer for string serialization of Abstract Syntax Tree nodes from moonbitlang/parser/syntax, designed for code generation and AST visualization workflows.
///|
test "basic printing" {
let source = "let value = 42"
let parsed = @parser.parse_string(source).0.unsafe_head()
let output = @printer.to_string(parsed)
inspect(output, content="let value = 42")
}///|
test "custom printing with StringBuilder" {
let source = "let result = 1 + 2 * 3"
let parsed = @parser.parse_string(source).0.unsafe_head()
let builder = StringBuilder::new()
@printer.SyntaxPrinter::print(parsed, builder)
let result = builder.to_string()
inspect(result, content="let result = 1 + 2 * 3")
}///|
test "function declaration printing" {
let func_source = "fn add(x : Int, y : Int) -> Int { x + y }"
let parsed = @parser.parse_string(func_source).0.unsafe_head()
let printed = @printer.to_string(parsed)
inspect(printed, content="fn add(x : Int, y : Int) -> Int { x + y }")
}///|
test "type definition printing" {
let type_source = "struct Point { x : Int; y : Int }"
let parsed = @parser.parse_string(type_source).0.unsafe_head()
let output = @printer.to_string(parsed)
inspect(output, content="struct Point { x : Int; y : Int; }")
}impl SyntaxPrinter for Accessorimpl SyntaxPrinter for Argumentimpl SyntaxPrinter for ArgumentKindimpl SyntaxPrinter for ArrayPatternimpl SyntaxPrinter for ArrayPatternsimpl SyntaxPrinter for Binderimpl SyntaxPrinter for Constantimpl SyntaxPrinter for ConstrIdimpl SyntaxPrinter for ConstrNameimpl SyntaxPrinter for ConstrPatArgimpl SyntaxPrinter for Constructorimpl SyntaxPrinter for DeclBodyimpl SyntaxPrinter for DotDotBinderimpl SyntaxPrinter for ErrorTypeimpl SyntaxPrinter for Exprimpl SyntaxPrinter for FieldDefimpl SyntaxPrinter for FieldPatimpl SyntaxPrinter for FunDeclimpl SyntaxPrinter for Funcimpl SyntaxPrinter for Implimpl SyntaxPrinter for Labelimpl SyntaxPrinter for LongIdentimpl SyntaxPrinter for MapPatElemimpl SyntaxPrinter for Parameterimpl SyntaxPrinter for Patternimpl SyntaxPrinter for SpreadableElemimpl SyntaxPrinter for Typeimpl SyntaxPrinter for TypeDeclimpl SyntaxPrinter for TypeNameimpl SyntaxPrinter for TypeVarBinderimpl SyntaxPrinter for TypeVarConstraintimpl SyntaxPrinter for Varimpl SyntaxPrinter for VisibilityInstall
Download zipA MoonBit AST printer for string serialization of Abstract Syntax Tree nodes from moonbitlang/parser/syntax, designed for code generation and AST visualization workflows.