krueger

    Parser and parsing utilities for Elm and Elm-like dialects (e.g. Morphir) in MoonBit

    elm
    elm-like
    morphir
    parser
    scanner
    ast
    Download zip
    Author
    Version
    0.2.0
    License
    Apache-2.0
    Last updated
    8 hours ago
    Downloads
    4

    Dependencies

    #moonrockz/krueger

    Parser and parsing utilities for Elm and Elm-like dialects (such as Morphir) in MoonBit.

    #Status

    Project setup only. Scanner, parser, AST, and visitor interfaces will be designed and implemented in a follow-up phase. The repository is configured with:

    • MoonBit module and single-package layout
    • CI (lint + unit tests) and Release (validate → publish → GitHub Release) pipelines
    • Mise and file-based tasks (hooks:install, info:generate, lint:check, format:check, check, test:unit, test:bdd, test:e2e, test, release:version, release:credentials, release:publish)
    • AGENTS.md / CLAUDE.md and conventional commits

    #Installation

    moon add moonrockz/krueger

    #Development Setup

    Install project-level git hooks (managed by lefthook) with:

    mise run hooks:install

    #Usage (future)

    Once the library is implemented, you can expect APIs along the lines of:

    • Scanner: tokenize Elm/Elm-like source into a token stream.
    • Parser: parse tokens (or source) into an AST.
    • AST: algebraic types for modules, declarations, expressions, etc.
    • Visitors: flexible traversal (DOM, fold, SAX-style), similar to moonrockz/gherkin.

    #License

    Apache-2.0

    AttributeGroup

    The attributes of the module or of one declaration, in source order.

    AttributeSyntax

    Whether attributes in doc comments are parsed.

    AttributeTarget

    What a group of doc-comment attributes belongs to.

    Block

    One block of a report. Excerpt shows the source lines of context with markers under highlight; renderers read the lines from the source.

    Case

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    CaseBlock

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    Cases

    Elm.Syntax.Expression.Cases

    Chunk

    A piece of report text: plain, or styled like elm make styles code and keywords.

    Color

    Colours of elm make reports. Vivid* are the bright variants; in the --report=json output they are upper case ("RED"), the others lower case.

    Control

    What a traversal does after it enters a node.

    Declaration

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    DeclarationCst

    DecodeError

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    DefaultModuleData

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    Dialect

    A variant of Elm: which rejection rules run, and the extension data (operator table, extra reserved words, extra operator symbols) the scanner and the parser read. The AST shape is elm-syntax 7.3.9 in every dialect.

    • An extra operator symbol must start with a character the lexer already treats as a symbol (+ - / * = . < > : & | ^ ?) and must not start with -- (a line comment).
    • An extra reserved word must not be alias, infix or effect: the parser reads those by name.
    • { ..d, field: value } shares rules and operators with d; copy them before changing either.

    DocAttribute

    One attribute line in a doc comment: @name value..., or the built-in @docs a, b list.

    Documentation

    type Documentation = String

    Elm.Syntax.Documentation.Documentation

    EffectModuleData

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    EnterEvent

    What an Enter event tells: only what a streaming parser knows when a node starts. field is the node's field in its parent and path the steps from the start node (None and the empty path for the start node); depth is path.depth().

    Event

    A traversal event, in walk order.

    EventReader

    Reads the events of a tree one at a time (the walk engine, paused between next calls). Each reader owns its state; readers over one tree do not affect each other.

    EventSource

    A pull source of events in walk order. skip_children is valid right after an Enter: the next event is then that node's Leave. Elsewhere it does nothing.

    ExposedType

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    Exposing

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    Expression

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    File

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    Function

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    FunctionCst

    FunctionImplementation

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    Handler

    Receives pushed events. on_enter steers the traversal like a walk's enter; both methods have defaults (Continue, nothing).

    Import

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    ImportCst

    Infix

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    InfixDirection

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    KeywordKind

    Reserved words of Elm 0.19.1 as elm-syntax 7.3.9 treats them. alias, infix and effect are not reserved; they are identifiers.

    Lambda

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    LeaveEvent

    What a Leave event tells: the finished node, with the depth and path of its Enter.

    LetBlock

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    LetDeclaration

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    Location

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    Module

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    ModuleCst

    ModuleHeaderCst

    ModuleName

    type ModuleName = ArrayView[String]

    Elm.Syntax.ModuleName.ModuleName

    Node

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    NodePath

    Where a node sits below a start node: the steps from the start node, each a field and an index, like a path into elm-syntax's JSON. A path is immutable; a child's path shares its parent's steps.

    NodeRef

    A read-only reference to one node of a parse result. Each case points into the typed AST (nothing is copied). Generic code uses category, kind, range, children and field; typed code matches the cases.

    Kinds and field names follow the JSON that elm-syntax (and @ast.encode_*) writes. elm-syntax reuses tags across node types (record, list, unit, …), so (category, kind) identifies a node type.

    OperatorDef

    An infix operator: its symbol, precedence (1 to 9) and direction.

    ParseResult

    Result of parsing one Elm module.

    ast is the elm-syntax AST, present when the module header is valid. cst keeps every token and every declaration that parses. diagnostics lists scanner and parser problems.

    PathStep

    One step of a node path: a field of the parent and the node's index in that field (0 for a field that holds one node).

    Pattern

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    QualifiedNameRef

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    Range

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    RecordDefinition

    Elm.Syntax.TypeAnnotation.RecordDefinition

    RecordField

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    RecordSetter

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    Rule

    A rejection rule: one class of syntax that a dialect rejects. A rule only runs when the dialect enables it.

    ScanErrorList

    Signature

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    TopLevelExpose

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    Tree

    A parse result as a tree with random access: parents, ancestors, paths, the node at a position and the tokens in a range. It is built once and never changes; its indexes are private.

    TreeCursor

    A tree-sitter-style cursor: the caller moves it with the goto_* methods. Each goto_* returns false and leaves the cursor in place when there is nowhere to go. Its state is a stack of frames, not recursion. A cursor belongs to its caller; copy gives an independent cursor.

    Type

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    TypeAlias

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    TypeAliasCst

    TypeAnnotation

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    UnionTypeCst

    ValueConstructor

    elm-syntax 7.3.9 model. Elm.Syntax.Comments.Comment is not re-exported because the scanner's Comment type uses the same name.

    Visitor

    A visitor over the node model: one method per group of node types (see accept for which method sees which node). Every method has a default: visit_* returns Continue and leave does nothing, so a visitor implements only what it needs. The visitor's state belongs to the caller.

    accept

    Walk root (see walk) and call one visitor method per node: functions (top-level or let) → visit_function; other declarations → visit_declaration; expressions, patterns, types → visit_expression, visit_pattern, visit_type; case branches → visit_case; imports, comments, doc attributes → visit_import, visit_comment, visit_attribute; every other node (doc comments included) → visit_other. The method's Control steers the walk; leave runs after each node's children.

    diagnostic_description

    fn diagnostic_description(code : String) -> String?

    The fixed meaning of a diagnostic code, or None for an unknown code.

    encode_attributes

    Attribute groups as JSON, for tools.

    encode_attributes_with

    fn encode_attributes_with(groups : Array[
    AttributeGroup
    ], exact_ints~ : Bool) -> Json

    Attribute groups as JSON. With exact_ints, Int arguments are written with their exact digits (see @ast.encode_file_with).

    encode_diagnostics

    All diagnostics (warnings too) with krueger's codes, as JSON.

    fold

    Walk root (see walk) with an accumulator: enter and leave take the current value and return the next one, in walk's callback order. The result is the value after the last callback. The accumulator belongs to the caller; fold does not copy it.

    is_lower_start

    fn is_lower_start(c : Char) -> Bool

    Whether c can start a lower-case name (a Unicode lower-case letter).

    is_name_part

    fn is_name_part(c : Char) -> Bool

    Whether c can continue a name: a Unicode letter or number, or _.

    is_upper_start

    fn is_upper_start(c : Char) -> Bool

    Whether c can start an upper-case name (a Unicode upper-case or title-case letter).

    kind_table

    fn kind_table() -> Array[(String, String, Array[String])]

    Every node type: (category, kind, fields), one row per kind. AGENTS.md lists the same table.

    parse_module

    Tokenize and parse source in dialect (default: Elm 0.19.1).

    parse_tokens

    Parse a token stream in dialect (default: Elm 0.19.1).

    push_events

    fn[S :
    EventSource
    , H :
    Handler
    ] push_events(source : S, handler : H) -> Unit

    Pull every event from source and push it to handler: on_enter for Enter (its SkipChildren skips the node's children, its Stop ends the run) and on_leave for Leave.

    render_elm_json

    Errors in diags in the shape of elm make --report=json output. Warnings are left out: elm make has none.

    render_plain

    A diagnostic as plain text, laid out like elm make output.

    render_terminal

    fn render_terminal(diag :
    Diagnostic
    , source :
    SourceText
    , path : String) -> String

    A diagnostic for a terminal, with ANSI colours like elm make.

    standard_operators

    The infix operators of Elm 0.19.1 as elm-syntax 7.3.9 knows them, including </> and <?> from elm/url.

    version

    fn version() -> String

    Krueger — Parser and parsing utilities for Elm and Elm-like dialects (e.g. Morphir).

    This module will provide scanner, parser, AST, and visitor interfaces with flexibility similar to moonrockz/gherkin. Project setup only; scanner/parser/AST/visitor design in a follow-up.

    walk

    Visit root and every node below it in pre-order (source order). enter runs when a node is reached and decides what happens next; leave runs after all of a node's children, with the same node object. An explicit stack, not recursion, holds the open nodes, so trees of any depth work on every target. All traversal state belongs to this call.