Package eu.bandm.tools.ramus.runtime2
Class AbstractCharacterInput<D,T,U extends Parser.Token<D,T>>
java.lang.Object
eu.bandm.tools.ramus.runtime2.AbstractCharacterInput<D,T,U>
Character input source.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The maximum number of characters a lexer may look ahead. -
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractCharacterInput
(D documentId, Reader in) DOCUMENT ME -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Consumes and returns the next input character.Creates an empty token of a given type at the current line/column location.Ends the creation of a new token with the given type and currently accumulated text.protected abstract int
protected abstract int
location()
Returns a location that spans input since the last recorded line/column number.Returns a location that points to the current line/column number.int
lookahead
(int k) Returns thek
-th input character after the current, without changing the state.Creates a token with the given type and text, if matching the input.protected abstract U
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.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.Creates a token ofk
characters of a given type at the current line/column location.
-
Field Details
-
MAX_LOOKAHEAD
public static final int MAX_LOOKAHEADThe maximum number of characters a lexer may look ahead.- See Also:
-
-
Constructor Details
-
AbstractCharacterInput
DOCUMENT ME
-
-
Method Details
-
getFirstLine
protected abstract int getFirstLine() -
getFirstColumn
protected abstract int getFirstColumn() -
lookahead
Returns thek
-th input character after the current, without changing the state.- Parameters:
k
- the number of characters to skip ahead- Returns:
- the k-th input character after the current, or
-1
if not enough characters are available - Throws:
IllegalArgumentException
- ifk < 0
ork > MAX_LOOKAHEAD
IOException
-
consume
Consumes and returns the next input character. The current line and column number are updated.- Returns:
- the next input character, or
-1
if no more characters are available - Throws:
IOException
-
consume
- Throws:
IOException
-
consumeNoEOF
Consumes and returns the next input character. The current line and column number are updated.- Returns:
- the next input character
- Throws:
EOFException
- if no more characters are availableIOException
-
newToken
-
empty
Creates an empty token of a given type at the current line/column location. -
singleton
Creates a single-character token of a given type at the current line/column location.- Throws:
IOException
-
take
Creates a token ofk
characters of a given type at the current line/column location.- Throws:
IOException
-
begin
public void begin()Starts creation of a new token and records the current line/column location. -
shift
Consumes the next input character and appends it to the current text.- Throws:
EOFException
- if no more characters are availableIOException
-
shiftIf
Consumes the next input character if a condition is satisfied and appends them to the current text.- Parameters:
condition
- indicates whether to consume the next character- Throws:
EOFException
- if no more characters are availableIOException
-
shiftWhile
Consumes input characters as long as a loop condition is satisfied and appends them to the current text.- Parameters:
condition
- indicates whether to consume the next character and iterate- Throws:
EOFException
- if no more characters are availableIOException
-
substitute
Consumes the next input character and appends a substitute to the current text.- Parameters:
subst
- the character to substitute- Throws:
EOFException
- if no more characters are availableIOException
-
end
Ends the creation of a new token with the given type and currently accumulated text.- Parameters:
type
- the token type
-
match
Creates a token with the given type and text, if matching the input. Otherwise, no input characters are consumed.- Parameters:
the
- expected input textthe
- type of token to create- Returns:
- an
Optional
containing a token with the given type and text, if input characters can be consumed to match the text exactly; otherwiseOptional#none
. - Throws:
IOException
-
location
Returns a location that spans input since the last recorded line/column number.- Returns:
- a location that spans input since the last recorded line/column number.
- See Also:
-
#start
-
locationEnd
Returns a location that points to the current line/column number.- Returns:
- a location that points to the current line/column number.
-
replace
-