Package org.codehaus.janino
Interface TokenStream
-
- All Known Implementing Classes:
TokenStreamImpl
public interface TokenStreamAn interface that allows for peeking and consuming a stream ofTokens.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Locationlocation()Tokenpeek()booleanpeek(java.lang.String suspected)intpeek(java.lang.String... suspected)Checks whether the value of the next token equals any of the suspected; does not consume the next token.booleanpeek(TokenType suspected)intpeek(TokenType... suspected)Checks whether the type of the next token is any of the suspected; does not consume the next token.TokenpeekNextButOne()booleanpeekNextButOne(java.lang.String suspected)booleanpeekRead(java.lang.String suspected)Checks whether the value of the next token equals the suspected; if so, consumes the token.intpeekRead(java.lang.String... suspected)Checks whether the value of the next token is one of the suspected; if so, consumes the token.java.lang.StringpeekRead(TokenType suspected)Checks whether the type of the next token is the suspected; if so, consumes the token.intpeekRead(TokenType... suspected)Checks whether the type of the next token is one of the suspected; if so, consumes the token.Tokenread()voidread(java.lang.String expected)Verifies that the value of the next token equals expected, and consumes the token.intread(java.lang.String... expected)Verifies that the value of the next token equals one of the expected, and consumes the token.java.lang.Stringread(TokenType expected)Verifies that the type of the next token is the expected, and consumes the token.intread(TokenType... expected)Verifies that the type of the next token is one of the expected, and consumes the token.voidsetWarningHandler(WarningHandler warningHandler)By default, warnings are discarded, but an application my install aWarningHandler.
-
-
-
Method Detail
-
peek
Token peek() throws CompileException, java.io.IOException
- Returns:
- The next token, but does not consume it
- Throws:
CompileExceptionjava.io.IOException
-
peek
boolean peek(java.lang.String suspected) throws CompileException, java.io.IOException- Returns:
- Whether the value of the next token equals suspected; does not consume the next token
- Throws:
CompileExceptionjava.io.IOException
-
peek
int peek(java.lang.String... suspected) throws CompileException, java.io.IOException
Checks whether the value of the next token equals any of the suspected; does not consume the next token.- 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
- Throws:
CompileExceptionjava.io.IOException
-
peek
boolean peek(TokenType suspected) throws CompileException, java.io.IOException
- Returns:
- Whether the type of the next token is suspected
- Throws:
CompileExceptionjava.io.IOException
-
peek
int peek(TokenType... suspected) throws CompileException, java.io.IOException
Checks whether the type of the next token is any of the suspected; does not consume the next token.- 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
- Throws:
CompileExceptionjava.io.IOException
-
peekNextButOne
Token peekNextButOne() throws CompileException, java.io.IOException
- Returns:
- The next-but-one token, but consumes neither the next nor the next-but-one token
- Throws:
CompileExceptionjava.io.IOException
-
peekNextButOne
boolean peekNextButOne(java.lang.String suspected) throws CompileException, java.io.IOException- Returns:
- Whether the value of the next-but-one token equals the suspected; consumes neither the next nor the next-but-one token
- Throws:
CompileExceptionjava.io.IOException
-
read
Token read() throws CompileException, java.io.IOException
- Returns:
- The next token, which it also consumes, or
nulliff the scanner is at end-of-input - Throws:
CompileExceptionjava.io.IOException
-
read
void read(java.lang.String expected) throws CompileException, java.io.IOException
Verifies that the value of the next token equals expected, and consumes the token.- Throws:
CompileException- The value of the next token does not equal expected (this includes the case that the scanner is at end-of-input)java.io.IOException
-
read
int read(java.lang.String... expected) throws CompileException, java.io.IOException
Verifies that the value of the next token equals one of the expected, and consumes the token.- Returns:
- The index of the consumed token within expected
- Throws:
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)java.io.IOException
-
read
java.lang.String read(TokenType expected) throws CompileException, java.io.IOException
Verifies that the type of the next token is the expected, and consumes the token.- Returns:
- The value of the next token; an
internedString iff the token represents an identifier,true,false,null, or an operator - Throws:
CompileException- The next token's type is not the expectedjava.io.IOException
-
read
int read(TokenType... expected) throws CompileException, java.io.IOException
Verifies that the type of the next token is one of the expected, and consumes the token.- 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
- Throws:
CompileException- The next token's type is none of the expectedjava.io.IOException
-
peekRead
boolean peekRead(java.lang.String suspected) throws CompileException, java.io.IOExceptionChecks whether the value of the next token equals the suspected; if so, consumes the token.- Throws:
CompileExceptionjava.io.IOException
-
peekRead
int peekRead(java.lang.String... suspected) throws CompileException, java.io.IOExceptionChecks whether the value of the next token is one of the suspected; if so, consumes the token.- 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
- Throws:
CompileExceptionjava.io.IOException
-
peekRead
@Nullable java.lang.String peekRead(TokenType suspected) throws CompileException, java.io.IOException
Checks whether the type of the next token is the suspected; if so, consumes the token.- Returns:
- The value of the next token; an
internedString iff the token represents an identifier,true,false,null, or an operator - Throws:
CompileExceptionjava.io.IOException
-
peekRead
int peekRead(TokenType... suspected) throws CompileException, java.io.IOException
Checks whether the type of the next token is one of the suspected; if so, consumes the token.- 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
- Throws:
CompileExceptionjava.io.IOException
-
setWarningHandler
void setWarningHandler(@Nullable WarningHandler warningHandler)
By default, warnings are discarded, but an application my install aWarningHandler.Notice that there is no
Parser.setErrorHandler()method, but parse errors always throw aCompileException. 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-nullto indicate that no warnings be issued
-
location
Location location()
- Returns:
- The location of the first character of the previously read (not peeked!) token
-
-