Sign in

    #parser

    parse_text parses Smithy IDL into a ParseResult: the AST (ast), the CST (cst, lossless), the declared version and the diagnostics. An error inside a statement is reported once and the parser resumes at the next statement.

    ///|
    test {
    let r = @parser.parse_text(
    "$version: \"2\"\nnamespace com.foo\n\nstring Name\n",
    )
    inspect(r.has_errors(), content="false")
    guard r.ast is Some(f) else { fail("no ast") }
    inspect(f.shapes()[0].shape.name().value, content="Name")
    }

    ParseError

    A syntax error, carrying its finished diagnostic. Raised inside a statement; parse catches it, records it and recovers.

    ParseError::diagnostic

    The diagnostic the error carries.

    Depth

    pub struct Depth(Int) derive(Compare, Eq,
    Debug
    )

    A nesting count of node values, member blocks and trait bodies.

    Depth::deeper

    fn Depth::deeper(self : Depth) -> Depth

    One level deeper.

    Depth::shallower

    fn Depth::shallower(self : Depth) -> Depth

    One level shallower; never goes below zero.

    Depth::zero

    fn Depth::zero() -> Depth

    The shallowest depth: not nested at all.

    ParseResult

    What parse returns. ast is the (possibly partial) tree whenever at least one statement parsed, and an empty IdlFile (with an empty span) for a file with no tokens (empty or only comments); it is None only when the file has tokens and every statement failed. cst has every token. version is the declared $version, None when absent.

    ParseResult::errors

    Only the diagnostics that are errors.

    ParseResult::has_errors

    fn ParseResult::has_errors(self : ParseResult) -> Bool

    Whether any diagnostic is an error (not just a warning).

    Version

    pub(all) enum Version {
    V1
    V2
    } derive(Eq, Hash,
    Debug
    )

    The IDL version a file declares with $version.

    Version::of

    fn Version::of(text : String) -> Version?

    1, 1.0, 2, 2.0, else None.

    max_nesting

    let max_nesting : Depth

    Deepest nesting the parser enters; deeper text is SM-PARSE-010, never a stack overflow.

    parse

    Parse Smithy IDL source text: a pipeline of the pure scanner and the parser.

    parse_text

    fn parse_text(text : String) -> ParseResult

    parse of a SourceText built from text.

    parse_tokens

    Parse a token stream into an IdlFile, with recovery per statement.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io