Sign in

    moonrockz/gleam-parser/ast does not have a README file

    Target

    Standard and validated extension target identities.

    BindingError

    pub(all) suberror BindingError {
    DuplicateBinding(
    Target
    )
    } derive(Eq,
    Debug
    )

    A repeated external binding. The existing collection is unchanged.

    DecodeError

    pub(all) suberror DecodeError {
    DecodeError(path~ : String, message~ : String)
    } derive(Eq,
    Debug
    )

    Raised on malformed input. path is a JSONPath-like location ($ is the value given to the public decoder).

    ExportError

    pub(all) suberror ExportError {
    NonStandardTarget(target~ :
    Target
    , location~ :
    SrcSpan
    )
    } derive(Eq,
    Debug
    )

    Compiler-compatible JSON cannot represent this extension target. The error identifies the target and its definition or annotation location. The AST is unchanged. Use the versioned extended interchange format instead.

    ExtendedError

    pub(all) suberror ExtendedError {
    UnregisteredTarget(
    Target
    )
    InvalidIdentity(String)
    } derive(Eq,
    Debug
    )

    Invalid extended-document metadata or an AST target absent from its registry. These errors never alter the AST or substitute a standard target.

    InvalidBitArrayUnit

    pub(all) suberror InvalidBitArrayUnit {
    InvalidBitArrayUnit(Int)
    } derive(Eq,
    Debug
    )

    A bit array unit falls outside the byte range 0..255.

    Arg

    pub(all) struct Arg {
    names : ArgNames
    location :
    SrcSpan

    annotation : TypeAst?
    } derive(Eq,
    Debug
    )

    ArgNames

    pub(all) enum ArgNames {
    Discard(name~ : String, location~ :
    SrcSpan
    )
    LabelledDiscard(label~ : String, label_location~ :
    SrcSpan
    , name~ : String, name_location~ :
    SrcSpan
    )
    Named(name~ : String, location~ :
    SrcSpan
    )
    NamedLabelled(label~ : String, label_location~ :
    SrcSpan
    , name~ : String, name_location~ :
    SrcSpan
    )
    } derive(Eq,
    Debug
    )

    Assert

    pub(all) struct Assert {
    location :
    SrcSpan

    value : Expr
    message : Expr?
    } derive(Eq,
    Debug
    )

    AssignName

    pub(all) enum AssignName {
    Variable(String)
    Discard(String)
    } derive(Eq,
    Debug
    )

    Assignment

    pub(all) struct Assignment {
    location :
    SrcSpan

    value : Expr
    pattern : Pattern
    kind : AssignmentKind
    annotation : TypeAst?
    } derive(Eq,
    Debug
    )

    AssignmentKind

    pub(all) enum AssignmentKind {
    Let
    Generated
    Assert(location~ :
    SrcSpan
    , assert_keyword_start~ :
    ByteOffset
    , message~ : Expr?)
    } derive(Eq,
    Debug
    )

    BinOp

    pub(all) enum BinOp {
    And
    Or
    Eq
    NotEq
    LtInt
    LtEqInt
    LtFloat
    LtEqFloat
    GtEqInt
    GtInt
    GtEqFloat
    GtFloat
    AddInt
    AddFloat
    SubInt
    SubFloat
    MultInt
    MultFloat
    DivInt
    DivFloat
    RemainderInt
    Concatenate
    } derive(Eq, Hash,
    Debug
    )

    BinOp::all

    fn BinOp::all() -> Array[BinOp]

    Every operator, in the compiler's order.

    BinOp::name

    fn BinOp::name(self : BinOp) -> String

    Return the binary operator's snake_case JSON name.

    BinOp::of

    fn BinOp::of(name : String) -> BinOp?

    Read a binary operator's JSON name. Return None for an unknown name.

    BitArraySegment

    pub(all) struct BitArraySegment[V] {
    location :
    SrcSpan

    value : V
    options : ArrayView[BitArrayOption[V]]
    } derive(Eq,
    Debug
    )

    BitArraySize

    pub(all) enum BitArraySize {
    Int(location~ :
    SrcSpan
    , value~ : String, int_value~ :
    BigInt
    )
    Variable(location~ :
    SrcSpan
    , name~ : String)
    BinaryOperator(location~ :
    SrcSpan
    , operator~ : IntOperator, left~ : BitArraySize, right~ : BitArraySize)
    Block(location~ :
    SrcSpan
    , inner~ : BitArraySize)
    }

    impl Eq for BitArraySize

    BitArraySize::location

    Return the byte span of a bit array size expression.

    BitArrayUnit

    pub struct BitArrayUnit {
    // private fields
    } derive(Compare, Eq, Hash,
    Debug
    )

    A bit array segment's unit, in the compiler's byte range 0..255.

    BitArrayUnit::BitArrayUnit

    fn BitArrayUnit::BitArrayUnit(value : Int) -> BitArrayUnit raise InvalidBitArrayUnit

    Create a bit array unit. Raise InvalidBitArrayUnit outside 0..255. Use from_int to get Option.

    test {
    assert_eq(@ast.BitArrayUnit(255).to_int(), 255)
    }

    BitArrayUnit::from_int

    #alias(new, deprecated="Use `BitArrayUnit::from_int(...)` instead")
    fn BitArrayUnit::from_int(value : Int) -> BitArrayUnit?

    Validate a bit array unit. Return None outside 0..255.

    test {
    debug_inspect(@ast.BitArrayUnit::from_int(256), content="None")
    assert_eq(@ast.BitArrayUnit::from_int(255).unwrap().to_int(), 255)
    }

    BitArrayUnit::to_int

    fn BitArrayUnit::to_int(self : BitArrayUnit) -> Int

    The unit value for serialization or formatting.

    CallArg

    pub(all) struct CallArg[A] {
    label : String?
    location :
    SrcSpan

    value : A
    implicit : ImplicitCallArgOrigin?
    } derive(Eq,
    Debug
    )

    Clause

    pub(all) struct Clause {
    location :
    SrcSpan

    pattern : ArrayView[Pattern]
    alternative_patterns : ArrayView[ArrayView[Pattern]]
    guard_ : ClauseGuard?
    then : Expr
    } derive(Eq,
    Debug
    )

    ClauseGuard

    pub(all) enum ClauseGuard {
    Block(location~ :
    SrcSpan
    , value~ : ClauseGuard)
    BinaryOperator(location~ :
    SrcSpan
    , operator~ : BinOp, operator_start~ :
    ByteOffset
    , left~ : ClauseGuard, right~ : ClauseGuard)
    Not(location~ :
    SrcSpan
    , expression~ : ClauseGuard)
    Var(location~ :
    SrcSpan
    , name~ : String)
    TupleIndex(location~ :
    SrcSpan
    , index~ : TupleIndex, tuple~ : ClauseGuard)
    FieldAccess(label_location~ :
    SrcSpan
    , index~ : TupleIndex?, label~ : String, container~ : ClauseGuard)
    Constant(Constant)
    }

    ClauseGuard without ModuleSelect and Invalid, which analysis builds, not the parser (module.name in a guard is FieldAccess).
    impl Eq for ClauseGuard

    ClauseGuard::location

    The span of a clause guard. A FieldAccess has no span field: it runs from the start of its container to the end of its label, as ClauseGuard::location does in the compiler.

    Constant

    pub(all) enum Constant {
    Int(location~ :
    SrcSpan
    , value~ : String, int_value~ :
    BigInt
    )
    Float(location~ :
    SrcSpan
    , value~ : String, float_value~ : Double)
    String(location~ :
    SrcSpan
    , value~ : String)
    Tuple(location~ :
    SrcSpan
    , elements~ : ArrayView[Constant])
    List(location~ :
    SrcSpan
    , elements~ : ArrayView[Constant], tail~ : Constant?)
    Record(location~ :
    SrcSpan
    , arguments_start_position~ :
    ByteOffset
    , module_~ : SpannedString?, name~ : String, arguments~ : ArrayView[CallArg[Constant]]?)
    RecordUpdate(location~ :
    SrcSpan
    , constructor_location~ :
    SrcSpan
    , module_~ : SpannedString?, name~ : String, record~ : RecordBeingUpdated[Constant], arguments~ : ArrayView[RecordUpdateArg[Constant]])
    BitArray(location~ :
    SrcSpan
    , segments~ : ArrayView[BitArraySegment[Constant]])
    Var(location~ :
    SrcSpan
    , module_~ : SpannedString?, name~ : String)
    BinaryOperator(location~ :
    SrcSpan
    , operator_start~ :
    ByteOffset
    , operator~ : BinOp, left~ : Constant, right~ : Constant)
    Todo(location~ :
    SrcSpan
    , message~ : Constant?)
    }

    Constant<()> without Invalid (analysis only).
    impl Eq for Constant
    impl Debug for Constant

    Constant::location

    Return the byte span of a constant.

    CustomType

    pub(all) struct CustomType {
    location :
    SrcSpan

    end_position :
    ByteOffset

    name : String
    name_location :
    SrcSpan

    publicity : Publicity
    constructors : ArrayView[RecordConstructor]
    documentation : Documentation?
    deprecation : Deprecation
    opaque_ : Bool
    parameters : ArrayView[SpannedString]
    externals : ExternalBindings
    } derive(Eq,
    Debug
    )

    CustomType::external_for

    Find this external type's binding for a target, including standard targets.

    Definition

    pub(all) enum Definition {
    Function(Function)
    TypeAlias(TypeAlias)
    CustomType(CustomType)
    Import(Import)
    ModuleConstant(ModuleConstant)
    } derive(Eq,
    Debug
    )

    Definition::external_bindings

    fn Definition::external_bindings(self : Definition) -> ExternalBindings

    Return a definition's external bindings. Definitions without an external annotation grammar return an empty collection.

    Definition::location

    The span of a definition: the compiler's location field, which for a function or custom type covers the head only (end_position ends the body).

    Deprecation

    pub(all) enum Deprecation {
    NotDeprecated
    Deprecated(message~ : String)
    } derive(Eq,
    Debug
    )

    type_::Deprecation.

    Documentation

    pub(all) struct Documentation {
    start :
    ByteOffset

    text : String
    } derive(Eq,
    Debug
    )

    (u32, EcoString): a doc comment's start byte and text.

    Expr

    pub(all) enum Expr {
    Int(location~ :
    SrcSpan
    , value~ : String, int_value~ :
    BigInt
    )
    Float(location~ :
    SrcSpan
    , value~ : String, float_value~ : Double)
    String(location~ :
    SrcSpan
    , value~ : String)
    Block(location~ :
    SrcSpan
    , statements~ : ArrayView[Statement])
    Var(location~ :
    SrcSpan
    , name~ : String)
    Fn(location~ :
    SrcSpan
    , kind~ : FunctionLiteralKind, end_of_head_byte_index~ :
    ByteOffset
    , arguments~ : ArrayView[Arg], body~ : ArrayView[Statement], return_annotation~ : TypeAst?)
    List(location~ :
    SrcSpan
    , elements~ : ArrayView[Expr], tail~ : Expr?)
    Call(location~ :
    SrcSpan
    , fun~ : Expr, arguments~ : ArrayView[CallArg[Expr]], open_parenthesis~ :
    ByteOffset
    )
    BinOp(location~ :
    SrcSpan
    , operator~ : BinOp, operator_start~ :
    ByteOffset
    , left~ : Expr, right~ : Expr)
    Pipeline(expressions~ : ArrayView[Expr])
    Case(location~ :
    SrcSpan
    , subjects~ : ArrayView[Expr], clauses~ : ArrayView[Clause]?)
    FieldAccess(location~ :
    SrcSpan
    , label_location~ :
    SrcSpan
    , label~ : String, container~ : Expr)
    Tuple(location~ :
    SrcSpan
    , elements~ : ArrayView[Expr])
    TupleIndex(location~ :
    SrcSpan
    , index~ : TupleIndex, tuple~ : Expr)
    Todo(kind~ : TodoKind, location~ :
    SrcSpan
    , message~ : Expr?)
    Panic(location~ :
    SrcSpan
    , message~ : Expr?)
    Echo(location~ :
    SrcSpan
    , keyword_end~ :
    ByteOffset
    , expression~ : Expr?, message~ : Expr?)
    BitArray(location~ :
    SrcSpan
    , segments~ : ArrayView[BitArraySegment[Expr]])
    RecordUpdate(location~ :
    SrcSpan
    , spread_start~ :
    ByteOffset
    , constructor_~ : Expr, record~ : RecordBeingUpdated[Expr], arguments~ : ArrayView[RecordUpdateArg[Expr]])
    NegateBool(location~ :
    SrcSpan
    , value~ : Expr)
    NegateInt(location~ :
    SrcSpan
    , value~ : Expr)
    }

    UntypedExpr.
    impl Eq for Expr
    impl Debug for Expr

    Expr::location

    The span of an expression. A Pipeline has no span of its own: it runs from the start of its first expression to the end of its last one, as UntypedExpr::location does in the compiler.

    Extended

    pub struct Extended {
    parsed : Parsed
    dialect : String
    profiles : ArrayView[String]
    targets :
    Registry

    } derive(Eq,
    Debug
    )

    A parsed AST and its declared dialect, profile identities, and target registry. This document contains data only. Decoding never imports profile code. Use Extended to validate the references before encoding.

    Extended::Extended

    fn Extended::Extended(parsed : Parsed, dialect~ : String, targets~ :
    Registry
    , profiles? : ArrayView[String]) -> Extended raise ExtendedError

    Create an extended document. Every AST target must occur in targets. dialect must be nonempty. Profile identities must be nonempty and unique; use module-qualified identities with a version for published profiles. The profile list is copied. Registration does not implement a backend.

    External

    pub(all) struct External {
    module_ : String
    function : String
    location :
    SrcSpan

    } derive(Eq,
    Debug
    )

    (EcoString, EcoString, SrcSpan): an @external(target, module,function) attribute.

    ExternalBinding

    pub(all) struct ExternalBinding {
    target :
    Target

    external : External
    } derive(Eq,
    Debug
    )

    One target-specific reference with its annotation's source location. The module and function strings are opaque. Consumers interpret them.

    ExternalBindings

    pub struct ExternalBindings {
    bindings : ArrayView[ExternalBinding]
    } derive(Eq,
    Debug
    )

    An immutable collection with at most one external binding per target. Use with_binding to add a binding and get to look one up.

    test {
    let target = @ast.Target::extension("orbit")
    let external : @ast.External = {
    module_: "space/list",
    function: "length",
    location: @span.SrcSpan::from_ints(0, 40).unwrap(),
    }
    let bindings = @ast.ExternalBindings::empty().with_binding(target, external)
    assert_eq(bindings.get(target), Some(external))
    assert_eq(bindings.get(Erlang), None)
    }

    ExternalBindings::all

    Return a copy of all bindings in canonical order, with standard targets first.

    ExternalBindings::empty

    No external bindings.

    ExternalBindings::from_standard

    fn ExternalBindings::from_standard(erlang : External?, javascript : External?) -> ExternalBindings

    Import the compiler's two optional external fields into a generic collection. Standard compatibility decoders use this boundary. New code can use empty().with_binding(target, external) for any registered target.

    ExternalBindings::get

    Find a binding by target identity. Return None when none is present.

    ExternalBindings::is_empty

    fn ExternalBindings::is_empty(self : ExternalBindings) -> Bool

    Whether the definition has no external binding for any target.

    ExternalBindings::with_binding

    Add a binding in a new collection. Raise DuplicateBinding when that target already has a binding. No registration or backend selection occurs.

    Function

    pub(all) struct Function {
    location :
    SrcSpan

    body_start :
    ByteOffset
    ?
    end_position :
    ByteOffset

    name : SpannedString?
    arguments : ArrayView[Arg]
    body : ArrayView[Statement]
    publicity : Publicity
    deprecation : Deprecation
    return_annotation : TypeAst?
    documentation : Documentation?
    externals : ExternalBindings
    } derive(Eq,
    Debug
    )

    Function::external_for

    Find this function's binding for a target, including standard targets. A binding does not imply a target restriction on the definition.

    FunctionLiteralKind

    ImplicitCallArgOrigin

    pub(all) enum ImplicitCallArgOrigin {
    Use
    Pipe
    PatternFieldSpread
    IncorrectArityUse
    RecordUpdate
    } derive(Eq, Hash,
    Debug
    )

    ImplicitCallArgOrigin::name

    fn ImplicitCallArgOrigin::name(self : ImplicitCallArgOrigin) -> String

    Return the implicit argument origin's snake_case JSON name.

    ImplicitCallArgOrigin::of

    Read an implicit argument origin's JSON name. Return None for an unknown name.

    Import

    pub(all) struct Import {
    documentation : String?
    location :
    SrcSpan

    module_location :
    SrcSpan

    module_ : String
    as_name : ImportAlias?
    unqualified_values : ArrayView[UnqualifiedImport]
    unqualified_types : ArrayView[UnqualifiedImport]
    } derive(Eq,
    Debug
    )

    ImportAlias

    pub(all) struct ImportAlias {
    name : AssignName
    location :
    SrcSpan

    } derive(Eq,
    Debug
    )

    (AssignName, SrcSpan).

    IntOperator

    pub(all) enum IntOperator {
    Add
    Subtract
    Multiply
    Divide
    Remainder
    } derive(Eq, Hash,
    Debug
    )

    IntOperator::name

    fn IntOperator::name(self : IntOperator) -> String

    Return the integer operator's snake_case JSON name.

    IntOperator::of

    fn IntOperator::of(name : String) -> IntOperator?

    Read an integer operator's JSON name. Return None for an unknown name.

    Module

    pub(all) struct Module {
    definitions : ArrayView[TargetedDefinition]
    } derive(Eq,
    Debug
    )

    Module<(), Vec<TargetedDefinition>> without name and documentation, which the parser leaves empty.

    ModuleConstant

    pub(all) struct ModuleConstant {
    documentation : Documentation?
    location :
    SrcSpan

    publicity : Publicity
    name : String
    name_location :
    SrcSpan

    annotation : TypeAst?
    value : Constant
    deprecation : Deprecation
    } derive(Eq,
    Debug
    )

    ModuleExtra

    parse::extra::ModuleExtra: byte positions of the trivia the formatter needs. Comment spans are the compiler's (after the slashes).

    ModuleExtra::empty

    fn ModuleExtra::empty() -> ModuleExtra

    Create trivia metadata with no comments, line ends or trailing commas.

    OracleOutput

    pub(all) enum OracleOutput {
    Parsed(Parsed)
    Error(kind~ : String, lexical_kind~ : String?, location~ :
    SrcSpan
    )
    } derive(Eq,
    Debug
    )

    What the oracle (tools/gleam-ast-oracle) writes for one file: the parse result, or the compiler's first parse error. kind is the ParseErrorType variant name; for LexError, lexical_kind is the LexicalErrorType name as @scanner.LexicalErrorType::kind() gives it.

    Parsed

    pub(all) struct Parsed {
    module_ : Module
    extra : ModuleExtra
    warnings : ArrayView[Warning]
    } derive(Eq,
    Debug
    )

    What the compiler's parse_module returns: the module, the trivia positions (ModuleExtra) and the parse-time warnings.

    Pattern

    pub(all) enum Pattern {
    Int(location~ :
    SrcSpan
    , value~ : String, int_value~ :
    BigInt
    )
    Float(location~ :
    SrcSpan
    , value~ : String, float_value~ : Double)
    String(location~ :
    SrcSpan
    , value~ : String)
    Variable(location~ :
    SrcSpan
    , name~ : String)
    BitArraySize(BitArraySize)
    Assign(name~ : String, location~ :
    SrcSpan
    , pattern~ : Pattern)
    Discard(name~ : String, location~ :
    SrcSpan
    )
    List(location~ :
    SrcSpan
    , elements~ : ArrayView[Pattern], tail~ : TailPattern?)
    Constructor(location~ :
    SrcSpan
    , name_location~ :
    SrcSpan
    , name~ : String, arguments~ : ArrayView[CallArg[Pattern]], module_~ : SpannedString?, spread~ :
    SrcSpan
    ?)
    Tuple(location~ :
    SrcSpan
    , elements~ : ArrayView[Pattern])
    BitArray(location~ :
    SrcSpan
    , segments~ : ArrayView[BitArraySegment[Pattern]])
    StringPrefix(location~ :
    SrcSpan
    , left_location~ :
    SrcSpan
    , left_side_assignment~ : StringPrefixLeftSideAssignment?, right_location~ :
    SrcSpan
    , left_side_string~ : String, right_side_assignment~ : AssignName)
    }

    Pattern without Invalid (analysis only).
    impl Eq for Pattern
    impl Debug for Pattern

    Pattern::location

    The span of a pattern. A BitArraySize pattern has its size's span; an Assign (pattern as name) runs from its inner pattern's start to the name's end (its location field is the name's span), as Pattern::location does in the compiler.

    Publicity

    pub(all) enum Publicity {
    Public
    Private
    Internal(attribute_location~ :
    SrcSpan
    ?)
    } derive(Eq,
    Debug
    )

    RecordBeingUpdated

    pub(all) struct RecordBeingUpdated[A] {
    base : A
    location :
    SrcSpan

    } derive(Eq,
    Debug
    )

    RecordConstructor

    pub(all) struct RecordConstructor {
    location :
    SrcSpan

    name_location :
    SrcSpan

    name : String
    arguments : ArrayView[RecordConstructorArg]
    documentation : Documentation?
    deprecation : Deprecation
    } derive(Eq,
    Debug
    )

    RecordConstructorArg

    pub(all) struct RecordConstructorArg {
    label : SpannedString?
    ast : TypeAst
    location :
    SrcSpan

    doc : Documentation?
    } derive(Eq,
    Debug
    )

    RecordUpdateArg

    pub(all) struct RecordUpdateArg[A] {
    label : String
    location :
    SrcSpan

    value : A
    } derive(Eq,
    Debug
    )

    SpannedString

    pub(all) struct SpannedString {
    location :
    SrcSpan

    name : String
    } derive(Eq,
    Debug
    )

    (SrcSpan, EcoString): a name with its span.

    Statement

    pub(all) enum Statement {
    Expression(Expr)
    Assignment(Assignment)
    Use(Use)
    Assert(Assert)
    } derive(Eq,
    Debug
    )

    Statement::location

    Return the byte span of a statement. An expression statement uses the expression's span.

    StringPrefixLeftSideAssignment

    pub(all) struct StringPrefixLeftSideAssignment {
    name : String
    name_start_position :
    ByteOffset

    location :
    SrcSpan

    } derive(Eq,
    Debug
    )

    TailPattern

    pub(all) struct TailPattern {
    location :
    SrcSpan

    pattern : Pattern
    } derive(Eq,
    Debug
    )

    TargetedDefinition

    pub(all) struct TargetedDefinition {
    definition : Definition
    target :
    Target
    ?
    } derive(Eq,
    Debug
    )

    TodoKind

    pub(all) enum TodoKind {
    Keyword
    EmptyFunction(function_location~ :
    SrcSpan
    )
    IncompleteUse
    EmptyBlock
    } derive(Eq,
    Debug
    )

    TupleIndex

    pub(all) struct TupleIndex(UInt64) derive(Compare, Eq, Hash,
    Debug
    )

    A tuple element index. The full unsigned 64-bit range matches Gleam.

    test {
    let index : @ast.TupleIndex = @ast.TupleIndex(18446744073709551615UL)
    assert_eq(index.to_uint64(), 18446744073709551615UL)
    }

    TupleIndex::from_int64

    #alias(new, deprecated="Use `TupleIndex::from_int64(...)` instead")
    fn TupleIndex::from_int64(value : Int64) -> TupleIndex?

    Validate a signed input. Return None for a negative index.

    TupleIndex::from_uint64

    #deprecated("Use `TupleIndex(value)` instead")
    fn TupleIndex::from_uint64(value : UInt64) -> TupleIndex

    Use TupleIndex(value) to import an unsigned index without loss.

    TupleIndex::to_uint64

    fn TupleIndex::to_uint64(self : TupleIndex) -> UInt64

    The exact index for serialization or formatting.

    TypeAlias

    pub(all) struct TypeAlias {
    location :
    SrcSpan

    alias_ : String
    name_location :
    SrcSpan

    parameters : ArrayView[SpannedString]
    type_ast : TypeAst
    publicity : Publicity
    documentation : Documentation?
    deprecation : Deprecation
    } derive(Eq,
    Debug
    )

    TypeAst

    pub(all) enum TypeAst {
    Constructor(TypeAstConstructor)
    Fn(TypeAstFn)
    Var(TypeAstVar)
    Tuple(TypeAstTuple)
    Hole(TypeAstHole)
    }

    impl Eq for TypeAst
    impl Debug for TypeAst

    TypeAst::location

    Return the byte span of a type annotation.

    TypeAstConstructor

    TypeAstConstructorName

    pub(all) enum TypeAstConstructorName {
    Qualified(module_~ : String, module_location~ :
    SrcSpan
    , dot_location~ :
    ByteOffset
    , name~ : SpannedString?)
    Unqualified(name~ : String, location~ :
    SrcSpan
    )
    } derive(Eq,
    Debug
    )

    TypeAstFn

    pub(all) struct TypeAstFn {
    location :
    SrcSpan

    arguments : ArrayView[TypeAst]
    return_ : TypeAst
    } derive(Eq,
    Debug
    )

    TypeAstHole

    pub(all) struct TypeAstHole {
    location :
    SrcSpan

    name : String
    } derive(Eq,
    Debug
    )

    TypeAstTuple

    pub(all) struct TypeAstTuple {
    location :
    SrcSpan

    elements : ArrayView[TypeAst]
    } derive(Eq,
    Debug
    )

    TypeAstVar

    pub(all) struct TypeAstVar {
    location :
    SrcSpan

    name : String
    } derive(Eq,
    Debug
    )

    UnqualifiedImport

    pub(all) struct UnqualifiedImport {
    location :
    SrcSpan

    name : String
    name_position :
    ByteOffset

    as_name : String?
    } derive(Eq,
    Debug
    )

    UseAssignment

    pub(all) struct UseAssignment {
    location :
    SrcSpan

    pattern : Pattern
    annotation : TypeAst?
    } derive(Eq,
    Debug
    )

    Warning

    pub(all) enum Warning {
    DeprecatedListPrepend(location~ :
    SrcSpan
    )
    DeprecatedListPattern(location~ :
    SrcSpan
    )
    DeprecatedListCatchAllPattern(location~ :
    SrcSpan
    )
    DeprecatedListSpreadAsVariablePattern(location~ :
    SrcSpan
    , name~ : String)
    DeprecatedRecordSpreadPattern(location~ :
    SrcSpan
    )
    DeprecatedEmptyClauseGuard(location~ :
    SrcSpan
    )
    DeprecatedTargetShorthand(target~ :
    Target
    , location~ :
    SrcSpan
    )
    DetachedDocComment(location~ :
    SrcSpan
    )
    } derive(Eq,
    Debug
    )

    The warnings parse_module emits: DeprecatedSyntaxWarning and DetachedDocComment.

    canonical

    fn canonical(json : Json) -> String

    The canonical text of an encoded value: keys in sorted (byte) order at every level, no whitespace, serde_json's string escaping (\", \\, \b, \f, \n, \r, \t, other controls as \u00xx, everything else raw). Map order is not relied on. Writes through the step trampoline, so a value of any depth is written without recursion; the builder is local to this call.

    decode_clause_guard

    fn decode_clause_guard(json : Json) -> ClauseGuard raise DecodeError

    Decode a clause guard from its tagged JSON object. Tuple and field indexes must fit an unsigned 64-bit integer. Raise DecodeError with the field path for malformed input.

    decode_constant

    fn decode_constant(json : Json) -> Constant raise DecodeError

    Decode a constant from its tagged JSON object. Raise DecodeError with the field path for malformed input.

    decode_definition

    fn decode_definition(json : Json) -> Definition raise DecodeError

    Decode one definition from its tagged JSON object. Raise DecodeError with the field path for malformed input.

    decode_expr

    fn decode_expr(json : Json) -> Expr raise DecodeError

    Decode an expression from its tagged JSON object. Derive a float value from a complete Gleam float lexeme. Raise DecodeError with the field path for malformed input.

    test {
    let value : @ast.Expr = Var(
    location=@span.SrcSpan::from_ints(0, 1).unwrap(),
    name="x",
    )
    assert_eq(@ast.decode_expr(@ast.encode_expr(value)), value)
    }

    decode_extended

    fn decode_extended(json : Json) -> Extended raise DecodeError

    Decode version 1 of the extended JSON format without loading profile code. Validate the embedded registry, rejecting invalid names, aliases, duplicates, missing standard identities, unknown references, and duplicate bindings. Raise DecodeError with the JSON path for malformed or unsupported input. Profile identities are descriptive data; an application must supply matching profile code explicitly if it wants to parse or format new source.

    decode_extra

    fn decode_extra(json : Json) -> ModuleExtra raise DecodeError

    Decode comment spans, line offsets and trailing comma offsets. Offsets must be non-negative integers that fit Int32. Raise DecodeError with the field path for malformed input.

    decode_module

    fn decode_module(json : Json) -> Module raise DecodeError

    Decode a module from its JSON object. Raise DecodeError with the field path for malformed input.

    decode_oracle_output

    fn decode_oracle_output(json : Json) -> OracleOutput raise DecodeError

    Decode the oracle's parsed module or first-error object. An error field selects the error form. Otherwise, decode a parsed module. Raise DecodeError with the field path for malformed input.

    decode_parsed

    fn decode_parsed(json : Json) -> Parsed raise DecodeError

    Decode a module with its trivia positions and parse-time warnings. Raise DecodeError at the invalid field when JSON does not fit the schema. The decoder uses no recursive calls and has no depth limit.

    test {
    let p = @ast.Parsed::{
    module_: { definitions: [][:], },
    extra: @ast.ModuleExtra::empty(),
    warnings: [][:],
    }
    assert_eq(@ast.decode_parsed(@ast.encode_parsed(p)), p)
    }

    decode_pattern

    fn decode_pattern(json : Json) -> Pattern raise DecodeError

    Decode a pattern from its tagged JSON object. Raise DecodeError with the field path for malformed input.

    decode_statement

    fn decode_statement(json : Json) -> Statement raise DecodeError

    Decode a statement from its tagged JSON object. Raise DecodeError with the field path for malformed input.

    decode_type_ast

    fn decode_type_ast(json : Json) -> TypeAst raise DecodeError

    Decode a type annotation from its tagged JSON object. A qualified name can be null when the source ends at the module dot. Raise DecodeError with the field path for malformed input.

    decode_warning

    fn decode_warning(json : Json) -> Warning raise DecodeError

    Decode a parse-time warning from its tagged JSON object. Raise DecodeError with the field path for malformed input.

    encode_clause_guard

    fn encode_clause_guard(g : ClauseGuard) -> Json

    Encode a clause guard as a tagged JSON object. Tuple and field indexes keep all unsigned 64-bit digits.

    encode_constant

    fn encode_constant(c : Constant) -> Json

    Encode a constant as a tagged JSON object.

    encode_definition

    fn encode_definition(d : Definition) -> Json raise ExportError

    Encode a definition as a tagged JSON object. Raise ExportError if it contains an extension external binding.

    encode_expr

    fn encode_expr(e : Expr) -> Json

    Encode an expression as a tagged JSON object. Write only a float's lexeme; the decoder derives its numeric value.

    test {
    let value : @ast.Expr = Var(
    location=@span.SrcSpan::from_ints(0, 1).unwrap(),
    name="x",
    )
    assert_eq(@ast.decode_expr(@ast.encode_expr(value)), value)
    }

    encode_extended

    fn encode_extended(document : Extended) -> Json raise ExtendedError

    Encode version 1 of the extended JSON format. Use canonical for deterministic bytes. Unlike compiler-compatible export, this preserves every registered target and generic external binding. Revalidate references on each call in case the caller changed an AST array after construction.

    test {
    let parsed : @ast.Parsed = {
    module_: { definitions: [][:], },
    extra: @ast.ModuleExtra::empty(),
    warnings: [][:],
    }
    let document = @ast.Extended(
    parsed,
    dialect="gleam-1.19",
    targets=@target.Registry::standard(),
    )
    assert_eq(@ast.decode_extended(@ast.encode_extended(document)), document)
    }

    encode_extra

    fn encode_extra(x : ModuleExtra) -> Json

    Encode comment spans, line offsets and trailing comma offsets.

    encode_module

    fn encode_module(m : Module) -> Json raise ExportError

    Encode a module as a JSON object with its definitions in source order. Raise ExportError for an extension restriction or external binding.

    encode_oracle_output

    fn encode_oracle_output(o : OracleOutput) -> Json raise ExportError

    Encode a parsed module or the compiler's first error. Raise ExportError if the parsed module contains an extension target. Use canonical to write the JSON text, then add a line feed for oracle output.

    test {
    let value : @ast.OracleOutput = Error(
    kind="UnexpectedEof",
    lexical_kind=None,
    location=@span.SrcSpan::from_ints(0, 0).unwrap(),
    )
    assert_eq(@ast.decode_oracle_output(@ast.encode_oracle_output(value)), value)
    }

    encode_parsed

    fn encode_parsed(p : Parsed) -> Json raise ExportError

    Encode a module with its trivia positions and parse-time warnings. Use canonical to write the JSON in the oracle's key order. Encoding uses no recursive calls and has no depth limit. Raise ExportError::NonStandardTarget if any target restriction, binding, or warning contains an extension. Use encode_extended to preserve it.

    test {
    let p = @ast.Parsed::{
    module_: { definitions: [][:], },
    extra: @ast.ModuleExtra::empty(),
    warnings: [][:],
    }
    assert_eq(@ast.decode_parsed(@ast.encode_parsed(p)), p)
    }

    encode_pattern

    fn encode_pattern(p : Pattern) -> Json

    Encode a pattern as a tagged JSON object.

    encode_publicity

    fn encode_publicity(p : Publicity) -> Json

    Encode public, private or internal visibility as a tagged JSON object.

    encode_span

    Encode a source span as start and end byte offsets. The offsets are written as given, including the compiler's start..0 EOF spans.

    encode_statement

    fn encode_statement(s : Statement) -> Json

    Encode a statement as a tagged JSON object.

    encode_targeted_definition

    fn encode_targeted_definition(d : TargetedDefinition) -> Json raise ExportError

    Encode a definition with its optional target. An absent target is written as null. Raise ExportError for an extension restriction or external binding.

    encode_type_ast

    fn encode_type_ast(t : TypeAst) -> Json

    Encode a type annotation as a tagged JSON object.

    encode_warning

    fn encode_warning(w : Warning) -> Json raise ExportError

    Encode a parse-time warning as a tagged JSON object. Raise ExportError if a constructed shorthand warning contains an extension target.