public abstract class Lexer extends Recognizer<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 |
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() |
List<? extends Token> |
getAllTokens()
Return a list of all Token objects in input char stream.
|
int |
getChannel() |
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.
|
String |
getErrorDisplay(int c) |
String |
getErrorDisplay(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.
|
String[] |
getModeNames() |
String |
getSourceName()
Gets the name of the underlying input source.
|
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. |
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(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, setState
public 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 String _text
public Lexer()
public Lexer(CharStream input)
public void reset()
public Token nextToken()
nextToken
in interface TokenSource
public void skip()
public void more()
public void mode(int m)
public void pushMode(int m)
public int popMode()
public void setTokenFactory(TokenFactory<?> factory)
TokenSource
TokenFactory
this token source should use for creating
Token
objects from the input.setTokenFactory
in interface TokenSource
setTokenFactory
in class Recognizer<Integer,LexerATNSimulator>
factory
- The TokenFactory
to use for creating tokens.public TokenFactory<? extends Token> getTokenFactory()
TokenSource
TokenFactory
this token source is currently using for
creating Token
objects from the input.getTokenFactory
in interface TokenSource
getTokenFactory
in class Recognizer<Integer,LexerATNSimulator>
TokenFactory
currently used by this token source.public void setInputStream(IntStream input)
setInputStream
in class Recognizer<Integer,LexerATNSimulator>
public String getSourceName()
TokenSource
IntStream.UNKNOWN_SOURCE_NAME
.getSourceName
in interface TokenSource
public CharStream getInputStream()
TokenSource
CharStream
from which this token source is currently
providing tokens.getInputStream
in interface TokenSource
getInputStream
in class Recognizer<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()
TokenSource
getLine
in interface TokenSource
public int getCharPositionInLine()
TokenSource
getCharPositionInLine
in interface TokenSource
public void setLine(int line)
public void setCharPositionInLine(int charPositionInLine)
public int getCharIndex()
public String getText()
public void setText(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 String[] getModeNames()
@Deprecated public String[] getTokenNames()
getTokenNames
in class Recognizer<Integer,LexerATNSimulator>
public List<? extends Token> getAllTokens()
public void recover(LexerNoViableAltException e)
public void notifyListeners(LexerNoViableAltException e)
public String getErrorDisplay(int c)
public String getCharErrorDisplay(int c)
public void recover(RecognitionException re)
Copyright © 1992-2015 ANTLR. All Rights Reserved.