Sign in

    #ast

    The typed Smithy IDL tree. Every node has a span; every list is a read-only ArrayView; shape IDs are syntactic and unresolved.

    ///|
    test {
    let id = @ast.ShapeId::new("String", namespace="smithy.api")
    inspect(id, content="smithy.api#String")
    }

    AggregateType

    pub(all) enum AggregateType {
    List
    Map
    Union
    Structure
    Set
    } derive(Eq, Hash,
    Debug
    )

    Set is Smithy 1.0 syntax; it parses in every version and the loader decides what it means.

    AggregateType::keyword

    fn AggregateType::keyword(self : AggregateType) -> String

    The keyword that spells this aggregate type.

    ApplyStatement

    pub(all) struct ApplyStatement {
    target : Node[ShapeId]
    traits : ArrayView[Trait]
    block : Bool
    span :
    Span

    } derive(Eq,
    Debug
    )

    apply Target @trait or apply Target { @a @b }.

    ControlStatement

    pub(all) struct ControlStatement {
    key : Node[String]
    value : NodeValue
    span :
    Span

    } derive(Eq,
    Debug
    )

    $key: value.

    DocComment

    pub(all) struct DocComment {
    text : String
    span :
    Span

    } derive(Eq,
    Debug
    )

    One /// line, the slashes stripped, the line break not included.

    EntityType

    pub(all) enum EntityType {
    Service
    Resource
    } derive(Eq, Hash,
    Debug
    )

    service or resource.

    EnumMember

    pub(all) struct EnumMember {
    docs : ArrayView[DocComment]
    traits : ArrayView[Trait]
    name : Node[String]
    value : NodeValue?
    span :
    Span

    } derive(Eq,
    Debug
    )

    A member of an enum or intEnum.

    EnumType

    pub(all) enum EnumType {
    Enum
    IntEnum
    } derive(Eq, Hash,
    Debug
    )

    enum or intEnum.

    IdlFile

    One IDL file: control section, metadata section, then the shape section (namespace, use statements, shape and apply statements).

    IdlFile::control_value

    fn IdlFile::control_value(self : IdlFile, key : String) -> NodeValue?

    The value of the $key control statement, else None.

    IdlFile::shapes

    fn IdlFile::shapes(self : IdlFile) -> Array[ShapeStatement]

    The shape statements, without the apply statements.

    InlineShape

    pub(all) struct InlineShape {
    docs : ArrayView[DocComment]
    traits : ArrayView[Trait]
    for_resource : Node[ShapeId]?
    mixins : Mixins?
    members : ArrayView[Member]
    span :
    Span

    } derive(Eq,
    Debug
    )

    := { ... } with its own traits, for and mixins.

    Keyword

    pub(all) enum Keyword {
    True
    False
    Null
    } derive(Eq, Hash,
    Debug
    )

    The Smithy node keywords: true, false and null.

    Member

    pub(all) struct Member {
    docs : ArrayView[DocComment]
    traits : ArrayView[Trait]
    name : Node[String]
    target : MemberTarget
    default : NodeValue?
    span :
    Span

    } derive(Eq,
    Debug
    )

    A member of a structure, union, list or map.

    MemberTarget

    pub(all) enum MemberTarget {
    Explicit(Node[ShapeId])
    Elided
    } derive(Eq,
    Debug
    )

    name: Target or the elided $name.

    MetadataStatement

    pub(all) struct MetadataStatement {
    key : Node[String]
    value : NodeValue
    span :
    Span

    } derive(Eq,
    Debug
    )

    metadata key = value.

    Mixins

    with [A, B].

    NamespaceStatement

    pub(all) struct NamespaceStatement {
    namespace : Node[String]
    span :
    Span

    } derive(Eq,
    Debug
    )

    namespace a.b.c.

    Node

    pub(all) struct Node[T] {
    value : T
    span :
    Span

    } derive(Eq,
    Debug
    )

    A leaf value with its span.

    Node::new

    fn[T] Node::new(value : T, span :
    Span
    ) -> Node[T]

    Pairs a value with the span it was parsed from.

    NodeKvp

    pub(all) struct NodeKvp {
    key : Node[String]
    value : NodeValue
    span :
    Span

    } derive(Eq,
    Debug
    )

    NodeObjectKvp: a key (an identifier or a quoted string) and a value.

    NodeValue

    NodeValue. Strings hold their decoded value; ShapeId is a bare identifier or shape ID in value position (@foo(bar)).

    NodeValue::as_string

    fn NodeValue::as_string(self : NodeValue) -> String?

    The string value of a String or TextBlock, else None.

    NodeValue::get

    fn NodeValue::get(self : NodeValue, key : String) -> NodeValue?

    The value of key in an object, else None.

    NodeValue::span

    The span of the value, whatever its shape.

    NumberLiteral

    pub(all) struct NumberLiteral {
    text : String
    value : NumberValue
    } derive(Eq,
    Debug
    )

    A number literal: the lexeme as written and its exact value.

    NumberLiteral::as_double

    fn NumberLiteral::as_double(self : NumberLiteral) -> Double

    The value as a Double (lossy for large integers and long decimals).

    NumberLiteral::as_int64

    fn NumberLiteral::as_int64(self : NumberLiteral) -> Int64?

    The value as an Int64 when it is an integer that fits.

    NumberValue

    The exact value of a number literal.

    OperationProperty

    One property of an operation shape: input, output or errors.

    OperationTarget

    pub(all) enum OperationTarget {
    Reference(Node[ShapeId])
    Inline(InlineShape)
    } derive(Eq,
    Debug
    )

    The target of an operation's input or output: a reference to a shape, or an inline shape defined on the spot.

    Shape

    pub(all) enum Shape {
    Simple(kind~ : SimpleType, name~ : Node[String], mixins~ : Mixins?)
    Enum(kind~ : EnumType, name~ : Node[String], mixins~ : Mixins?, members~ : ArrayView[EnumMember])
    Aggregate(kind~ : AggregateType, name~ : Node[String], for_resource~ : Node[ShapeId]?, mixins~ : Mixins?, members~ : ArrayView[Member])
    Entity(kind~ : EntityType, name~ : Node[String], mixins~ : Mixins?, body~ : NodeValue)
    Operation(name~ : Node[String], mixins~ : Mixins?, properties~ : ArrayView[OperationProperty])
    } derive(Eq,
    Debug
    )

    Shape, one case per grammar production. name is the identifier after the keyword.

    Shape::kind

    fn Shape::kind(self : Shape) -> ShapeKind

    The shape's kind.

    Shape::name

    fn Shape::name(self : Shape) -> Node[String]

    The shape's name.

    ShapeId

    pub(all) struct ShapeId {
    namespace : String?
    name : String
    member : String?
    } derive(Eq, Hash,
    Debug
    )

    A syntactic, unresolved shape ID: namespace#name$member. A relative ID has no namespace; resolution against use statements and the prelude is the loader's job.
    impl Show for ShapeId

    ShapeId::is_absolute

    fn ShapeId::is_absolute(self : ShapeId) -> Bool

    Whether the ID carries a namespace.

    ShapeId::new

    fn ShapeId::new(name : String, namespace? : String, member? : String) -> ShapeId

    Builds a ShapeId from its parts.

    ShapeKind

    pub(all) enum ShapeKind {
    Simple(SimpleType)
    Enum(EnumType)
    Aggregate(AggregateType)
    Entity(EntityType)
    Operation
    } derive(Eq, Hash,
    Debug
    )

    Every shape keyword, for recovery and for ShapeKind in the CST.
    impl Show for ShapeKind

    ShapeKind::of

    fn ShapeKind::of(word : String) -> ShapeKind?

    The shape kind a keyword starts, or None.

    ShapeStatement

    pub(all) struct ShapeStatement {
    docs : ArrayView[DocComment]
    traits : ArrayView[Trait]
    shape : Shape
    span :
    Span

    } derive(Eq,
    Debug
    )

    Doc comments and traits, then the shape.

    SimpleType

    pub(all) enum SimpleType {
    Blob
    Boolean
    Document
    String
    Byte
    Short
    Integer
    Long
    Float
    Double
    BigInteger
    BigDecimal
    Timestamp
    } derive(Eq, Hash,
    Debug
    )

    A simple (unparameterized) shape type.

    SimpleType::keyword

    fn SimpleType::keyword(self : SimpleType) -> String

    The keyword that spells this simple type.

    SimpleType::of

    fn SimpleType::of(word : String) -> SimpleType?

    The simple type named by a keyword, or None.

    Statement

    pub(all) enum Statement {
    Shape(ShapeStatement)
    Apply(ApplyStatement)
    } derive(Eq,
    Debug
    )

    A shape or apply statement in the shape section.

    Statement::span

    The statement's span.

    Trait

    A single applied trait: @id with an optional body.

    TraitBody

    pub(all) enum TraitBody {
    Structure(ArrayView[NodeKvp])
    Node(NodeValue)
    } derive(Eq,
    Debug
    )

    @id, @id(value) or @id(key: value, ...). @id() is Structure([]).

    UseStatement

    pub(all) struct UseStatement {
    id : Node[ShapeId]
    span :
    Span

    } derive(Eq,
    Debug
    )

    use a.b#Name.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io