smithy.mbt
v0.6.0next
Docs / moonrockz/smithy-syntax
On this pageStatusExampleInstallationPackages

moonrockz/smithy-syntax

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

Status

  • Scanner: done.

  • AST: done.

  • CST: done.

  • Parser: done.

  • Diagnostics: done.

  • Traversal: done (traversal: NodeRef, walk, fold, reduce, accept, events, Tree, TreeCursor).

  • JSON AST: done (json_ast: typed records, decoder and encoder with exact numeric text round trips).

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
json_ast.../json_astJsonAst, shape records, parse, decode, encode, stringify
rootmoonrockz/smithy-syntaxparse_idl, parse_json_ast, decode_json_ast, encode_json_ast, public type re-exports

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 DESIGN.md, and the cookbook in docs/cookbook for task articles.

The JSON AST package depends on core JSON and the IDL AST's simple-type enum. Its package guide defines the codec's preservation and validation rules. The semantic loader and IDL-to-JSON conversion are available in moonrockz/smithy.

The facade also exports parse_tokens, codes and render_all_to. Use the scanner package for its pipeline records Piece and Step, and the parser package for Depth and ParseError. Property-test generators are internal.

ShapeKind::keyword() and its Show implementation return IDL keywords. NumberLiteral::as_double() returns signed infinity on overflow. The exact number stays in NumberLiteral::value. Partial trees may contain duplicate member names; check has_errors() before relying on member uniqueness.

Edit this page on GitHub