moonrockz/krueger/ast does not have a README file

    Cases

    type Cases = ArrayView[Case]

    Elm.Syntax.Expression.Cases

    Comment

    type Comment = String

    Elm.Syntax.Comments.Comment

    Documentation

    type Documentation = String

    Elm.Syntax.Documentation.Documentation

    ModuleName

    type ModuleName = ArrayView[String]

    Elm.Syntax.ModuleName.ModuleName

    RecordDefinition

    type RecordDefinition = ArrayView[Node[RecordField]]

    Elm.Syntax.TypeAnnotation.RecordDefinition

    DecodeError

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

    Error raised on malformed input. path is a JSONPath-like location ($ is the value given to the public decoder).
    impl Show for DecodeError

    Case

    pub(all) struct Case {
    pattern : Node[Pattern]
    expression : Node[Expression]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Expression.Case (an Elm tuple ( Node Pattern, Node Expression ))

    CaseBlock

    pub(all) struct CaseBlock {
    expression : Node[Expression]
    cases : ArrayView[Case]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Expression.CaseBlock

    Declaration

    pub(all) enum Declaration {
    FunctionDeclaration(Function)
    AliasDeclaration(TypeAlias)
    CustomTypeDeclaration(Type)
    PortDeclaration(Signature)
    InfixDeclaration(Infix)
    Destructuring(Node[Pattern], Node[Expression])
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Declaration.Declaration

    DefaultModuleData

    pub(all) struct DefaultModuleData {
    module_name : Node[ArrayView[String]]
    exposing_list : Node[Exposing]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Module.DefaultModuleData

    EffectModuleData

    pub(all) struct EffectModuleData {
    module_name : Node[ArrayView[String]]
    exposing_list : Node[Exposing]
    command : Node[String]?
    subscription : Node[String]?
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Module.EffectModuleData

    ExposedType

    pub(all) struct ExposedType {
    name : String
    open : Range?
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Exposing.ExposedType

    Exposing

    pub(all) enum Exposing {
    All(Range)
    Explicit(ArrayView[Node[TopLevelExpose]])
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Exposing.Exposing

    Expression

    pub(all) enum Expression {
    UnitExpr
    Application(ArrayView[Node[Expression]])
    OperatorApplication(String, InfixDirection, Node[Expression], Node[Expression])
    FunctionOrValue(ArrayView[String], String)
    IfBlock(Node[Expression], Node[Expression], Node[Expression])
    PrefixOperator(String)
    Operator(String)
    Integer(Int64)
    Hex(Int64)
    Floatable(Double)
    Negation(Node[Expression])
    Literal(String)
    CharLiteral(Char)
    TupledExpression(ArrayView[Node[Expression]])
    ParenthesizedExpression(Node[Expression])
    LetExpression(LetBlock)
    CaseExpression(CaseBlock)
    LambdaExpression(Lambda)
    RecordExpr(ArrayView[Node[RecordSetter]])
    ListExpr(ArrayView[Node[Expression]])
    RecordAccess(Node[Expression], Node[String])
    RecordAccessFunction(String)
    RecordUpdateExpression(Node[String], ArrayView[Node[RecordSetter]])
    GLSLExpression(String)
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Expression.Expression

    File

    pub(all) struct File {
    module_definition : Node[Module]
    imports : ArrayView[Node[Import]]
    declarations : ArrayView[Node[Declaration]]
    comments : ArrayView[Node[String]]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.File.File

    Function

    pub(all) struct Function {
    documentation : Node[String]?
    signature : Node[Signature]?
    declaration : Node[FunctionImplementation]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Expression.Function

    FunctionImplementation

    pub(all) struct FunctionImplementation {
    name : Node[String]
    arguments : ArrayView[Node[Pattern]]
    expression : Node[Expression]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Expression.FunctionImplementation

    Import

    pub(all) struct Import {
    module_name : Node[ArrayView[String]]
    module_alias : Node[ArrayView[String]]?
    exposing_list : Node[Exposing]?
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Import.Import

    Infix

    pub(all) struct Infix {
    direction : Node[InfixDirection]
    precedence : Node[Int]
    operator : Node[String]
    function : Node[String]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Infix.Infix

    InfixDirection

    pub(all) enum InfixDirection {
    Left
    Right
    Non
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Infix.InfixDirection

    Lambda

    pub(all) struct Lambda {
    args : ArrayView[Node[Pattern]]
    expression : Node[Expression]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Expression.Lambda

    LetBlock

    pub(all) struct LetBlock {
    declarations : ArrayView[Node[LetDeclaration]]
    expression : Node[Expression]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Expression.LetBlock

    LetDeclaration

    pub(all) enum LetDeclaration {
    LetFunction(Function)
    LetDestructuring(Node[Pattern], Node[Expression])
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Expression.LetDeclaration

    Location

    pub(all) struct Location {
    row : Int
    column : Int
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Range.Location: a point in the source. row is the line and column the column, both counted from 1. Columns count code points, so a character outside the BMP (a surrogate pair) is one column.

    Module

    pub(all) enum Module {
    NormalModule(DefaultModuleData)
    PortModule(DefaultModuleData)
    EffectModule(EffectModuleData)
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Module.Module

    Node

    pub(all) struct Node[T] {
    range : Range
    value : T
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Node.Node: a value with its source range. Most parts of the AST are nodes: names, expressions, patterns, type annotations and declarations.

    Pattern

    pub(all) enum Pattern {
    AllPattern
    UnitPattern
    CharPattern(Char)
    StringPattern(String)
    IntPattern(Int64)
    HexPattern(Int64)
    FloatPattern(Double)
    TuplePattern(ArrayView[Node[Pattern]])
    RecordPattern(ArrayView[Node[String]])
    UnConsPattern(Node[Pattern], Node[Pattern])
    ListPattern(ArrayView[Node[Pattern]])
    VarPattern(String)
    NamedPattern(QualifiedNameRef, ArrayView[Node[Pattern]])
    AsPattern(Node[Pattern], Node[String])
    ParenthesizedPattern(Node[Pattern])
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Pattern.Pattern

    QualifiedNameRef

    pub(all) struct QualifiedNameRef {
    module_name : ArrayView[String]
    name : String
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Pattern.QualifiedNameRef

    Range

    pub(all) struct Range {
    start : Location
    end : Location
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Range.Range: the source from start up to end. end is the location just after the last character, so x in column 1 has the range 1:1 to 1:2. elm-syntax writes it as [startRow, startColumn,endRow, endColumn].

    test {
    let source = @scanner.SourceText::new(
    "module Main exposing (..)\n\nname = \"\u{1F600}\" ++ x\n",
    )
    let result = @parser.parse_module(source, @scanner.DefaultScanner::new())
    guard result.ast is Some(file) else { fail("no AST") }
    let decl = file.declarations[0]
    debug_inspect(
    decl.range,
    content="{ start: { row: 3, column: 1 }, end: { row: 3, column: 16 } }",
    )
    inspect(@ast.encode_range(decl.range).stringify(), content="[3,1,3,16]")
    }

    RecordField

    pub(all) struct RecordField {
    name : Node[String]
    type_annotation : Node[TypeAnnotation]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.TypeAnnotation.RecordField (an Elm tuple ( Node String, Node TypeAnnotation ))

    RecordSetter

    pub(all) struct RecordSetter {
    field : Node[String]
    expression : Node[Expression]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Expression.RecordSetter (an Elm tuple ( Node String, Node Expression ))

    Signature

    pub(all) struct Signature {
    name : Node[String]
    type_annotation : Node[TypeAnnotation]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Signature.Signature

    TopLevelExpose

    pub(all) enum TopLevelExpose {
    InfixExpose(String)
    FunctionExpose(String)
    TypeOrAliasExpose(String)
    TypeExpose(ExposedType)
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Exposing.TopLevelExpose

    Type

    pub(all) struct Type {
    documentation : Node[String]?
    name : Node[String]
    generics : ArrayView[Node[String]]
    constructors : ArrayView[Node[ValueConstructor]]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Type.Type

    TypeAlias

    pub(all) struct TypeAlias {
    documentation : Node[String]?
    name : Node[String]
    generics : ArrayView[Node[String]]
    type_annotation : Node[TypeAnnotation]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.TypeAlias.TypeAlias

    TypeAnnotation

    pub(all) enum TypeAnnotation {
    GenericType(String)
    Typed(Node[(ArrayView[String], String)], ArrayView[Node[TypeAnnotation]])
    Unit
    Tupled(ArrayView[Node[TypeAnnotation]])
    Record(ArrayView[Node[RecordField]])
    GenericRecord(Node[String], Node[ArrayView[Node[RecordField]]])
    FunctionTypeAnnotation(Node[TypeAnnotation], Node[TypeAnnotation])
    } derive(Eq,
    Debug
    )

    Elm.Syntax.TypeAnnotation.TypeAnnotation

    ValueConstructor

    pub(all) struct ValueConstructor {
    name : Node[String]
    arguments : ArrayView[Node[TypeAnnotation]]
    } derive(Eq,
    Debug
    )

    Elm.Syntax.Type.ValueConstructor

    decode_declaration

    fn decode_declaration(json : Json) -> Declaration raise DecodeError

    Elm.Syntax.Declaration.decoder.

    decode_exposing

    fn decode_exposing(json : Json) -> Exposing raise DecodeError

    Elm.Syntax.Exposing.decoder.

    decode_expression

    fn decode_expression(json : Json) -> Expression raise DecodeError

    Elm.Syntax.Expression.decoder.

    decode_file

    fn decode_file(json : Json) -> File raise DecodeError

    Elm.Syntax.File.decoder.

    It reads the JSON that elm-syntax 7.3.9 writes, and the JSON from encode_file and encode_file_with. decode_file(encode_file(f)) gives f back, except for Int literals above 2^53 (use exact_ints=true for those). Malformed input raises DecodeError with the JSON path of the problem.

    test {
    let source = @scanner.SourceText::new(
    "module Main exposing (main)\n\nmain =\n \"hi\"\n",
    )
    let result = @parser.parse_module(source, @scanner.DefaultScanner::new())
    guard result.ast is Some(file) else { fail("no AST") }
    let text = @ast.encode_file(file).stringify()
    let decoded = @ast.decode_file(@json.parse(text))
    inspect(decoded == file, content="true")
    // Malformed input raises an error that names the JSON path.
    try @ast.decode_file({ "imports": [] }) catch {
    e =>
    inspect(
    e,
    content="$: Expecting an OBJECT with a field named `moduleDefinition`",
    )
    } noraise {
    _ => fail("expected a DecodeError")
    }
    }

    decode_function

    fn decode_function(json : Json) -> Function raise DecodeError

    Elm.Syntax.Expression.functionDecoder.

    decode_import

    fn decode_import(json : Json) -> Import raise DecodeError

    Elm.Syntax.Import.decoder.

    decode_infix

    fn decode_infix(json : Json) -> Infix raise DecodeError

    Elm.Syntax.Infix.decoder.

    decode_infix_direction

    fn decode_infix_direction(json : Json) -> InfixDirection raise DecodeError

    Elm.Syntax.Infix.decodeDirection.

    decode_module

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

    Elm.Syntax.Module.decoder.

    decode_module_name

    fn decode_module_name(json : Json) -> ArrayView[String] raise DecodeError

    Elm.Syntax.ModuleName.decoder.

    decode_node

    fn[T] decode_node(json : Json, f : (Json) -> T raise DecodeError) -> Node[T] raise DecodeError

    Elm.Syntax.Node.decoder. Errors raised by f get the prefix $.value.

    decode_pattern

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

    Elm.Syntax.Pattern.decoder.

    decode_range

    fn decode_range(json : Json) -> Range raise DecodeError

    Elm.Syntax.Range.decoder.

    decode_signature

    fn decode_signature(json : Json) -> Signature raise DecodeError

    Elm.Syntax.Signature.decoder.

    decode_top_level_expose

    fn decode_top_level_expose(json : Json) -> TopLevelExpose raise DecodeError

    Elm.Syntax.Exposing.topLevelExposeDecoder (the value inside the Node).

    decode_type

    fn decode_type(json : Json) -> Type raise DecodeError

    Elm.Syntax.Type.decoder.

    decode_type_alias

    fn decode_type_alias(json : Json) -> TypeAlias raise DecodeError

    Elm.Syntax.TypeAlias.decoder.

    decode_type_annotation

    fn decode_type_annotation(json : Json) -> TypeAnnotation raise DecodeError

    Elm.Syntax.TypeAnnotation.decoder.

    decode_value_constructor

    fn decode_value_constructor(json : Json) -> ValueConstructor raise DecodeError

    Elm.Syntax.Type.valueConstructorDecoder.

    encode_declaration

    fn encode_declaration(d : Declaration) -> Json

    Elm.Syntax.Declaration.encode.

    encode_declaration_with

    fn encode_declaration_with(d : Declaration, exact_ints~ : Bool) -> Json

    Elm.Syntax.Declaration.encode. With exact_ints, Int literals are written with their exact digits (elm-syntax writes the nearest Double, which differs above 2^53).

    encode_exposing

    fn encode_exposing(e : Exposing) -> Json

    Elm.Syntax.Exposing.encode.

    encode_expression

    fn encode_expression(e : Expression) -> Json

    Elm.Syntax.Expression.encode.

    encode_expression_with

    fn encode_expression_with(e : Expression, exact_ints~ : Bool) -> Json

    Elm.Syntax.Expression.encode. With exact_ints, Int literals are written with their exact digits (elm-syntax writes the nearest Double, which differs above 2^53).

    encode_file

    fn encode_file(file : File) -> Json

    Elm.Syntax.File.encode.

    The JSON is the JSON that elm-syntax 7.3.9 writes for the same file, with the object keys in elm-syntax's order. The parity check compares the two on a corpus of real packages. An Int literal above 2^53 becomes the nearest Double, as in elm-syntax; use encode_file_with(file, exact_ints=true) to keep its digits.

    test {
    let source = @scanner.SourceText::new("module Main exposing (x)\n\nx = 1\n")
    let result = @parser.parse_module(source, @scanner.DefaultScanner::new())
    guard result.ast is Some(file) else { fail("no AST") }
    let json = @ast.encode_file(file)
    guard json is { "declarations": [declaration], .. } else {
    fail("unexpected shape")
    }
    inspect(
    declaration.stringify(),
    content=(
    #|{"range":[3,1,3,6],"value":{"type":"function","function":{"documentation":null,"signature":null,"declaration":{"range":[3,1,3,6],"value":{"name":{"range":[3,1,3,2],"value":"x"},"arguments":[],"expression":{"range":[3,5,3,6],"value":{"type":"integer","integer":1}}}}}}}
    ),
    )
    }

    encode_file_with

    fn encode_file_with(file : File, exact_ints~ : Bool) -> Json

    Elm.Syntax.File.encode. With exact_ints, Int literals are written with their exact digits (elm-syntax writes the nearest Double, which differs above 2^53). With exact_ints=false the result is the same as encode_file.

    test {
    let source = @scanner.SourceText::new(
    "module Main exposing (..)\n\nbig =\n 9007199254740993\n",
    )
    let result = @parser.parse_module(source, @scanner.DefaultScanner::new())
    guard result.ast is Some(file) else { fail("no AST") }
    // elm-syntax writes the nearest Double.
    let nearest = @ast.encode_file(file).stringify()
    inspect(nearest.contains("9007199254740992"), content="true")
    // exact_ints keeps the digits of the literal.
    let exact = @ast.encode_file_with(file, exact_ints=true).stringify()
    inspect(exact.contains("9007199254740993"), content="true")
    // The decoder reads both forms; the exact form gives the literal back.
    inspect(@ast.decode_file(@json.parse(exact)) == file, content="true")
    }

    encode_function

    fn encode_function(f : Function) -> Json

    Elm.Syntax.Expression.encodeFunction.

    encode_function_with

    fn encode_function_with(f : Function, exact_ints~ : Bool) -> Json

    Elm.Syntax.Expression.encodeFunction. With exact_ints, Int literals are written with their exact digits (elm-syntax writes the nearest Double, which differs above 2^53).

    encode_import

    fn encode_import(i : Import) -> Json

    Elm.Syntax.Import.encode.

    encode_infix

    fn encode_infix(i : Infix) -> Json

    Elm.Syntax.Infix.encode.

    encode_infix_direction

    fn encode_infix_direction(d : InfixDirection) -> Json

    Elm.Syntax.Infix.encodeDirection.

    encode_module

    fn encode_module(m : Module) -> Json

    Elm.Syntax.Module.encode.

    encode_module_name

    fn encode_module_name(m : ArrayView[String]) -> Json

    Elm.Syntax.ModuleName.encode.

    encode_node

    fn[T] encode_node(n : Node[T], f : (T) -> Json) -> Json

    Elm.Syntax.Node.encode: {"range": ..., "value": ...}.

    encode_pattern

    fn encode_pattern(p : Pattern) -> Json

    Elm.Syntax.Pattern.encode.

    encode_pattern_with

    fn encode_pattern_with(p : Pattern, exact_ints~ : Bool) -> Json

    Elm.Syntax.Pattern.encode. With exact_ints, Int literals are written with their exact digits (elm-syntax writes the nearest Double, which differs above 2^53).

    encode_range

    fn encode_range(r : Range) -> Json

    Elm.Syntax.Range.encode: [startRow, startColumn, endRow, endColumn].

    encode_signature

    fn encode_signature(s : Signature) -> Json

    Elm.Syntax.Signature.encode.

    encode_top_level_expose

    fn encode_top_level_expose(t : TopLevelExpose) -> Json

    Elm.Syntax.Exposing.encodeTopLevelExpose (without the Node wrapper).

    encode_type

    fn encode_type(t : Type) -> Json

    Elm.Syntax.Type.encode.

    encode_type_alias

    fn encode_type_alias(a : TypeAlias) -> Json

    Elm.Syntax.TypeAlias.encode.

    encode_type_annotation

    fn encode_type_annotation(t : TypeAnnotation) -> Json

    Elm.Syntax.TypeAnnotation.encode.

    encode_value_constructor

    fn encode_value_constructor(c : ValueConstructor) -> Json

    Elm.Syntax.Type.encodeValueConstructor.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io