public class TokenStreamImpl extends Object implements TokenStream
TokenStream.| Constructor and Description |
|---|
TokenStreamImpl(Scanner scanner) |
| Modifier and Type | Method and Description |
|---|---|
protected CompileException |
compileException(String message)
Convenience method for throwing a
CompileException. |
String |
doc()
Gets the text of the doc comment (a.k.a.
|
Location |
location() |
Token |
peek() |
int |
peek(String... suspected)
Checks whether the value of the next token equals any of the suspected; does not consume the next
token.
|
boolean |
peek(String suspected) |
int |
peek(TokenType... suspected)
Checks whether the type of the next token is any of the suspected; does not consume the next token.
|
boolean |
peek(TokenType suspected) |
Token |
peekNextButOne() |
boolean |
peekNextButOne(String suspected) |
int |
peekRead(String... suspected)
Checks whether the value of the next token is one of the suspected; if so, consumes the token.
|
boolean |
peekRead(String suspected)
Checks whether the value of the next token equals the suspected; if so, consumes the token.
|
int |
peekRead(TokenType... suspected)
Checks whether the type of the next token is one of the suspected; if so, consumes the token.
|
String |
peekRead(TokenType suspected)
Checks whether the type of the next token is the suspected; if so, consumes the token.
|
Token |
read() |
int |
read(String... expected)
Verifies that the value of the next token equals one of the expected, and consumes the token.
|
void |
read(String expected)
Verifies that the value of the next token equals expected, and consumes the token.
|
int |
read(TokenType... expected)
Verifies that the type of the next token is one of the expected, and consumes the token.
|
String |
read(TokenType expected)
Verifies that the type of the next token is the expected, and consumes the token.
|
void |
setWarningHandler(WarningHandler optionalWarningHandler)
By default, warnings are discarded, but an application my install a
WarningHandler. |
String |
toString() |
public TokenStreamImpl(Scanner scanner)
@Nullable public String doc()
null if the next token is not preceded by a doc commentpublic Token peek() throws CompileException, IOException
peek in interface TokenStreamCompileExceptionIOExceptionpublic Token peekNextButOne() throws CompileException, IOException
peekNextButOne in interface TokenStreamCompileExceptionIOExceptionpublic boolean peek(String suspected) throws CompileException, IOException
peek in interface TokenStreamCompileExceptionIOExceptionpublic int peek(String... suspected) throws CompileException, IOException
TokenStreampeek in interface TokenStreamCompileExceptionIOExceptionpublic boolean peek(TokenType suspected) throws CompileException, IOException
peek in interface TokenStreamCompileExceptionIOExceptionpublic int peek(TokenType... suspected) throws CompileException, IOException
TokenStreampeek in interface TokenStreamCompileExceptionIOExceptionpublic boolean peekNextButOne(String suspected) throws CompileException, IOException
peekNextButOne in interface TokenStreamCompileExceptionIOExceptionpublic Token read() throws CompileException, IOException
read in interface TokenStreamnull iff the scanner is at end-of-inputCompileExceptionIOExceptionpublic void read(String expected) throws CompileException, IOException
TokenStreamread in interface TokenStreamCompileException - The value of the next token does not equal expected (this includes the case
that the scanner is at end-of-input)IOExceptionpublic int read(String... expected) throws CompileException, IOException
TokenStreamread in interface TokenStreamCompileException - 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)IOExceptionpublic String read(TokenType expected) throws CompileException, IOException
TokenStreamread in interface TokenStreaminterned String iff the token
represents an identifier, true, false, null, or an operatorCompileException - The next token's type is not the expectedIOExceptionpublic int read(TokenType... expected) throws CompileException, IOException
TokenStreamread in interface TokenStreamCompileException - The next token's type is none of the expectedIOExceptionpublic boolean peekRead(String suspected) throws CompileException, IOException
TokenStreampeekRead in interface TokenStreamCompileExceptionIOExceptionpublic int peekRead(String... suspected) throws CompileException, IOException
TokenStreampeekRead in interface TokenStreamCompileExceptionIOException@Nullable public String peekRead(TokenType suspected) throws CompileException, IOException
TokenStreampeekRead in interface TokenStreaminterned String iff the token represents an
identifier, true, false, null, or an operatorCompileExceptionIOExceptionpublic int peekRead(TokenType... suspected) throws CompileException, IOException
TokenStreampeekRead in interface TokenStreamCompileExceptionIOExceptionpublic Location location()
location in interface TokenStreampublic void setWarningHandler(@Nullable WarningHandler optionalWarningHandler)
TokenStreamWarningHandler.
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.
setWarningHandler in interface TokenStreamoptionalWarningHandler - null to indicate that no warnings be issuedprotected final CompileException compileException(String message)
CompileException.Copyright © 2019. All rights reserved.