cm-tarnation
Version:
An alternative parser for CodeMirror 6
86 lines (85 loc) • 3.22 kB
TypeScript
import type { GrammarStackElement, MatchOutput, VariableTable } from "../types";
import type { Node } from "./node";
import type { Rule } from "./rules/rule";
import type { State } from "./rules/state";
/** Internal state for a {@link Grammar}. */
export declare class GrammarState {
variables: VariableTable;
context: Record<string, string>;
stack: GrammarStack;
last?: MatchOutput | undefined;
/**
* @param variables - The variables to use when substituting.
* @param context - The current context table.
* @param stack - The current {@link GrammarStack}.
* @param last - The last {@link MatchOutput} that was matched.
*/
constructor(variables: VariableTable, context?: Record<string, string>, stack?: GrammarStack, last?: MatchOutput | undefined);
/**
* Sets a key in the context table.
*
* @param key - The key to set.
* @param value - The value to set. If `null`, the key will be removed.
*/
set(key: string, value: string | null): void;
/**
* Gets a key from the context table.
*
* @param key - The key to get.
*/
get(key: string): string | null;
/**
* Expands any substitutions found in the given string.
*
* @param str - The string to expand.
*/
sub(str: string): import("../types").Variable;
/**
* Returns if another {@link GrammarState} is effectively equivalent to this one.
*
* @param other - The other {@link GrammarState} to compare to.
*/
equals(other: GrammarState): boolean;
/** Returns a new clone of this state, including its stack. */
clone(): GrammarState;
}
/** A stack of {@link GrammarStackElement}s used by a {@link Grammar}. */
export declare class GrammarStack {
/** The current stack. */
readonly stack: GrammarStackElement[];
/** @param stack - The stack array to use. Will be shallow cloned. */
constructor(stack?: GrammarStackElement[]);
/**
* Pushes a new {@link GrammarStackElement}.
*
* @param node - The parent {@link Node}.
* @param rules - The rules to loop parsing with.
* @param end - A specific {@link Rule} that, when matched, should pop
* this element off.
*/
push(node: Node, rules: (Rule | State)[], end: Rule | State): void;
/** Pops the last element on the stack. */
pop(): GrammarStackElement | undefined;
/**
* Remove every element at or beyond the index given.
*
* @param idx - The index to remove elements at or beyond.
*/
close(idx: number): void;
/**
* Returns if another {@link GrammarStack} is effectively equivalent to this one.
*
* @param other - The other {@link GrammarStack} to compare to.
*/
equals(other: GrammarStack): boolean;
/** The number of elements on the stack. */
get length(): number;
/** The last parent {@link Node}. */
get node(): Node;
/** The last list of rules. */
get rules(): (State | Rule)[];
/** The last end rule. */
get end(): State | Rule | null;
/** Returns a new clone of this stack. */
clone(): GrammarStack;
}