HighlightResult class final

The output of highlighting: code split into contiguous tokens.

Tokens are stored flat, as two parallel integer lists, rather than as a tree of objects. Token i covers code[tokenStart(i), tokenEnd(i)) and carries a scope stack id from scopes. Tokens always cover all of code with no gaps, and neighbouring tokens never share a stack.

Constructors

HighlightResult.fromBuffers({required String code, required Grammar language, required ScopeTable scopes, required Int32List ends, required Int32List stacks, required int tokenCount, Int32List? lineStarts})
Creates a result from raw token buffers.

Properties

code → String
The highlighted source.
final
hashCode → int
The hash code for this object.
no setterinherited
language → Grammar
Grammar used to highlight code.
final
lineCount → int
Number of lines. Empty code has one empty line, and a trailing \n starts a final empty line.
no setter
rawEnds → Int32List
The raw token end offsets, for engines that copy tokens in bulk. Only the first tokenCount entries are valid.
no setter
rawStacks → Int32List
The raw token stack ids, alongside rawEnds.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scopes → ScopeTable
Scope names and stacks referenced by the tokens.
final
tokenCount → int
Number of tokens.
final
tokens → Iterable<HighlightToken>
All tokens, in order.
no setter

Methods

forEachSegment(int line, void segment(int start, int end, int stack)) → void
Calls segment for each piece of line line, in order, with the piece's offsets and scope stack. Pieces never include the line break.
lineEnd(int line) → int
End offset of line line, excluding its \n or \r\n.
lineStart(int line) → int
Start offset of line line.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toHtml([HtmlRenderer renderer = const HtmlRenderer()]) → String
Renders the result as HTML. See HtmlRenderer for options.
tokenAt(int offset) → int
Index of the token covering offset, or tokenCount if offset is at or past the end.
tokenEnd(int index) → int
End offset (exclusive) of token index.
tokenStack(int index) → int
Scope stack id of token index. See scopes.
tokenStart(int index) → int
Start offset of token index.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited