Package eu.bandm.tools.ramus.runtime2
Class AbstractCharacterInput<D,T,U extends Token<D,T>>
java.lang.Object
eu.bandm.tools.ramus.runtime2.AbstractCharacterInput<D,T,U>
Character input source.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum number of characters a lexer may look ahead. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractCharacterInput(D documentId, Reader in) DOCUMENT ME -
Method Summary
Modifier and TypeMethodDescriptionvoidbegin()Starts creation of a new token and records the current line/column location.intconsume()Consumes and returns the next input character.intconsume(char expected) charConsumes 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 intprotected abstract intlocation()Returns a location that spans input since the last recorded line/column number.Returns a location that points to the current line/column number.intlookahead(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 Uvoidshift()Consumes the next input character and appends it to the current text.voidshiftIf(IntPredicate condition) Consumes the next input character if a condition is satisfied and appends them to the current text.voidshiftWhile(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.voidsubstitute(char subst) Consumes the next input character and appends a substitute to the current text.Creates a token ofkcharacters 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
-1if not enough characters are available - Throws:
IllegalArgumentException- ifk < 0ork > MAX_LOOKAHEADIOException
-
consume
Consumes and returns the next input character. The current line and column number are updated.- Returns:
- the next input character, or
-1if 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 ofkcharacters 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:
text- the expected input texttype- the type of token to create- Returns:
- an
Optionalcontaining a token with the given type and text, if input characters can be consumed to match the text exactly; otherwiseOptional.empty(). - 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:
-
locationEnd
Returns a location that points to the current line/column number.- Returns:
- a location that points to the current line/column number.
-
replace
-