TT - The enumerator representing the scanner's token typespublic class AbstractParser<TT extends Enum<TT>> extends Object
| Modifier and Type | Field and Description |
|---|---|
protected ProducerWhichThrows<? extends AbstractScanner.Token<TT>,? extends ScanException> |
scanner
The source of tokens that are processed by this parser.
|
| Constructor and Description |
|---|
AbstractParser(ProducerWhichThrows<? extends AbstractScanner.Token<TT>,? extends ScanException> scanner) |
| Modifier and Type | Method and Description |
|---|---|
void |
eoi()
Asserts that the scanner is at end-of-input.
|
AbstractScanner.Token<TT> |
peek()
Checks the next token, but does not consume it.
|
int |
peek(Object... tokenTypeOrText)
Checks the next token, but does not consume it.
|
boolean |
peek(String text)
Checks the next token, but does not consume it.
|
String |
peek(TT tokenType)
Checks the next token, but does not consume it.
|
int |
peekRead(String... texts)
Checks the next token and consumes it if it matches.
|
boolean |
peekRead(String text)
Checks the next token and consumes it if it matches.
|
AbstractScanner.Token<TT> |
peekRead(TT... tokenTypes)
Checks the next token and consumes it if its type is one of the tokenTypes.
|
String |
peekRead(TT tokenType)
Checks the next token and consumes it if its type is tokenType.
|
<T extends Enum<T>> |
peekReadEnum(T... values)
Checks the next token and consumes it if its text equals the return value of
toString() of one of the values. |
AbstractScanner.Token<TT> |
read()
Consumes the next token.
|
int |
read(Object... tokenTypeOrText)
Consumes the next token.
|
void |
read(String text)
Consumes the next token.
|
String |
read(TT tokenType)
Consumes the next token.
|
void |
unread(AbstractScanner.Token<TT> t)
Modifies this parser such that t will appear as the "next token" before the actual next
token.
|
protected final ProducerWhichThrows<? extends AbstractScanner.Token<TT extends Enum<TT>>,? extends ScanException> scanner
public AbstractParser(ProducerWhichThrows<? extends AbstractScanner.Token<TT>,? extends ScanException> scanner)
scanner - Its toString() method returns a human-readable indication of the scanner location@Nullable public AbstractScanner.Token<TT> peek() throws ParseException
null if the scanner is at end-of-inputParseException@Nullable public String peek(TT tokenType) throws ParseException
null if the next token's type is not tokenType, or if the
scanner is at end-of-inputParseExceptionpublic boolean peek(@Nullable
String text)
throws ParseException
nullParseExceptionpublic int peek(Object... tokenTypeOrText) throws ParseException
An element of tokenTypeOrText matches iff:
null and the scanner is at end-of-input-1ParseException@Nullable public String peekRead(TT tokenType) throws ParseException
null if the next token's type is not tokenType, or if
the scanner is at end-of-inputParseExceptionpublic boolean peekRead(@Nullable
String text)
throws ParseException
nullParseExceptionpublic int peekRead(String... texts) throws ParseException
An element of texts matches iff:
null and the scanner is at end-of-input-1ParseException@Nullable public <T extends Enum<T>> T peekReadEnum(T... values) throws ParseException
toString() of one of the values.null if none match, or the scanner is at end-of-inputParseException@Nullable public AbstractScanner.Token<TT> peekRead(TT... tokenTypes) throws ParseException
null iff none match, or the scanner is at end-of-inputParseExceptionpublic AbstractScanner.Token<TT> read() throws ParseException
ParseException - The scanner is at end-of-inputpublic String read(TT tokenType) throws ParseException
ParseException - The next token's type is not tokenTypeParseException - The scanner is at end-of-inputpublic void read(String text) throws ParseException
ParseException - The next token's text does not equal textParseException - The scanner is at end-of-inputeoi()public int read(Object... tokenTypeOrText) throws ParseException
An element of tokenTypeOrText matches iff:
null and the scanner is at end-of-inputParseException - Neither the next token's type nor its text equals any of tokenTypeOrTextParseException - The scanner is at end-of-inputpublic void unread(AbstractScanner.Token<TT> t)
This operation is only permitted iff the next token has not been read-ahead.
IllegalStateException - Another token has already been read-ahead, either by one of the peek()
operations, or an unsuccessful peekRead() operationpublic void eoi()
throws ParseException
ParseException - Iff the scanner is not at end-of-inputCopyright © 2018 Arno Unkrig. All rights reserved.