Top Description Fields Methods
org.antlr.v4.runtime

public Interface Token

Known Direct Subinterfaces
org.antlr.v4.runtime.WritableToken
Known Direct Implementers
org.antlr.v4.runtime.tree.pattern.RuleTagToken

A token has properties: text, type, line, character position in the line (so we can ignore tabs), token channel, index, and source from which we obtained this token.

Field Summary

Modifier and TypeField and Description
public static final int
DEFAULT_CHANNEL

All tokens go to the parser (unless skip() is called in that rule) on a particular "channel".

public static final int
public static final int
EPSILON

During lookahead operations, this "token" signifies we hit rule end ATN state and did not follow it despite needing to.

public static final int
HIDDEN_CHANNEL

Anything on different channel than DEFAULT_CHANNEL is not parsed by parser.

public static final int
public static final int
MIN_USER_CHANNEL_VALUE

This is the minimum constant value which can be assigned to a user-defined token channel.

public static final int

Method Summary

Modifier and TypeMethod and Description
public int
getChannel()

Return the channel this token.

public int
getCharPositionInLine()

The index of the first character of this token relative to the beginning of the line at which it occurs, 0..n-1

public CharStream
getInputStream()

Gets the CharStream from which this token was derived.

public int
getLine()

The line number on which the 1st character of this token was matched, line=1..n

public int
getStartIndex()

The starting character index of the token This method is optional; return -1 if not implemented.

public int
getStopIndex()

The last character index of the token.

public String
getText()

Get the text of the token.

public int
getTokenIndex()

An index from 0..n-1 of the token object in the input stream.

public TokenSource
getTokenSource()

Gets the TokenSource which created this token.

public int
getType()

Get the token type of the token

Field Detail

DEFAULT_CHANNELback to summary
public static final int DEFAULT_CHANNEL

All tokens go to the parser (unless skip() is called in that rule) on a particular "channel". The parser tunes to a particular channel so that whitespace etc... can go to the parser on a "hidden" channel.

EOFback to summary
public static final int EOF
EPSILONback to summary
public static final int EPSILON

During lookahead operations, this "token" signifies we hit rule end ATN state and did not follow it despite needing to.

HIDDEN_CHANNELback to summary
public static final int HIDDEN_CHANNEL

Anything on different channel than DEFAULT_CHANNEL is not parsed by parser.

INVALID_TYPEback to summary
public static final int INVALID_TYPE
MIN_USER_CHANNEL_VALUEback to summary
public static final int MIN_USER_CHANNEL_VALUE

This is the minimum constant value which can be assigned to a user-defined token channel.

The non-negative numbers less than MIN_USER_CHANNEL_VALUE are assigned to the predefined channels DEFAULT_CHANNEL and HIDDEN_CHANNEL.

See Also
Token#getChannel()
MIN_USER_TOKEN_TYPEback to summary
public static final int MIN_USER_TOKEN_TYPE

Method Detail

getChannelback to summary
public int getChannel()

Return the channel this token. Each token can arrive at the parser on a different channel, but the parser only "tunes" to a single channel. The parser ignores everything not on DEFAULT_CHANNEL.

getCharPositionInLineback to summary
public int getCharPositionInLine()

The index of the first character of this token relative to the beginning of the line at which it occurs, 0..n-1

getInputStreamback to summary
public CharStream getInputStream()

Gets the CharStream from which this token was derived.

getLineback to summary
public int getLine()

The line number on which the 1st character of this token was matched, line=1..n

getStartIndexback to summary
public int getStartIndex()

The starting character index of the token This method is optional; return -1 if not implemented.

getStopIndexback to summary
public int getStopIndex()

The last character index of the token. This method is optional; return -1 if not implemented.

getTextback to summary
public String getText()

Get the text of the token.

getTokenIndexback to summary
public int getTokenIndex()

An index from 0..n-1 of the token object in the input stream. This must be valid in order to print token streams and use TokenRewriteStream. Return -1 to indicate that this token was conjured up since it doesn't have a valid index.

getTokenSourceback to summary
public TokenSource getTokenSource()

Gets the TokenSource which created this token.

getTypeback to summary
public int getType()

Get the token type of the token