Documentation
¶
Overview ¶
Package stream highlights a document with a CodeMirror 5-style stream mode, as CodeMirror's StreamLanguage does for the languages @codemirror/legacy-modes covers and Lezer does not.
Index ¶
- Constants
- func Highlight(text []uint16, mode Mode, sets *lezer.TagSets, ...)
- func IsDigit(u uint16) bool
- func IsSpace(u uint16) bool
- func IsWord(u uint16) bool
- type Mode
- type Stream
- func (s *Stream) BackUp(n int)
- func (s *Stream) Current() []uint16
- func (s *Stream) EOL() bool
- func (s *Stream) Eat(c uint16) bool
- func (s *Stream) EatFunc(match func(uint16) bool) bool
- func (s *Stream) EatSpace() bool
- func (s *Stream) EatWhile(match func(uint16) bool) bool
- func (s *Stream) Line() []uint16
- func (s *Stream) LookingAt(text string) bool
- func (s *Stream) Match(text string) bool
- func (s *Stream) MatchFunc(match func(rest []uint16) int) bool
- func (s *Stream) Next() int
- func (s *Stream) Peek() int
- func (s *Stream) SOL() bool
- func (s *Stream) SkipTo(c uint16) bool
- func (s *Stream) SkipToEnd()
Constants ¶
const EOL = -1
EOL is what Peek and Next return at the end of the line, where JavaScript's StringStream returns undefined.
Variables ¶
This section is empty.
Functions ¶
func Highlight ¶
func Highlight(text []uint16, mode Mode, sets *lezer.TagSets, span func(from, to int, set *lezer.TagSet))
Highlight calls span, in order, for every token of text (UTF-16 code units, split into lines at "\n" alone) whose style names tags, as highlightTree does with a highlighter that gives every tag its own class over the tree a StreamLanguage parses. Positions are code units.
A mode that returns a token without reading anything ten times in a row is a bug, and Highlight panics, where CodeMirror's parse throws.
Types ¶
type Mode ¶
type Mode interface {
// Token reads one token from s and returns its style, "" for none: a
// legacy name ("variable", "def") or tag names joined by "." and " ",
// as @codemirror/language's legacy token table reads them.
Token(s *Stream) string
}
Mode is a stream mode with its state: a fresh one for each document, since a mode carries its state from line to line.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream is one line of a document, read by a mode one token at a time. Like JavaScript's StringStream it counts in UTF-16 code units, so a character outside the BMP is two units and a mode sees them one by one.
func (*Stream) EatWhile ¶
EatWhile reads code units as long as match accepts them, and reports whether it read any.
func (*Stream) LookingAt ¶
LookingAt reports whether the line continues with text, an ASCII string, without reading it: match(text, false).
func (*Stream) Match ¶
Match reads text if the line continues with it, as StringStream's match does with a string.
func (*Stream) MatchFunc ¶
MatchFunc reads what match finds at the start of the rest of the line, the job of a regular expression starting with ^ in StringStream's match: match returns the length it matched, or -1 for none.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package kotlin is the Kotlin mode of @codemirror/legacy-modes, the one CodeMirror highlights Kotlin with.
|
Package kotlin is the Kotlin mode of @codemirror/legacy-modes, the one CodeMirror highlights Kotlin with. |
|
Package shell is the shell mode of @codemirror/legacy-modes, the one CodeMirror highlights shell scripts with.
|
Package shell is the shell mode of @codemirror/legacy-modes, the one CodeMirror highlights shell scripts with. |
|
Package streamtest checks a mode's port against what CodeMirror gives: the goldens internal/stream/gen/golden.mjs writes, one per fixture.
|
Package streamtest checks a mode's port against what CodeMirror gives: the goldens internal/stream/gen/golden.mjs writes, one per fixture. |