public interface RestartableLexer
This interface is suitable for providing even distribution for restartable states in highlighting lexer implementation.
Perfect highlighting lexer should be able to restart quickly from any context.
Sometimes it's not enough to have only one restartable state in lexer logic.
Implement
isRestartableState(int) to provide several restartable states.
In some cases some additional information is needed to restart from non-trivial state.
start(CharSequence, int, int, int, TokenIterator) implementation helps quickly retrieve information from preceding part of the file
to restore lexer properly.
com.intellij.openapi.editor.ex.util.LexerEditorHighlighter#documentChanged(com.intellij.openapi.editor.event.DocumentEvent)-
Method Summary
Modifier and TypeMethodDescriptionintReturns the start state of the lexer.booleanisRestartableState(int state) Specifies which states are restartable.voidstart(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState, TokenIterator tokenIterator) Extended form ofLexer.start(CharSequence, int, int, int)which provides an Iterable based oncom.intellij.openapi.editor.ex.util.LexerEditorHighlighter#mySegments.
-
Method Details
-
getStartState
int getStartState()Returns the start state of the lexer.- Returns:
- the lexer state.
-
isRestartableState
@Experimental boolean isRestartableState(int state) Specifies which states are restartable.- Parameters:
state- lexer state to check- Returns:
trueif state is restartable,falseotherwise.
-
start
@Experimental void start(@NotNull @NotNull CharSequence buffer, int startOffset, int endOffset, int initialState, TokenIterator tokenIterator) Extended form ofLexer.start(CharSequence, int, int, int)which provides an Iterable based oncom.intellij.openapi.editor.ex.util.LexerEditorHighlighter#mySegments. Iteration starts from current token and goes in reverse order. This iterable can be used for getting some additional data needed for context dependent restart.- Parameters:
buffer- character data for lexingstartOffset- offset to start lexing fromendOffset- offset to stop lexing atinitialState- state to start lexing withtokenIterator- iterator for getting info from preceding tokens
-