cm-tarnation
Version:
An alternative parser for CodeMirror 6
102 lines (101 loc) • 3.7 kB
TypeScript
import type { Input, TreeFragment } from "@lezer/common";
/**
* The region of a document that should be parsed, along with other
* information such as what the edited range of the document was.
*/
export declare class ParseRegion {
/** The parser should start before or at this position. */
from: number;
/** The parse should stop past or at this position. */
to: number;
/**
* The range describing the original parse range when this region was
* constructed. This is so that the `from` and `to` properties can be
* modified while retaining originally designated parse range.
*/
original: {
/** The start of the original range. */
from: number;
/** The end of the original range. */
to: number;
/** The length of the original range. */
length: number;
};
/** The edited range of the document. */
edit?: {
/** The start of the edited range. */
from: number;
/** The end of the edited range. */
to: number;
/** The number of characters added in the change. */
offset: number;
};
/** The `Input` used to read strings from the document. */
input: Input;
/** The ranges to be parsed. */
ranges: {
from: number;
to: number;
}[];
/** The current viewport of the document, if available. */
viewport?: {
from: number;
to: number;
};
/**
* @param input - The input to get the parse region for.
* @param ranges - The ranges of the document that should be parsed.
* @param fragments - Fragments that are used to compute the edited range.
*/
constructor(input: Input, ranges: {
from: number;
to: number;
}[], fragments?: TreeFragment[], viewport?: {
from: number;
to: number;
});
/** The length of the region. */
get length(): number;
/** True if we don't need to care about range handling. */
get contiguous(): boolean;
/**
* Compensates for an adjustment to a position. That is, given the range
* `pos` is inside of, what position should adding `addition` return?
* This is for skipping past the gaps inbetween ranges.
*
* @param pos - The position to start from.
* @param addition - The amount to add to `pos`.
*/
compensate(pos: number, addition: number): number;
/**
* Clamps a `to` value for a range to the end of the parse range that
* `from` is inside of.
*
* @param from - The `from` position, for which the `to` position will be
* clamped relative to.
* @param to - The `to` position, which will be clamped to the end of the
* range that `from` is inside of.
*/
clamp(from: number, to: number): number;
/**
* Gets what range the given position is inside of. Returns `null` if the
* position can't be found inside of any range.
*
* @param pos - The position to get the range for.
* @param side - The side of the range to get. -1 returns the range
* previous, 1 returns the range after. Defaults to 0.
*/
posRange(pos: number, side?: -1 | 0 | 1): {
from: number;
to: number;
} | null;
/**
* Gets a substring of the current input, accounting for range handling
* automatically.
*
* @param pos - The position to start at.
* @param min - The minimum length of the substring.
* @param max - The maximum position of the end of the substring.
*/
read(pos: number, min: number, max: number): string;
}