public abstract class AbstractCharacterInput<D,T,U extends Parser.Token<D,T>> extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_LOOKAHEAD
The maximum number of characters a lexer may look ahead.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractCharacterInput(D documentId,
Reader in)
DOCUMENT ME
|
| Modifier and Type | Method and Description |
|---|---|
void |
begin()
Starts creation of a new token and records the current
line/column location.
|
int |
consume()
Consumes and returns the next input character.
|
int |
consume(char expected) |
char |
consumeNoEOF()
Consumes and returns the next input character.
|
U |
empty(T type)
Creates an empty token of a given type at the current
line/column location.
|
U |
end(T type)
Ends the creation of a new token with the given type and
currently accumulated text.
|
protected abstract int |
getFirstColumn() |
protected abstract int |
getFirstLine() |
protected Location<D> |
location()
Returns a location that spans input since the last recorded
line/column number.
|
protected Location<D> |
locationEnd()
Returns a location that points to the current line/column
number.
|
int |
lookahead(int k)
Returns the
k-th input character after the current,
without changing the state. |
Optional<U> |
match(String text,
T type)
Creates a token with the given type and text, if matching the
input.
|
protected abstract U |
newToken(@Opt Location<D> location,
String text,
T type) |
U |
replace(String text,
T type) |
void |
shift()
Consumes the next input character and appends it to the current
text.
|
void |
shiftIf(IntPredicate condition)
Consumes the next input character if a condition is satisfied
and appends them to the current text.
|
void |
shiftWhile(IntPredicate condition)
Consumes input characters as long as a loop condition is
satisfied and appends them to the current text.
|
U |
singleton(T type)
Creates a single-character token of a given type at the current
line/column location.
|
void |
substitute(char subst)
Consumes the next input character and appends a substitute to
the current text.
|
U |
take(int k,
T type)
Creates a token of
k characters of a given type at the
current line/column location. |
public static final int MAX_LOOKAHEAD
protected abstract int getFirstLine()
protected abstract int getFirstColumn()
public int lookahead(int k)
throws IOException
k-th input character after the current,
without changing the state.k - the number of characters to skip ahead-1 if not enough characters are availableIllegalArgumentException - if k < 0 or k > MAX_LOOKAHEADIOExceptionpublic int consume()
throws IOException
-1 if no more
characters are availableIOExceptionpublic int consume(char expected)
throws IOException
IOExceptionpublic char consumeNoEOF()
throws IOException
EOFException - if no more characters are availableIOExceptionpublic U empty(T type)
public U singleton(T type) throws IOException
IOExceptionpublic U take(int k, T type) throws IOException
k characters of a given type at the
current line/column location.IOExceptionpublic void begin()
public void shift()
throws IOException
EOFException - if no more characters are availableIOExceptionpublic void shiftIf(IntPredicate condition) throws IOException
condition - indicates whether to consume the next
characterEOFException - if no more characters are availableIOExceptionpublic void shiftWhile(IntPredicate condition) throws IOException
condition - indicates whether to consume the next
character and iterateEOFException - if no more characters are availableIOExceptionpublic void substitute(char subst)
throws IOException
subst - the character to substituteEOFException - if no more characters are availableIOExceptionpublic U end(T type)
type - the token typepublic Optional<U> match(String text, T type) throws IOException
the - expected input textthe - type of token to createOptional containing a token with the given
type and text, if input characters can be consumed to match the
text exactly; otherwise Optional#none.IOExceptionprotected Location<D> location()
#startprotected Location<D> locationEnd()
see also the complete user documentation .