@r47onfire/nebula - v0.0.0
    Preparing search index...

    Interface OpContext<R>

    The services an operation's call needs from the parser: the input, the grammar, the memoizing entry point for sub-parses, error recovery, and the cut bookkeeping. Provided by parseToCST; see there for what each one does.

    interface OpContext<R extends string> {
        applyCut(depth: number): void;
        applyRule(
            path: string,
            node: GrammarCombinator<R, any>,
            i: number,
            locals: Locals<any>,
            dynamics: Dynamics,
        ): MatchFail | CSTNode<R>;
        committedDepth(): number;
        consumeCut(): void;
        createSpan(begin: number, end: number): Span;
        cutDepth(): number;
        errorNode(
            start: number,
            end: number,
            expected: GrammarCombinator<R, any>,
        ): CSTNode<R>;
        grammar: Grammar<R>;
        inCommittedScope(): boolean;
        memo: Memo<R>;
        popCutFrame(): number;
        pushCutFrame(): void;
        recover(
            path: string,
            item: GrammarCombinator<R, any>,
            i: number,
            fail: MatchFail,
            children: CSTNode<R>[],
            locals: Locals<any>,
            dynamics: Dynamics,
        ): number;
        recoverChild(
            path: string,
            child: GrammarCombinator<R, any>,
            i: number,
            fail: MatchFail,
            children: CSTNode<R>[],
            locals: Locals<any>,
            dynamics: Dynamics,
        ): number | null;
        restoreCuts(saved: readonly number[]): void;
        snapshotCuts(): readonly number[];
        text: string;
    }

    Type Parameters

    • R extends string
    Index
    grammar: Grammar<R>
    memo: Memo<R>
    text: string
    • Records a cut of the given depth in the innermost frame.

      Parameters

      • depth: number

      Returns void

    • How many open frames currently hold a cut.

      Returns number

    • Marks the innermost frame's cut as consumed by the current alternative.

      Returns void

    • Create a span for the given index

      Parameters

      Returns Span

    • Cut depth of the innermost open rule frame (0 if there is none).

      Returns number

    • True if an enclosing construct has committed (cut) without finishing yet. Resyncs inside such a scope must stay local to it!

      Returns boolean

    • Pops the innermost cut frame and returns the depth it reached.

      Returns number

    • Pushes a fresh cut frame for a rule invocation.

      Returns void

    • Panic-mode recovery: scan forward for the next index where item matches, turning all skipped source into a single error node. Returns the index to continue parsing from. If nothing works, emits an error up to end of input.

      Only used when NOT inside a committed scope. Inside one, the enclosing construct owns resynchronization (seq_sep rescans for its failed child; repeats emit a minimal error), so no bracket guessing is needed.

      Parameters

      Returns number

    • Local recovery for a sequence with a fail after a cut. Resynchronize to the nearest position where that child matches, keeping the committed prefix intact. Returns the index to continue from, or null if the child never matches (give up and propagate the fail).

      The skipped text becomes a BAD node that carries the recovered child in its recovered field. This keeps the sequence's fixed arity while still allowing the parse to recover later

      Parameters

      Returns number | null

    • A snapshot of the cut stack's depths, for speculative parses.

      Returns readonly number[]