#@core

    Shared error types used across the parser pipeline. Most callers see these through parse(...).errors or by catching @core.HtmlError from a sanitize/serialize call.

    The examples below are mbt check blocks and run as part of moon test core.

    #ParseError

    A single parse diagnostic. code is the spec-style identifier; category distinguishes tokenizer from tree-builder issues; line/column are UTF-16 1-based positions when known.

    ///|
    test "readme ParseError" {
    let err = @core.ParseError(
    "unexpected-null-character",
    line=3,
    column=14,
    category="tokenizer",
    )
    debug_inspect(
    err,
    content=(
    #|{
    #| code: "unexpected-null-character",
    #| line: Some(3),
    #| column: Some(14),
    #| category: "tokenizer",
    #| message: "unexpected-null-character",
    #|}
    ),
    )
    }

    When category and message are omitted, they default to the code itself; positions default to None.

    #parser_error_category

    Maps a parser-error code to its canonical category. Useful when you want to bucket diagnostics without writing a per-code switch.

    ///|
    test "readme parser_error_category" {
    debug_inspect(
    (
    @core.parser_error_category("unexpected-null-character"),
    @core.parser_error_category("unexpected-end-tag"),
    ),
    content=(
    #|("tokenizer", "treebuilder")
    ),
    )
    }

    #HtmlError

    The error type raised by parse, sanitize_dom, and to_html when something goes wrong end-to-end. Match on the variant to recover the specific failure mode.

    ///|
    pub(all) suberror HtmlError {
    StrictMode(ParseError) // strict=true and parser found a diagnostic
    InvalidSerialization(String) // tree could not be serialized
    UnsafeHtml(String) // sanitizer found content it refused
    SelectorError(String) // CSS selector failed to compile
    }

    HtmlError

    pub(all) suberror HtmlError {
    StrictMode(ParseError)
    InvalidSerialization(String)
    UnsafeHtml(String)
    SelectorError(String)
    } derive(Eq,
    Debug
    )

    Error type raised by strict parsing, serialization, sanitizer, and selector operations.

    HtmlError::equal

    #deprecated("implicit derived-impl promotion; call the trait method directly")
    fn HtmlError::equal(HtmlError, HtmlError) -> Bool

    HtmlError::not_equal

    #deprecated("implicit derived-impl promotion; call the trait method directly")
    fn HtmlError::not_equal(x : HtmlError, y : HtmlError) -> Bool

    HtmlError::to_repr

    #deprecated("implicit derived-impl promotion; call the trait method directly")
    fn HtmlError::to_repr(HtmlError) ->
    Repr

    ParseError

    pub(all) struct ParseError {
    code : String
    line : Int?
    column : Int?
    category : String
    message : String
    } derive(Eq,
    Debug
    )

    Parser or tokenizer diagnostic with optional source location.

    category identifies the source of the error, such as tokenizer or treebuilder. message defaults to code when no custom message is given.

    ParseError::ParseError

    fn ParseError::ParseError(code : String, line? : Int, column? : Int, category? : String, message? : String) -> ParseError

    Construct a parse diagnostic.

    ParseError::equal

    #deprecated("implicit derived-impl promotion; call the trait method directly")
    fn ParseError::equal(ParseError, ParseError) -> Bool

    ParseError::not_equal

    #deprecated("implicit derived-impl promotion; call the trait method directly")
    fn ParseError::not_equal(x : ParseError, y : ParseError) -> Bool

    ParseError::to_repr

    #deprecated("implicit derived-impl promotion; call the trait method directly")
    fn ParseError::to_repr(ParseError) ->
    Repr

    parser_error_category

    fn parser_error_category(code : StringView) -> String

    Classify a parse-error code by the subsystem that normally reports it.

    Known tokenizer error codes return "tokenizer". Other codes are treated as tree-builder/parser diagnostics and return "treebuilder".

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io