cm-tarnation
Version:
An alternative parser for CodeMirror 6
73 lines (72 loc) • 2.72 kB
TypeScript
import { Wrapping } from "../constants";
import type { GrammarToken, MatchOutput } from "../types";
import { Node } from "./node";
import type { GrammarState } from "./state";
/** Represents a leaf or branch of a tree of matches found by a grammar. */
export declare class Matched {
/** The current {@link GrammarState}. */
state: GrammarState;
/** The match's {@link Node} type. */
node: Node;
/** The entire matched string. */
total: string;
/** The start of the match. */
from: number;
/** The children contained by this match's {@link Node}. */
captures?: Matched[] | undefined;
/**
* The wrapping mode of the match. There are three modes:
*
* - FULL: The {@link Node} in this match contains the entirety of the branch.
* - BEGIN: The {@link Node} in this match begins the branch.
* - END: The {@link Node} in this match ends the branch.
*/
wrapping: Wrapping;
/** The total length of the match. */
length: number;
constructor(
/** The current {@link GrammarState}. */
state: GrammarState,
/** The match's {@link Node} type. */
node: Node,
/** The entire matched string. */
total: string,
/** The start of the match. */
from: number,
/** The children contained by this match's {@link Node}. */
captures?: Matched[] | undefined,
/**
* The wrapping mode of the match. There are three modes:
*
* - FULL: The {@link Node} in this match contains the entirety of the branch.
* - BEGIN: The {@link Node} in this match begins the branch.
* - END: The {@link Node} in this match ends the branch.
*/
wrapping?: Wrapping);
/** Changes the starting offset of the match. */
offset(offset: number): void;
/**
* Wraps this `Matched` with another one.
*
* @param node - The node of the `Matched` to wrap with.
* @param wrap - The wrapping mode, if different.
*/
wrap(node: Node, wrap?: Wrapping): Matched;
/**
* Pushes an opening or closing node to one side of this matches captures.
*
* @param node - The node to push.
* @param side - The side to push to.
* @param wrap - The wrapping mode of the node. Can't be `FULL`.
*/
push(node: Node, side: -1 | 1, wrap?: Wrapping): void;
/** Returns this match represented as a raw {@link MatchOutput}. */
output(): MatchOutput;
/** Internal method for compiling. */
private _compile;
/**
* Compiles this match into a list of tokens. Always returns a list, even
* if this match represents a leaf.
*/
compile(): GrammarToken[];
}