From d9c7c45a6164cb6de6e2d8b90d403a39178f2e67 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Fri, 19 May 2023 14:17:47 +0200 Subject: [PATCH] Export DocInput FEATURE: Export `DocInput` class for feeding editor documents to a Lezer parser. See https://discuss.codemirror.net/t/exporting-docinput-from-the-language-package/6506 --- src/README.md | 2 ++ src/index.ts | 2 +- src/language.ts | 15 +++++++++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/README.md b/src/README.md index 591a187..467f384 100644 --- a/src/README.md +++ b/src/README.md @@ -28,6 +28,8 @@ @LanguageDescription +@DocInput + ### Highlighting @HighlightStyle diff --git a/src/index.ts b/src/index.ts index 14e2f52..a68ac20 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ export {language, Language, LRLanguage, Sublanguage, sublanguageProp, defineLanguageFacet, syntaxTree, ensureSyntaxTree, languageDataProp, ParseContext, LanguageSupport, LanguageDescription, - syntaxTreeAvailable, syntaxParserRunning, forceParsing} from "./language" + syntaxTreeAvailable, syntaxParserRunning, forceParsing, DocInput} from "./language" export {IndentContext, getIndentUnit, indentString, indentOnInput, indentService, getIndentation, indentRange, indentUnit, TreeIndentContext, indentNodeProp, delimitedIndent, continuedIndent, flatIndent} from "./indent" diff --git a/src/language.ts b/src/language.ts index 379674c..ff5b0d2 100644 --- a/src/language.ts +++ b/src/language.ts @@ -249,12 +249,15 @@ export function syntaxParserRunning(view: EditorView) { return view.plugin(parseWorker)?.isWorking() || false } -// Lezer-style Input object for a Text document. -class DocInput implements Input { - cursor: TextIterator - cursorPos = 0 - string = "" - +/// Lezer-style +/// [`Input`](https://lezer.codemirror.net/docs/ref#common.Input) +/// object for a [`Text`](#state.Text) object. +export class DocInput implements Input { + private cursor: TextIterator + private cursorPos = 0 + private string = "" + + /// Create an input object for the given document. constructor(readonly doc: Text) { this.cursor = doc.iter() }