Top Description Fields Constructors Methods
org.antlr.v4.runtime

public Class ListTokenSource

extends Object
implements TokenSource
Class Inheritance
All Implemented Interfaces
org.antlr.v4.runtime.TokenSource
Imports
org.antlr.v4.runtime.misc.NotNull, .Tuple, java.util.List

Provides an implementation of TokenSource as a wrapper around a list of Token objects.

If the final token in the list is an Token#EOF token, it will be used as the EOF token for every call to nextToken after the end of the list is reached. Otherwise, an EOF token will be created.

Field Summary

Modifier and TypeField and Description
private TokenFactory
_factory

This is the backing field for getTokenFactory and setTokenFactory.

protected Token
eofToken

This field caches the EOF token for the token source.

protected int
i

The index into tokens of token to return by the next call to nextToken.

private final String
sourceName

The name of the input source.

protected final List<? extends Token>
tokens

The wrapped collection of Token objects to return.

Constructor Summary

AccessConstructor and Description
public
ListTokenSource(List<? extends Token>
The collection of Token objects to provide as a TokenSource.
tokens
)

Constructs a new ListTokenSource instance from the specified collection of Token objects.

public
ListTokenSource(List<? extends Token>
The collection of Token objects to provide as a TokenSource.
tokens
,
String
The name of the TokenSource. If this value is null, getSourceName will attempt to infer the name from the next Token (or the previous token if the end of the input has been reached).
sourceName
)

Constructs a new ListTokenSource instance from the specified collection of Token objects and source name.

Method Summary

Modifier and TypeMethod and Description
public int
getCharPositionInLine()

Implements org.antlr.v4.runtime.TokenSource.getCharPositionInLine.

Get the index into the current line for the current position in the input stream.
public CharStream
getInputStream()

Implements org.antlr.v4.runtime.TokenSource.getInputStream.

Get the CharStream from which this token source is currently providing tokens.
public int
getLine()

Implements org.antlr.v4.runtime.TokenSource.getLine.

Get the line number for the current position in the input stream.
public String
getSourceName()

Implements org.antlr.v4.runtime.TokenSource.getSourceName.

Gets the name of the underlying input source.
public TokenFactory
getTokenFactory()

Implements org.antlr.v4.runtime.TokenSource.getTokenFactory.

Gets the TokenFactory this token source is currently using for creating Token objects from the input.
public Token
nextToken()

Implements org.antlr.v4.runtime.TokenSource.nextToken.

Return a Token object from your input stream (usually a CharStream).
public void
setTokenFactory(TokenFactory
The TokenFactory to use for creating tokens.
factory
)

Implements org.antlr.v4.runtime.TokenSource.setTokenFactory.

Set the TokenFactory this token source should use for creating Token objects from the input.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_factoryback to summary
private TokenFactory _factory

This is the backing field for getTokenFactory and setTokenFactory.

eofTokenback to summary
protected Token eofToken

This field caches the EOF token for the token source.

iback to summary
protected int i

The index into tokens of token to return by the next call to nextToken. The end of the input is indicated by this value being greater than or equal to the number of items in tokens.

sourceNameback to summary
private final String sourceName

The name of the input source. If this value is null, a call to getSourceName should return the source name used to create the the next token in tokens (or the previous token if the end of the input has been reached).

tokensback to summary
protected final List<? extends Token> tokens

The wrapped collection of Token objects to return.

Constructor Detail

ListTokenSourceback to summary
public ListTokenSource(List<? extends Token> tokens)

Constructs a new ListTokenSource instance from the specified collection of Token objects.

Parameters
tokens:List<? extends Token>

The collection of Token objects to provide as a TokenSource.

Exceptions
NullPointerException:
if tokens is null
ListTokenSourceback to summary
public ListTokenSource(List<? extends Token> tokens, String sourceName)

Constructs a new ListTokenSource instance from the specified collection of Token objects and source name.

Parameters
tokens:List<? extends Token>

The collection of Token objects to provide as a TokenSource.

sourceName:String

The name of the TokenSource. If this value is null, getSourceName will attempt to infer the name from the next Token (or the previous token if the end of the input has been reached).

Exceptions
NullPointerException:
if tokens is null

Method Detail

getCharPositionInLineback to summary
public int getCharPositionInLine()

Implements org.antlr.v4.runtime.TokenSource.getCharPositionInLine.

Doc from org.antlr.v4.runtime.TokenSource.getCharPositionInLine.

Get the index into the current line for the current position in the input stream. The first character on a line has position 0.

Returns:int

The line number for the current position in the input stream, or -1 if the current token source does not track character positions.

Annotations
@Override
getInputStreamback to summary
public CharStream getInputStream()

Implements org.antlr.v4.runtime.TokenSource.getInputStream.

Doc from org.antlr.v4.runtime.TokenSource.getInputStream.

Get the CharStream from which this token source is currently providing tokens.

Returns:CharStream

The CharStream associated with the current position in the input, or null if no input stream is available for the token source.

Annotations
@Override
getLineback to summary
public int getLine()

Implements org.antlr.v4.runtime.TokenSource.getLine.

Doc from org.antlr.v4.runtime.TokenSource.getLine.

Get the line number for the current position in the input stream. The first line in the input is line 1.

Returns:int

The line number for the current position in the input stream, or 0 if the current token source does not track line numbers.

Annotations
@Override
getSourceNameback to summary
public String getSourceName()

Implements org.antlr.v4.runtime.TokenSource.getSourceName.

Doc from org.antlr.v4.runtime.TokenSource.getSourceName.

Gets the name of the underlying input source. This method returns a non-null, non-empty string. If such a name is not known, this method returns IntStream#UNKNOWN_SOURCE_NAME.

Annotations
@Override
getTokenFactoryback to summary
public TokenFactory getTokenFactory()

Implements org.antlr.v4.runtime.TokenSource.getTokenFactory.

Doc from org.antlr.v4.runtime.TokenSource.getTokenFactory.

Gets the TokenFactory this token source is currently using for creating Token objects from the input.

Returns:TokenFactory

The TokenFactory currently used by this token source.

Annotations
@Override
@NotNull
nextTokenback to summary
public Token nextToken()

Implements org.antlr.v4.runtime.TokenSource.nextToken.

Doc from org.antlr.v4.runtime.TokenSource.nextToken.

Return a Token object from your input stream (usually a CharStream). Do not fail/return upon lexing error; keep chewing on the characters until you get a good one; errors are not passed through to the parser.

Annotations
@Override
setTokenFactoryback to summary
public void setTokenFactory(TokenFactory factory)

Implements org.antlr.v4.runtime.TokenSource.setTokenFactory.

Doc from org.antlr.v4.runtime.TokenSource.setTokenFactory.

Set the TokenFactory this token source should use for creating Token objects from the input.

Parameters
factory:TokenFactory

The TokenFactory to use for creating tokens.

Annotations
@Override