public class CommonTokenFactory extends java.lang.Object implements TokenFactory<CommonToken>
TokenFactory creates
CommonToken objects.| Modifier and Type | Field and Description |
|---|---|
protected boolean |
copyText
Indicates whether
CommonToken.setText(java.lang.String) should be called after
constructing tokens to explicitly set the text. |
static TokenFactory<CommonToken> |
DEFAULT
The default
CommonTokenFactory instance. |
| Constructor and Description |
|---|
CommonTokenFactory()
|
CommonTokenFactory(boolean copyText)
Constructs a
CommonTokenFactory with the specified value for
copyText. |
| Modifier and Type | Method and Description |
|---|---|
CommonToken |
create(int type,
java.lang.String text)
Generically useful
|
CommonToken |
create(Pair<TokenSource,CharStream> source,
int type,
java.lang.String text,
int channel,
int start,
int stop,
int line,
int charPositionInLine)
This is the method used to create tokens in the lexer and in the
error handling strategy.
|
public static final TokenFactory<CommonToken> DEFAULT
CommonTokenFactory instance.
This token factory does not explicitly copy token text when constructing tokens.
protected final boolean copyText
CommonToken.setText(java.lang.String) should be called after
constructing tokens to explicitly set the text. This is useful for cases
where the input stream might not be able to provide arbitrary substrings
of text from the input after the lexer creates a token (e.g. the
implementation of CharStream.getText(org.antlr.v4.runtime.misc.Interval) in
UnbufferedCharStream throws an
UnsupportedOperationException). Explicitly setting the token text
allows Token.getText() to be called at any time regardless of the
input stream implementation.
The default value is false to avoid the performance and memory
overhead of copying text for every token unless explicitly requested.
public CommonTokenFactory(boolean copyText)
CommonTokenFactory with the specified value for
copyText.
When copyText is false, the DEFAULT instance
should be used instead of constructing a new instance.
copyText - The value for copyText.public CommonTokenFactory()
CommonTokenFactory with copyText set to
false.
The DEFAULT instance should be used instead of calling this
directly.
public CommonToken create(Pair<TokenSource,CharStream> source, int type, java.lang.String text, int channel, int start, int stop, int line, int charPositionInLine)
TokenFactorycreate in interface TokenFactory<CommonToken>public CommonToken create(int type, java.lang.String text)
TokenFactorycreate in interface TokenFactory<CommonToken>