- All Known Subinterfaces:
LexerBase
- All Known Implementing Classes:
DelegateLexer,FlexAdapter,LayeredLexer,LookAheadLexer,MergingLexerAdapter,MergingLexerAdapterBase,StringLiteralLexer
public interface Lexer
Interface for breaking a file into a sequence of tokens.
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidadvance()Advances the lexer to the next token.intReturns the offset at which the lexer will stop lexing.@NotNull CharSequenceReturns the buffer sequence over which the lexer is running.@NotNull LexerPositionReturns the current position and state of the lexer.intgetState()Returns the current state of the lexer.intReturns the end offset of the current token.default @NotNull CharSequenceintReturns the start offset of the current token.default @NotNull String@Nullable IElementTypeReturns the token at the current position of the lexer ornullif lexing is finished.voidrestore(@NotNull LexerPosition position) Restores the lexer to the specified state and position.default voidstart(@NotNull CharSequence buf) default voidstart(@NotNull CharSequence buf, int start, int end) voidstart(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) Prepare for lexing character data frombufferpassed.
-
Field Details
-
LEXER_START_THRESHOLD
static final long LEXER_START_THRESHOLD- See Also:
-
-
Method Details
-
start
Prepare for lexing character data frombufferpassed. Internal lexer state is supposed to beinitialState. It is guaranteed that the value of initialState is the same as returned bygetState()method of this lexer at conditionstartOffset=getTokenStart(). This method is used to incrementally re-lex changed characters using lexing data acquired from this particular lexer sometime in the past.- Parameters:
buffer- character data for lexing.startOffset- offset to start lexing fromendOffset- offset to stop lexing atinitialState- the initial state of the lexer.
-
start
-
start
-
getTokenSequence
-
getTokenText
-
getState
int getState()Returns the current state of the lexer.- Returns:
- the lexer state.
-
getTokenType
Returns the token at the current position of the lexer ornullif lexing is finished.- Returns:
- the current token.
-
getTokenStart
int getTokenStart()Returns the start offset of the current token.- Returns:
- the current token start offset.
-
getTokenEnd
int getTokenEnd()Returns the end offset of the current token.- Returns:
- the current token end offset.
-
advance
void advance()Advances the lexer to the next token. -
getCurrentPosition
Returns the current position and state of the lexer.- Returns:
- the lexer position and state.
-
restore
Restores the lexer to the specified state and position.- Parameters:
position- the state and position to restore to.
-
getBufferSequence
Returns the buffer sequence over which the lexer is running. This method should return the same buffer instance which was passed to thestart()method.- Returns:
- the lexer buffer.
-
getBufferEnd
int getBufferEnd()Returns the offset at which the lexer will stop lexing. This method should return the length of the buffer or the value passed in theendOffsetparameter to thestart()method.- Returns:
- the lexing end offset
-