Interface RestartableLexer


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 Type
    Method
    Description
    int
    Returns the start state of the lexer.
    boolean
    isRestartableState(int state)
    Specifies which states are restartable.
    void
    start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState, TokenIterator tokenIterator)
    Extended form of Lexer.start(CharSequence, int, int, int) which provides an Iterable based on com.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:
      true if state is restartable, false otherwise.
    • start

      @Experimental void start(@NotNull @NotNull CharSequence buffer, int startOffset, int endOffset, int initialState, TokenIterator tokenIterator)
      Extended form of Lexer.start(CharSequence, int, int, int) which provides an Iterable based on com.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 lexing
      startOffset - offset to start lexing from
      endOffset - offset to stop lexing at
      initialState - state to start lexing with
      tokenIterator - iterator for getting info from preceding tokens