Skip to content

Commit

Permalink
Export DocInput
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marijnh committed May 19, 2023
1 parent 01fda91 commit d9c7c45
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

@LanguageDescription

@DocInput

### Highlighting

@HighlightStyle
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
15 changes: 9 additions & 6 deletions src/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit d9c7c45

Please sign in to comment.