#justjavac/template_codegen/ast

    Shared template AST and source metadata.

    SourcePos

    pub(all) struct SourcePos {
    offset : Int
    line : Int
    column : Int
    } derive(Eq, ToJson,
    Debug
    )

    A 1-based source position plus the underlying string offset.

    offset is the raw string offset used by scanners, while line and column are intended for human-readable diagnostics.

    SourcePos::equal

    fn SourcePos::equal(SourcePos, SourcePos) -> Bool
    automatically derived

    SourcePos::not_equal

    fn SourcePos::not_equal(x : SourcePos, y : SourcePos) -> Bool

    SourcePos::to_json

    fn SourcePos::to_json(SourcePos) -> Json
    automatically derived

    SourcePos::to_repr

    automatically derived

    SourceSpan

    pub(all) struct SourceSpan {
    file : String
    start : SourcePos
    end : SourcePos
    } derive(Eq, ToJson,
    Debug
    )

    A half-open source span in one file.

    The start position points at the first character in the range and end points just after the range. This keeps parser and codegen diagnostics easy to map back to the original template or MoonBit source.

    SourceSpan::equal

    fn SourceSpan::equal(SourceSpan, SourceSpan) -> Bool
    automatically derived

    SourceSpan::not_equal

    fn SourceSpan::not_equal(x : SourceSpan, y : SourceSpan) -> Bool

    SourceSpan::to_json

    fn SourceSpan::to_json(SourceSpan) -> Json
    automatically derived

    SourceSpan::to_repr

    automatically derived

    Template

    pub(all) struct Template {
    path : String
    nodes : Array[TemplateNode]
    } derive(Eq, ToJson,
    Debug
    )

    A parsed template document.

    path identifies the source template for diagnostics, and nodes stores the parsed items in render order.

    Template::equal

    fn Template::equal(Template, Template) -> Bool
    automatically derived

    Template::not_equal

    fn Template::not_equal(x : Template, y : Template) -> Bool

    Template::to_json

    fn Template::to_json(Template) -> Json
    automatically derived

    Template::to_repr

    automatically derived

    TemplateBinding

    pub(all) struct TemplateBinding {
    source_path : String
    template_path : String
    struct_name : String
    field_names : Array[String]
    span : SourceSpan
    } derive(Eq, ToJson,
    Debug
    )

    A user struct bound to a template path by #tpl.path.

    Codegen uses the binding to connect a MoonBit struct with a template file. field_names records the struct fields that may be referenced without self. inside templates; generated code prefixes them automatically.

    TemplateBinding::equal

    automatically derived

    TemplateBinding::not_equal

    fn TemplateBinding::not_equal(x : TemplateBinding, y : TemplateBinding) -> Bool

    TemplateBinding::to_json

    automatically derived

    TemplateBinding::to_repr

    automatically derived

    TemplateNode

    pub(all) enum TemplateNode {
    Text(text~ : String, span~ : SourceSpan)
    EscapedExpr(expr~ : String, span~ : SourceSpan)
    RawExpr(expr~ : String, span~ : SourceSpan)
    Statement(code~ : String, span~ : SourceSpan)
    Include(path~ : String, span~ : SourceSpan)
    Comment(text~ : String, span~ : SourceSpan)
    } derive(Eq, ToJson,
    Debug
    )

    One parsed template item.

    Nodes preserve source spans so downstream tools can report precise errors. Escaped expressions correspond to <%= ... %>, raw expressions correspond to <%- ... %>, statements correspond to <% ... %>, includes correspond to <%~ "path" %>, and comments correspond to <%# ... %>.

    TemplateNode::equal

    automatically derived

    TemplateNode::not_equal

    fn TemplateNode::not_equal(x : TemplateNode, y : TemplateNode) -> Bool

    TemplateNode::to_json

    automatically derived

    TemplateNode::to_repr

    automatically derived

    comment_node

    fn comment_node(text : String, span : SourceSpan) -> TemplateNode

    Creates a template comment node.

    Comments are preserved in the AST for tooling, but they do not emit output.

    escaped_expr_node

    fn escaped_expr_node(expr : String, span : SourceSpan) -> TemplateNode

    Creates an escaped expression output node.

    Generated renderers evaluate the expression, format it with Show, and HTML-escape the formatted value before writing it.

    include_node

    fn include_node(path : String, span : SourceSpan) -> TemplateNode

    Creates a static include node.

    File-based codegen expands include nodes before emitting MoonBit source.

    pos

    fn pos(offset~ : Int, line~ : Int, column~ : Int) -> SourcePos

    Creates a source position for diagnostics and source spans.

    raw_expr_node

    fn raw_expr_node(expr : String, span : SourceSpan) -> TemplateNode

    Creates a raw expression output node.

    Generated renderers evaluate the expression and write the formatted value without HTML escaping, so callers should use it only for trusted content.

    span

    fn span(file~ : String, start~ : SourcePos, end~ : SourcePos) -> SourceSpan

    Creates a half-open source span for a single file.

    statement_node

    fn statement_node(code : String, span : SourceSpan) -> TemplateNode

    Creates a MoonBit statement node.

    Statement nodes are copied into the generated renderer after template field references and short filters have been qualified by codegen.

    template

    fn template(path~ : String, nodes~ : Array[TemplateNode]) -> Template

    Creates a parsed template document from a path and node sequence.

    template_binding

    fn template_binding(source_path~ : String, template_path~ : String, struct_name~ : String, field_names? : Array[String], span~ : SourceSpan) -> TemplateBinding

    Creates a template binding discovered in MoonBit source.

    This constructor is useful for tests and custom scanners that want to feed bindings into the code generator without parsing files again.

    text_node

    fn text_node(text : String, span : SourceSpan) -> TemplateNode

    Creates a plain text node.

    Text nodes are emitted directly as string writes by the generator.

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io