Sign in

    smithy-syntax

    Smithy IDL syntax for MoonBit: lossless scanner, typed AST, CST, parser and diagnostics

    smithy
    idl
    parser
    ast
    moonbit
    Download zip
    Author
    Version
    0.0.1
    License
    Apache-2.0
    Last updated
    2 hours ago
    Downloads
    2

    Dependencies

    #moonrockz/smithy-syntax

    Smithy IDL syntax for MoonBit: a lossless scanner, a typed AST with spans, a CST that prints the source back byte for byte, a parser with recovery per statement, and diagnostics in the style of Elm and Rust.

    #Status

    • Scanner: done.
    • AST: done.
    • CST: done.
    • Parser: done.
    • Diagnostics: done.
    • Traversal: done (traversal: NodeRef, walk, fold, reduce, accept, events, Tree, TreeCursor).
    • JSON AST: planned, in a later sub-project.

    #Example

    test {
    let r = @syntax.parse_idl(
    (
    #|$version: "2"
    #|namespace com.foo
    #|
    #|string Name
    #|
    ),
    name="a.smithy",
    )
    inspect(r.has_errors(), content="false")
    }

    #Installation

    moon add moonrockz/smithy-syntax

    #Packages

    PackageImport pathHolds
    spanmoonrockz/smithy-syntax/spanSpan, Position, SourceText
    diagnostic.../diagnosticSeverity, Label, Diagnostic, codes()
    scanner.../scannerTokenKind, Token, Trivia, Comment, TokenStream, tokenize, unescape, text_block_value
    ast.../astthe typed IDL tree
    cst.../cstIdlCst, StatementCst, StatementKind
    parser.../parserparse, parse_tokens, ParseResult, Version, max_nesting
    traversal.../traversalNodeRef, walk, fold, reduce, reduce_pruned, accept, EventReader, push_events, Tree, TreeCursor, NodePath, kind_table
    report.../reportrender_terminal, render_plain, render_short
    rootmoonrockz/smithy-syntaxparse_idl, re-exports of every public type

    Dependencies point one way: span ← diagnostic ← scanner ← ast ← cst ← parser ← traversal and report ← root (traversal and report do not import each other). Each package has a README.mbt.md with checked examples. See the design in docs/superpowers/specs/2026-10-15-idl-syntax-design.md, and the cookbook in docs/cookbook for task articles.

    AggregateType

    The AST.

    ApplyStatement

    The AST.

    Column

    Spans (UTF-16 unit offsets), positions and source text.

    Comment

    The scanner: tokens, trivia and lexical errors.

    CommentKind

    The scanner: tokens, trivia and lexical errors.

    Control

    The traversal: the node model, the cursor, the tree and the event types.

    ControlStatement

    The AST.

    Depth

    The parser's result, version, recursion depth and error.

    Diagnostic

    Diagnostics: severity, labels and the problem record.

    DocComment

    The AST.

    EnterEvent

    The traversal: the node model, the cursor, the tree and the event types.

    EntityType

    The AST.

    EnumMember

    The AST.

    EnumType

    The AST.

    Event

    The traversal: the node model, the cursor, the tree and the event types.

    EventReader

    The traversal: the node model, the cursor, the tree and the event types.

    EventSource

    The traversal: the node model, the cursor, the tree and the event types.

    Handler

    The traversal: the node model, the cursor, the tree and the event types.

    IdlCst

    The CST: every token grouped per statement.

    IdlFile

    The AST.

    InlineShape

    The AST.

    Keyword

    The AST.

    Label

    Diagnostics: severity, labels and the problem record.

    LeaveEvent

    The traversal: the node model, the cursor, the tree and the event types.

    Length

    Spans (UTF-16 unit offsets), positions and source text.

    Line

    Spans (UTF-16 unit offsets), positions and source text.

    Member

    The AST.

    MemberTarget

    The AST.

    MetadataStatement

    The AST.

    Mixins

    The AST.

    NamespaceStatement

    The AST.

    Node

    The AST.

    NodeKvp

    The AST.

    NodePath

    The traversal: the node model, the cursor, the tree and the event types.

    NodeRef

    The traversal: the node model, the cursor, the tree and the event types.

    NodeValue

    The AST.

    NumberLiteral

    The AST.

    NumberValue

    The AST.

    Offset

    Spans (UTF-16 unit offsets), positions and source text.

    OperationProperty

    The AST.

    OperationTarget

    The AST.

    ParseError

    The parser's result, version, recursion depth and error.

    ParseResult

    The parser's result, version, recursion depth and error.

    PathStep

    The traversal: the node model, the cursor, the tree and the event types.

    Piece

    The scanner: tokens, trivia and lexical errors.

    Position

    Spans (UTF-16 unit offsets), positions and source text.

    Severity

    Diagnostics: severity, labels and the problem record.

    Shape

    The AST.

    ShapeId

    The AST.

    ShapeKind

    The AST.

    ShapeStatement

    The AST.

    SimpleType

    The AST.

    SourceText

    Spans (UTF-16 unit offsets), positions and source text.

    Span

    Spans (UTF-16 unit offsets), positions and source text.

    Statement

    The AST.

    StatementCst

    The CST: every token grouped per statement.

    StatementKind

    The CST: every token grouped per statement.

    Step

    The scanner: tokens, trivia and lexical errors.

    Token

    The scanner: tokens, trivia and lexical errors.

    TokenKind

    The scanner: tokens, trivia and lexical errors.

    TokenStream

    The scanner: tokens, trivia and lexical errors.

    Trait

    The AST.

    TraitBody

    The AST.

    Tree

    The traversal: the node model, the cursor, the tree and the event types.

    TreeCursor

    The traversal: the node model, the cursor, the tree and the event types.

    Trivia

    The scanner: tokens, trivia and lexical errors.

    UseStatement

    The AST.

    Version

    The parser's result, version, recursion depth and error.

    Visitor

    The traversal: the node model, the cursor, the tree and the event types.

    accept

    Call one Visitor method per node; see @traversal.accept.

    diagnostic_description

    fn diagnostic_description(code : String) -> String?

    The one-line description of a diagnostic code, or None.

    fold

    Thread an accumulator through a walk; see @traversal.fold.

    kind_table

    fn kind_table() -> Array[(String, String, Array[String])]

    Every node type: (category, kind, fields); see @traversal.kind_table.

    parse

    Parse a source text with recovery per statement.

    parse_idl

    fn parse_idl(text : String, name? : String) ->
    ParseResult

    Parse Smithy IDL text. name is shown in rendered diagnostics.

    test {
    let r = @syntax.parse_idl(
    (
    #|$version: "2"
    #|namespace com.foo
    #|
    #|string Name
    #|
    ),
    name="a.smithy",
    )
    inspect(r.has_errors(), content="false")
    }

    push_events

    Drive an event source into a handler; see @traversal.push_events.

    reduce

    Reduce root bottom up; see @traversal.reduce.

    reduce_pruned

    Reduce bottom up, steered by enter; see @traversal.reduce_pruned.

    render_all

    Render every diagnostic in order, ending with an error/warning count.

    render_plain

    Render one diagnostic without colour, as the Elm/Rust-style layout.

    render_short

    Render one diagnostic as a single line, for editors (path:line:col:severity[code]: message).

    render_terminal

    Render one diagnostic for a terminal, with ANSI colour by default.

    render_terminal_to

    Render into any core Logger, for callers with their own sink.

    tokenize

    Scan source into tokens with trivia. Lossless: to_source() is the text.

    version

    fn version() -> String

    The version of smithy-syntax, the same as version in moon.mod.

    walk

    Visit root and every node below it in pre-order; see @traversal.walk.

    Source Files