cm-tarnation
Version:
An alternative parser for CodeMirror 6
36 lines (35 loc) • 1.15 kB
TypeScript
import type { GrammarToken, ParserAction } from "./types";
/**
* An `ArrayBuffer` stored token. This is effectively a highly efficient
* representation of a {@link GrammarToken}.
*
* Uses an ArrayBuffer that is, in order:
*
* - The token ID, which is a uint8
* - The token from position, which is a uint32
* - The token length, which is a uint16
* - A repeating list of parser actions
*
* Parser actions are:
*
* - Action type, which is a uint8 (0 is OPEN, 1 is CLOSE)
* - Node id, which is a uint8
*/
export declare class Token {
readonly buffer: ArrayBuffer;
private readonly view;
constructor(id: number | null, from: number, to: number, open?: ParserAction, close?: ParserAction);
/** Returns true if the token has any parser actions. */
hasActions(): boolean;
/** Reads the actions from the token. */
actions(): {
open: ParserAction | undefined;
close: ParserAction | undefined;
};
/**
* Reads out the token.
*
* @param offset - The offset to add to the token's position.
*/
read(offset?: number): GrammarToken;
}