cm-tarnation
Version:
An alternative parser for CodeMirror 6
63 lines (62 loc) • 2.47 kB
TypeScript
import type { BufferCursor } from "@lezer/common";
import type { Chunk } from "./chunk";
/** Stack used by the parser to track tree construction. */
export declare type ParseElementStack = [id: number, start: number, children: number][];
/**
* A `ParseStack` keeps track of opened nodes destined to be eventually
* closed. Any number of nodes can be open, and this is how parsing
* actually creates a tree with depth.
*/
export declare class ParseStack {
/** The actual array stack. */
stack: ParseElementStack;
/** @param stack - The stack to use as the starting state, which will be cloned. */
constructor(stack?: ParseElementStack);
/**
* Parses a {@link Chunk}, returning the parsed out {@link LezerToken}s.
* Mutates this {@link ParseStack}, and caches the resultant tokens and
* stack into the {@link Chunk} as well.
*
* @param chunk - The chunk to parse.
*/
parse(chunk: Chunk): ArrayBufferLike;
/** Add a child to every element. */
increment(): void;
/**
* Add a new element.
*
* @param id - The node type of the token.
* @param start - The start position of the token.
* @param children - The number of children the token will start with.
*/
push(id: number, start: number, children: number): void;
/** Remove and return the last element. */
pop(): [id: number, start: number, children: number] | undefined;
/** Remove every element past the index given. */
close(idx: number): void;
/** Returns the last element with the given ID. */
last(id: number): number | null;
/** Returns a clone of this stack. */
clone(): ParseStack;
}
/**
* Compiles, and if needed, parses, a list of {@link Chunk}s. Returns a
* `Tree.build` compatible buffer and a list of "reused" trees for language nesting.
*
* @param chunks - The chunks to compile.
* @param end - The length of the document.
*/
export declare function compileChunks(chunks: Chunk[], end: number): ArrayBufferCursor;
/** Cursor that the `Tree.buildData` function uses to read a buffer. */
declare class ArrayBufferCursor implements BufferCursor {
readonly buffer: Uint32Array;
pos: number;
constructor(buffer: Uint32Array, pos: number);
get id(): number;
get start(): number;
get end(): number;
get size(): number;
next(): void;
fork(): ArrayBufferCursor;
}
export {};