UNPKG

cm-tarnation

Version:

An alternative parser for CodeMirror 6

78 lines (77 loc) 3.21 kB
import { Language, LanguageDescription, LanguageSupport } from "@codemirror/language"; import type { Extension, Facet } from "@codemirror/state"; import { NodeProp, NodeSet, NodeType } from "@lezer/common"; import type { ChunkBuffer } from "./compiler/buffer"; import { Autocompleter } from "./completion/autcomplete"; import type * as DF from "./grammar/definition"; import { Grammar } from "./grammar/grammar"; import type { ParserConfiguration, TarnationLanguageDefinition } from "./types"; /** * Tarnation language. Use the `load` method to get the extension needed to * load the language into CodeMirror. If you need a `LanguageDescription`, * the `description` property will hold one. */ export declare class TarnationLanguage { /** CodeMirror language data. */ languageData: Record<string, any>; /** The grammar definition (or a function that returns one). */ grammarData: DF.Grammar | (() => DF.Grammar); /** Extra configuration for the parser. */ configure: ParserConfiguration; /** List of extensions to load with the language. */ extensions: Extension[]; /** `LanguageDescription` instance for the language. */ description: LanguageDescription; /** * Languages that are supported for nesting. Can also be a facet that * provides the list. */ nestLanguages: LanguageDescription[] | Facet<LanguageDescription>; /** Fully resolved grammar instance. Requires the language to have been loaded. */ grammar?: Grammar; /** * The CodeMirror top node for the language. Requires the language to * have been loaded. */ topNode?: NodeType; /** * All of the node types used by the language. Requires the language to * have been loaded. */ nodeTypes?: NodeType[]; /** * CodeMirror `NodeSet` for the language. Requires the language to have * been loaded. */ nodeSet?: NodeSet; /** * The `NodeProp` that points to the `ChunkBuffer` data. Will be assigned * to the top node of the language. Requires the language to have been loaded. */ stateProp?: NodeProp<ChunkBuffer>; /** * Autocompleter instance. Requires the language to have been loaded, but * will only be there if there are any autocompletion handlers. */ autocompleter?: Autocompleter; /** * `LanguageSupport` instance for the language. Requires the language to * have been loaded. */ support?: LanguageSupport; /** * CodeMirror `language` instance for the language. Requires the language * to have been loaded. */ language?: Language; /** Will be true if the langauge has been loaded once. */ loaded: boolean; /** Will be set to the number of milliseconds the last parse time took. */ performance: number; constructor({ name, grammar, nestLanguages, configure, alias, extensions, languageData, supportExtensions }: TarnationLanguageDefinition); /** * Loads and processes the language. Calling this function repeatedly * will just return the previously loaded language. */ load(): LanguageSupport; }