bobzhang/peg/vm does not have a README file

    ActionFn

    Implementation of an action or semantic predicate code block. Predicates return a value whose JavaScript truthiness decides the match.

    InitFn

    Implementation of a grammar's initializer block. It runs once per parse (after the start rule is validated) and returns bindings that take precedence over the statically supplied ones, so actions can share per-parse state by closing over it.

    SyntaxError

    Raised by a parser when the input does not match the grammar, or by the error() / expected() action helpers.

    expected and found are None for errors raised through error(), like the null fields of PEG.js' peg$SyntaxError.

    Tracer

    Receives rule enter/match/fail events when tracing is enabled.

    Value

    A dynamically typed value produced by a PEG.js-style parser.

    Mirrors the JavaScript values PEG.js parsers produce: literals, classes and . yield Str, sequences and repetitions yield Arr, ? yields Null on failure and predicates yield Undefined. Custom carries application payloads produced by actions.

    UnboundCode

    pub(all) suberror UnboundCode {
    UnboundCode(kind~ : String, code~ : String)
    } derive(
    Debug
    )

    Raised when a code block of the grammar has no MoonBit implementation.
    impl Show for UnboundCode

    Parser

    pub struct Parser[T] {
    program :
    Program
    ?
    // private fields
    }

    A generated parser.

    Usually built from a compiled Program by Parser::from_program, but any parse function can be wrapped (e.g. by compiler plugins).

    Parser::from_fn

    Wraps a parse function. It receives the input, the parse options (which include startRule / filename when given) and the tracer, if any.

    Parser::from_program

    Builds a parser interpreting program.

    Each action / predicate code block is implemented by the entry of actions keyed by its exact body or trimmed body (see lookup_binding). A grammar initializer requires initializer, which runs per parse and may supply further bindings. Raises UnboundCode for missing bindings (at parse time for bindings the initializer is expected to provide).

    Parser::parse

    fn[T] Parser::parse(self : Parser[T], input : String, start_rule? : String, filename? : String, tracer? :
    Tracer
    [T], options? : Map[String,
    Value
    [T]]) ->
    Value
    [T] raise

    Parses input, returning the start rule's result.

    options is exposed to actions as PEG.js' options object; start_rule and filename are shorthands for its startRule and filename entries. Raises @runtime.SyntaxError when the input does not match.

    lookup_binding

    fn[V] lookup_binding(bindings : Map[String, V], index : Int, body : String) -> V?

    Looks up the implementation of code block number index (its position in Program::functions) with source text body. Keys are tried in order:

    1. "#<index>" — exact, but specific to one compilation of the grammar;
    2. the exact body text;
    3. the body with surrounding whitespace trimmed (so a grammar can simply say { makeNumber }).

    Identical bodies with different labels in scope share a text key, so actions bound by text should read labels by name (ActionContext::label).