Top Description Methods
org.codehaus.janino

public Interface TokenStream

Known Direct Implementers
org.codehaus.janino.TokenStreamImpl
Imports
java.io.IOException, org.codehaus.commons.compiler.CompileException, .Location, .WarningHandler, org.codehaus.commons.nullanalysis.Nullable

An interface that allows for peeking and consuming a stream of Tokens.

Method Summary

Modifier and TypeMethod and Description
public Location

Returns:

The location of the first character of the previously read (not peeked!) token
location
()

public Token

Returns:

The next token, but does not consume it
peek
()

public boolean

Returns:

Whether the value of the next token equals suspected; does not consume the next token
peek
(String suspected)

public int

Returns:

The index of the first of the suspected that equals the value of the next token, or -1 if the value of the next token equals none of the suspected
peek
(String... suspected)

Checks whether the value of the next token equals any of the suspected; does not consume the next token.

public boolean

Returns:

Whether the type of the next token is suspected
peek
(TokenType suspected)

public int

Returns:

The index of the first of the suspected types that is the next token's type, or -1 if the type of the next token is none of the suspected types
peek
(TokenType... suspected)

Checks whether the type of the next token is any of the suspected; does not consume the next token.

public Token

Returns:

The next-but-one token, but consumes neither the next nor the next-but-one token
peekNextButOne
()

public boolean

Returns:

Whether the value of the next-but-one token equals the suspected; consumes neither the next nor the next-but-one token
peekNextButOne
(String suspected)

public boolean
peekRead(String suspected)

Checks whether the value of the next token equals the suspected; if so, consumes the token.

public int

Returns:

The index of the first of the suspected that equals the next token's value; -1 iff the next token's value equals none of the suspected
peekRead
(String... suspected)

Checks whether the value of the next token is one of the suspected; if so, consumes the token.

public String

Returns:

The value of the next token; an interned String iff the token represents an identifier, true, false, null, or an operator
peekRead
(TokenType suspected)

Checks whether the type of the next token is the suspected; if so, consumes the token.

public int

Returns:

The index of the elements that is the next token's type, or -1 iff the type of next token is none of the suspected
peekRead
(TokenType... suspected)

Checks whether the type of the next token is one of the suspected; if so, consumes the token.

public Token

Returns:

The next token, which it also consumes, or null iff the scanner is at end-of-input
read
()

public void
read(String expected)

Verifies that the value of the next token equals expected, and consumes the token.

public int

Returns:

The index of the consumed token within expected
read
(String... expected)

Verifies that the value of the next token equals one of the expected, and consumes the token.

public String

Returns:

The value of the next token; an interned String iff the token represents an identifier, true, false, null, or an operator
read
(TokenType expected)

Verifies that the type of the next token is the expected, and consumes the token.

public int

Returns:

The index of the first of the expected types that is the next token's type; -1 if the type of the next token is none of the expected
read
(TokenType... expected)

Verifies that the type of the next token is one of the expected, and consumes the token.

public void
setWarningHandler(WarningHandler
null to indicate that no warnings be issued
warningHandler
)

By default, warnings are discarded, but an application my install a WarningHandler.

Method Detail

locationback to summary
public Location location()
Returns:Location

The location of the first character of the previously read (not peeked!) token

peekback to summary
public Token peek() throws CompileException, IOException
Returns:Token

The next token, but does not consume it

peekback to summary
public boolean peek(String suspected) throws CompileException, IOException
Returns:boolean

Whether the value of the next token equals suspected; does not consume the next token

peekback to summary
public int peek(String... suspected) throws CompileException, IOException

Checks whether the value of the next token equals any of the suspected; does not consume the next token.

Returns:int

The index of the first of the suspected that equals the value of the next token, or -1 if the value of the next token equals none of the suspected

peekback to summary
public boolean peek(TokenType suspected) throws CompileException, IOException
Returns:boolean

Whether the type of the next token is suspected

peekback to summary
public int peek(TokenType... suspected) throws CompileException, IOException

Checks whether the type of the next token is any of the suspected; does not consume the next token.

Returns:int

The index of the first of the suspected types that is the next token's type, or -1 if the type of the next token is none of the suspected types

peekNextButOneback to summary
public Token peekNextButOne() throws CompileException, IOException
Returns:Token

The next-but-one token, but consumes neither the next nor the next-but-one token

peekNextButOneback to summary
public boolean peekNextButOne(String suspected) throws CompileException, IOException
Returns:boolean

Whether the value of the next-but-one token equals the suspected; consumes neither the next nor the next-but-one token

peekReadback to summary
public boolean peekRead(String suspected) throws CompileException, IOException

Checks whether the value of the next token equals the suspected; if so, consumes the token.

peekReadback to summary
public int peekRead(String... suspected) throws CompileException, IOException

Checks whether the value of the next token is one of the suspected; if so, consumes the token.

Returns:int

The index of the first of the suspected that equals the next token's value; -1 iff the next token's value equals none of the suspected

peekReadback to summary
public String peekRead(TokenType suspected) throws CompileException, IOException

Checks whether the type of the next token is the suspected; if so, consumes the token.

Returns:String

The value of the next token; an interned String iff the token represents an identifier, true, false, null, or an operator

Annotations
@Nullable
peekReadback to summary
public int peekRead(TokenType... suspected) throws CompileException, IOException

Checks whether the type of the next token is one of the suspected; if so, consumes the token.

Returns:int

The index of the elements that is the next token's type, or -1 iff the type of next token is none of the suspected

readback to summary
public Token read() throws CompileException, IOException
Returns:Token

The next token, which it also consumes, or null iff the scanner is at end-of-input

readback to summary
public void read(String expected) throws CompileException, IOException

Verifies that the value of the next token equals expected, and consumes the token.

Exceptions
CompileException:
The value of the next token does not equal expected (this includes the case that the scanner is at end-of-input)
readback to summary
public int read(String... expected) throws CompileException, IOException

Verifies that the value of the next token equals one of the expected, and consumes the token.

Returns:int

The index of the consumed token within expected

Exceptions
CompileException:
The value of the next token does not equal any of the expected (this includes the case where the scanner is at end-of-input)
readback to summary
public String read(TokenType expected) throws CompileException, IOException

Verifies that the type of the next token is the expected, and consumes the token.

Returns:String

The value of the next token; an interned String iff the token represents an identifier, true, false, null, or an operator

Exceptions
CompileException:
The next token's type is not the expected
readback to summary
public int read(TokenType... expected) throws CompileException, IOException

Verifies that the type of the next token is one of the expected, and consumes the token.

Returns:int

The index of the first of the expected types that is the next token's type; -1 if the type of the next token is none of the expected

Exceptions
CompileException:
The next token's type is none of the expected
setWarningHandlerback to summary
public void setWarningHandler(WarningHandler warningHandler)

By default, warnings are discarded, but an application my install a WarningHandler.

Notice that there is no Parser.setErrorHandler() method, but parse errors always throw a CompileException. The reason being is that there is no reasonable way to recover from parse errors and continue parsing, so there is no need to install a custom parse error handler.

Parameters
warningHandler:WarningHandler

null to indicate that no warnings be issued