UNPKG

cm-tarnation

Version:

An alternative parser for CodeMirror 6

55 lines (54 loc) 2.13 kB
import { NodeID } from "../constants"; import type { VariableTable } from "../types"; import type * as DF from "./definition"; import type { Grammar } from "./grammar"; import { Node } from "./node"; import { Rule } from "./rules/rule"; import { State } from "./rules/state"; /** Holds the rules, states, etc. for a {@link Grammar}. */ export declare class Repository { grammar: Grammar; variables: VariableTable; ignoreCase: boolean; /** Map of names to objects stored in this repository. */ private map; /** Current {@link Node} ID. */ private curID; constructor(grammar: Grammar, variables: VariableTable, ignoreCase?: boolean); /** Returns every {@link Node} in the repository, sorted by ID. */ nodes(): Node[]; /** Returns a fresh ID for use by a {@link Node}. */ id(): NodeID; /** * Adds an object to the repository. * * @param obj - The object to add. * @param name - If given, this name will be assumed to be the object's * name if it doesn't have one already. */ add(obj: DF.State, name?: string): State; add(obj: DF.Regex | DF.Rule, name?: string): Rule; add(obj: DF.Regex | DF.Rule | DF.State, name?: string): Rule | State; add(obj: DF.Node | DF.ReuseNode, name?: string): Node; add(obj: DF.RepositoryItem, name?: string): Node | Rule | State; /** * Gets an object from this repository. If it doesn't exist already, the * grammar definition will be checked. Returns `undefined` if nothing can * be found. * * @param key - The name of the object to get. */ get(key: string): Node | State | Rule | undefined; /** * Processes an `include` from the grammar definition, by name. * * @param str - The name of the `include` to process. */ include(str: string): (State | Rule)[]; /** * Processes an "inside" list of rules/states/includes, returning a resolved list. * * @param rules - The list of rules/states/includes to process. */ inside(rules: DF.Inside): (State | Rule)[]; }