public abstract class Lexer extends Recognizer<java.lang.Integer,LexerATNSimulator> implements TokenSource
| Modifier and Type | Field and Description |
|---|---|
int |
_channel
The channel number for the current token
|
protected TokenFactory<?> |
_factory
How to create token objects
|
boolean |
_hitEOF
Once we see EOF on char stream, next token will be EOF.
|
CharStream |
_input |
int |
_mode |
IntegerStack |
_modeStack |
java.lang.String |
_text
You can set the text for the current token to override what is in
the input char buffer.
|
Token |
_token
The goal of all lexer rules/methods is to create a token object.
|
protected Pair<TokenSource,CharStream> |
_tokenFactorySourcePair |
int |
_tokenStartCharIndex
What character index in the stream did the current token start at?
Needed, for example, to get the text for current token.
|
int |
_tokenStartCharPositionInLine
The character position of first character within the line
|
int |
_tokenStartLine
The line on which the first character of the token resides
|
int |
_type
The token type for the current token
|
static int |
DEFAULT_MODE |
static int |
DEFAULT_TOKEN_CHANNEL |
static int |
HIDDEN |
static int |
MAX_CHAR_VALUE |
static int |
MIN_CHAR_VALUE |
static int |
MORE |
static int |
SKIP |
_interp, EOF| Constructor and Description |
|---|
Lexer() |
Lexer(CharStream input) |
| Modifier and Type | Method and Description |
|---|---|
Token |
emit()
The standard method called to automatically emit a token at the
outermost lexical rule.
|
void |
emit(Token token)
By default does not support multiple emits per nextToken invocation
for efficiency reasons.
|
Token |
emitEOF() |
java.util.List<? extends Token> |
getAllTokens()
Return a list of all Token objects in input char stream.
|
int |
getChannel() |
java.lang.String |
getCharErrorDisplay(int c) |
int |
getCharIndex()
What is the index of the current character of lookahead?
|
int |
getCharPositionInLine()
Get the index into the current line for the current position in the input
stream.
|
java.lang.String |
getErrorDisplay(int c) |
java.lang.String |
getErrorDisplay(java.lang.String s) |
CharStream |
getInputStream()
Get the
CharStream from which this token source is currently
providing tokens. |
int |
getLine()
Get the line number for the current position in the input stream.
|
java.lang.String[] |
getModeNames() |
java.lang.String |
getSourceName()
Gets the name of the underlying input source.
|
java.lang.String |
getText()
Return the text matched so far for the current token or any
text override.
|
Token |
getToken()
Override if emitting multiple tokens.
|
TokenFactory<? extends Token> |
getTokenFactory()
Gets the
TokenFactory this token source is currently using for
creating Token objects from the input. |
java.lang.String[] |
getTokenNames()
Deprecated.
|
int |
getType() |
void |
mode(int m) |
void |
more() |
Token |
nextToken()
Return a token from this source; i.e., match a token on the char
stream.
|
void |
notifyListeners(LexerNoViableAltException e) |
int |
popMode() |
void |
pushMode(int m) |
void |
recover(LexerNoViableAltException e) |
void |
recover(RecognitionException re)
Lexers can normally match any char in it's vocabulary after matching
a token, so do the easy thing and just kill a character and hope
it all works out.
|
void |
reset() |
void |
setChannel(int channel) |
void |
setCharPositionInLine(int charPositionInLine) |
void |
setInputStream(IntStream input)
Set the char stream and reset the lexer
|
void |
setLine(int line) |
void |
setText(java.lang.String text)
Set the complete text of this token; it wipes any previous
changes to the text.
|
void |
setToken(Token _token) |
void |
setTokenFactory(TokenFactory<?> factory)
Set the
TokenFactory this token source should use for creating
Token objects from the input. |
void |
setType(int ttype) |
void |
skip()
Instruct the lexer to skip creating a token for current lexer rule
and look for another token.
|
action, addErrorListener, getATN, getErrorHeader, getErrorListenerDispatch, getErrorListeners, getGrammarFileName, getInterpreter, getParseInfo, getRuleIndexMap, getRuleNames, getSerializedATN, getState, getTokenErrorDisplay, getTokenType, getTokenTypeMap, getVocabulary, precpred, removeErrorListener, removeErrorListeners, sempred, setInterpreter, setStatepublic static final int DEFAULT_MODE
public static final int MORE
public static final int SKIP
public static final int DEFAULT_TOKEN_CHANNEL
public static final int HIDDEN
public static final int MIN_CHAR_VALUE
public static final int MAX_CHAR_VALUE
public CharStream _input
protected Pair<TokenSource,CharStream> _tokenFactorySourcePair
protected TokenFactory<?> _factory
public Token _token
public int _tokenStartCharIndex
public int _tokenStartLine
public int _tokenStartCharPositionInLine
public boolean _hitEOF
public int _channel
public int _type
public final IntegerStack _modeStack
public int _mode
public java.lang.String _text
public Lexer()
public Lexer(CharStream input)
public void reset()
public Token nextToken()
nextToken in interface TokenSourcepublic void skip()
public void more()
public void mode(int m)
public void pushMode(int m)
public int popMode()
public void setTokenFactory(TokenFactory<?> factory)
TokenSourceTokenFactory this token source should use for creating
Token objects from the input.setTokenFactory in interface TokenSourcesetTokenFactory in class Recognizer<java.lang.Integer,LexerATNSimulator>factory - The TokenFactory to use for creating tokens.public TokenFactory<? extends Token> getTokenFactory()
TokenSourceTokenFactory this token source is currently using for
creating Token objects from the input.getTokenFactory in interface TokenSourcegetTokenFactory in class Recognizer<java.lang.Integer,LexerATNSimulator>TokenFactory currently used by this token source.public void setInputStream(IntStream input)
setInputStream in class Recognizer<java.lang.Integer,LexerATNSimulator>public java.lang.String getSourceName()
TokenSourceIntStream.UNKNOWN_SOURCE_NAME.getSourceName in interface TokenSourcepublic CharStream getInputStream()
TokenSourceCharStream from which this token source is currently
providing tokens.getInputStream in interface TokenSourcegetInputStream in class Recognizer<java.lang.Integer,LexerATNSimulator>CharStream associated with the current position in
the input, or null if no input stream is available for the token
source.public void emit(Token token)
public Token emit()
public Token emitEOF()
public int getLine()
TokenSourcegetLine in interface TokenSourcepublic int getCharPositionInLine()
TokenSourcegetCharPositionInLine in interface TokenSourcepublic void setLine(int line)
public void setCharPositionInLine(int charPositionInLine)
public int getCharIndex()
public java.lang.String getText()
public void setText(java.lang.String text)
public Token getToken()
public void setToken(Token _token)
public void setType(int ttype)
public int getType()
public void setChannel(int channel)
public int getChannel()
public java.lang.String[] getModeNames()
@Deprecated public java.lang.String[] getTokenNames()
getTokenNames in class Recognizer<java.lang.Integer,LexerATNSimulator>public java.util.List<? extends Token> getAllTokens()
public void recover(LexerNoViableAltException e)
public void notifyListeners(LexerNoViableAltException e)
public java.lang.String getErrorDisplay(java.lang.String s)
public java.lang.String getErrorDisplay(int c)
public java.lang.String getCharErrorDisplay(int c)
public void recover(RecognitionException re)