Sign in

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

    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).

    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~ : Int, 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

    BinOp::of

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

    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)
    } derive(Eq,
    Debug
    )

    BitArraySize::location

    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~ : Int, left~ : ClauseGuard, right~ : ClauseGuard)
    Not(location~ :
    SrcSpan
    , expression~ : ClauseGuard)
    Var(location~ :
    SrcSpan
    , name~ : String)
    TupleIndex(location~ :
    SrcSpan
    , index~ : UInt64, tuple~ : ClauseGuard)
    FieldAccess(label_location~ :
    SrcSpan
    , index~ : UInt64?, label~ : String, container~ : ClauseGuard)
    Constant(Constant)
    } derive(Eq,
    Debug
    )

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

    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~ : Int, 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~ : Int, operator~ : BinOp, left~ : Constant, right~ : Constant)
    Todo(location~ :
    SrcSpan
    , message~ : Constant?)
    } derive(Eq,
    Debug
    )

    Constant<()> without Invalid (analysis only).

    Constant::location

    CustomType

    pub(all) struct CustomType {
    location :
    SrcSpan

    end_position : Int
    name : String
    name_location :
    SrcSpan

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

    Definition

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

    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 : Int
    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~ : Int, 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~ : Int)
    BinOp(location~ :
    SrcSpan
    , operator~ : BinOp, operator_start~ : Int, 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~ : UInt64, tuple~ : Expr)
    Todo(kind~ : TodoKind, location~ :
    SrcSpan
    , message~ : Expr?)
    Panic(location~ :
    SrcSpan
    , message~ : Expr?)
    Echo(location~ :
    SrcSpan
    , keyword_end~ : Int, expression~ : Expr?, message~ : Expr?)
    BitArray(location~ :
    SrcSpan
    , segments~ : ArrayView[BitArraySegment[Expr]])
    RecordUpdate(location~ :
    SrcSpan
    , spread_start~ : Int, constructor_~ : Expr, record~ : RecordBeingUpdated[Expr], arguments~ : ArrayView[RecordUpdateArg[Expr]])
    NegateBool(location~ :
    SrcSpan
    , value~ : Expr)
    NegateInt(location~ :
    SrcSpan
    , value~ : Expr)
    } derive(Eq,
    Debug
    )

    UntypedExpr.

    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.

    External

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

    } derive(Eq,
    Debug
    )

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

    Function

    pub(all) struct Function {
    location :
    SrcSpan

    body_start : Int?
    end_position : Int
    name : SpannedString?
    arguments : ArrayView[Arg]
    body : ArrayView[Statement]
    publicity : Publicity
    deprecation : Deprecation
    return_annotation : TypeAst?
    documentation : Documentation?
    external_erlang : External?
    external_javascript : External?
    } derive(Eq,
    Debug
    )

    FunctionLiteralKind

    ImplicitCallArgOrigin

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

    ImplicitCallArgOrigin::name

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

    ImplicitCallArgOrigin::of

    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

    IntOperator::of

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

    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

    pub(all) struct ModuleExtra {
    module_comments : ArrayView[
    SrcSpan
    ]
    doc_comments : ArrayView[
    SrcSpan
    ]
    comments : ArrayView[
    SrcSpan
    ]
    empty_lines : ArrayView[Int]
    new_lines : ArrayView[Int]
    trailing_commas : ArrayView[Int]
    } derive(Eq,
    Debug
    )

    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

    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)
    } derive(Eq,
    Debug
    )

    Pattern without Invalid (analysis only).

    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

    StringPrefixLeftSideAssignment

    pub(all) struct StringPrefixLeftSideAssignment {
    name : String
    name_start_position : Int
    location :
    SrcSpan

    } derive(Eq,
    Debug
    )

    TailPattern

    pub(all) struct TailPattern {
    location :
    SrcSpan

    pattern : Pattern
    } derive(Eq,
    Debug
    )

    Target

    pub(all) enum Target {
    Erlang
    JavaScript
    } derive(Eq, Hash,
    Debug
    )

    build::Target.

    Target::name

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

    Target::of

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

    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
    )

    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)
    } derive(Eq,
    Debug
    )

    TypeAst::location

    TypeAstConstructor

    pub(all) struct TypeAstConstructor {
    location :
    SrcSpan

    name : TypeAstConstructorName
    arguments : ArrayView[TypeAst]
    start_parentheses : Int?
    } derive(Eq,
    Debug
    )

    TypeAstConstructorName

    pub(all) enum TypeAstConstructorName {
    Qualified(module_~ : String, module_location~ :
    SrcSpan
    , dot_location~ : Int, 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 : Int
    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.

    decode_clause_guard

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

    decode_constant

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

    decode_definition

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

    decode_expr

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

    decode_extra

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

    decode_module

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

    decode_oracle_output

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

    decode_parsed

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

    decode_pattern

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

    decode_statement

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

    decode_type_ast

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

    decode_warning

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

    encode_clause_guard

    fn encode_clause_guard(g : ClauseGuard) -> Json

    encode_constant

    fn encode_constant(c : Constant) -> Json

    encode_definition

    fn encode_definition(d : Definition) -> Json

    encode_expr

    fn encode_expr(e : Expr) -> Json

    encode_extra

    fn encode_extra(x : ModuleExtra) -> Json

    encode_module

    fn encode_module(m : Module) -> Json

    encode_oracle_output

    fn encode_oracle_output(o : OracleOutput) -> Json

    encode_parsed

    fn encode_parsed(p : Parsed) -> Json

    encode_pattern

    fn encode_pattern(p : Pattern) -> Json

    encode_publicity

    fn encode_publicity(p : Publicity) -> Json

    encode_span

    encode_statement

    fn encode_statement(s : Statement) -> Json

    encode_targeted_definition

    fn encode_targeted_definition(d : TargetedDefinition) -> Json

    encode_type_ast

    fn encode_type_ast(t : TypeAst) -> Json

    encode_warning

    fn encode_warning(w : Warning) -> Json

    max_depth

    let max_depth : Int

    The deepest JSON nesting the decoder reads: deeper input raises a DecodeError instead of overflowing the stack (wasm has a small one). Each AST level is at least one JSON level, so this bounds the AST depth a decoded module can have; the parser keeps generated ASTs within it.