Represents a finite sequence of CivlcToken. Methods are provided to
access the sequence in a variety of convenient ways. Most importantly, method
newSource() returns a CivlcTokenSource, which can be used to
construct an ANTLR TokenStream, which can in turn be used as the
input to an ANTLR parser.
The tokens are never duplicated by any of these methods, so a modification to a token will be reflected in any subsequence method calls to access that token.
This sequence representation is best use for relatively short sequences, such as the tokens comprising a single pragma. It is not recommended for representing an entire translation unit.
This object will also include an addition "EOF" token. That token is not part
of the sequence, but it is used by method newSource(). That method
will in effect append an infinite sequence of EOF tokens to the end of the
sequence.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the extra EOF token which is used by methodnewSource().Returns the tokens as an array.Returns a newCivlcTokenSourcewhich produces the tokens in this sequence, in order, with an "EOF" token appended.intsize()Returns the number of tokens in the sequence.
-
Method Details
-
getEOFToken
CivlcToken getEOFToken()Returns the extra EOF token which is used by methodnewSource().- Returns:
- the extra EOF token
-
newSource
CivlcTokenSource newSource()Returns a new
CivlcTokenSourcewhich produces the tokens in this sequence, in order, with an "EOF" token appended. Since a token source is basically infinite, the final EOF token is stuttered, i.e., repeated calls toTokenSource.nextToken()will continue to produce the EOF token after the EOF token has been reached.This source may be used to construct a
TokenStreamand then used as the input to a parser.- Returns:
- a new
CivlcTokenSourceyielding the elements of this sequence.
-
getTokens
CivlcToken[] getTokens()Returns the tokens as an array. Whether or not this array can be modified depends on the implementation. The array does not include the extra "EOF" token. The length of this array is the same as the number returned bysize().- Returns:
- the tokens as an array
-
size
int size()Returns the number of tokens in the sequence. This number does not include the extra "EOF" token.- Returns:
- the number of tokens in the sequence
-