Package dev.prozilla.pine.common.util
Class SequentialParser<T>
java.lang.Object
dev.prozilla.pine.common.util.Parser<T>
dev.prozilla.pine.common.util.SequentialParser<T>
- All Implemented Interfaces:
Printable
- Direct Known Subclasses:
CSSParser,EasingParser,SelectorParser
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRepresents a predicate of one character. -
Field Summary
FieldsFields inherited from class dev.prozilla.pine.common.util.Parser
GENERIC_ERROR, UNEXPECTED_END_OF_INPUT_ERROR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanChecks if the cursor is at the end of the input and therefore not pointing to any character.protected chargetChar()Returns the character the cursor is pointing to.protected intReturns the amount of characters in the input string.protected final intReturns the position of the cursor.protected StringgetInput()Returns the input string.protected Stringprotected booleanisChar(char character) Checks if the cursor points to a character that is equal to the given character.protected booleanisMethodCall(String methodName) protected booleanisNotChar(char character) Checks if the cursor points to a character that is not equal to the given character.protected voidMoves the cursor by one.protected voidmoveCursor(int amount) Moves the cursor by a given amount.protected voidprotected booleanparseRecursively(String input) Recursively parses a new input string, then restores the previous state of this parser.protected StringreadBetweenCharacters(char before, char after) protected Stringprotected Stringprotected StringreadWhile(SequentialParser.CharPredicate predicate) Returns the sequence of characters constructed by validating the predicate and moving the cursor by one each time it is true.protected <R> RrecursiveStep(Supplier<R> callback) Executes a function and restores the previous state of this parser.protected voidMoves the cursor to the start.voidsetCursor(int cursor) Moves the cursor to a given positionprotected voidSets the input string and moves the cursor to the first character.protected voidskipIf(SequentialParser.CharPredicate predicate) Moves the cursor by one of the predicate evaluates totruefor the current character.protected voidskipIfChar(char character) Moves the cursor by one if the current character is equal to the given character.protected voidskipUntil(SequentialParser.CharPredicate predicate) Moves the cursor until the predicate evaluates totrue.protected voidskipUntilAnyChar(char... characters) Moves the cursor until it points to one of the given characters.protected voidskipUntilChar(char character) Moves the cursor until it points to the given character.protected voidMoves the cursor to the next character that is not whitespace.protected voidprotected booleansucceed()Methods inherited from class dev.prozilla.pine.common.util.Parser
fail, fail, getError, getResult, parse, read, succeed, toString
-
Field Details
-
intermediate
-
-
Constructor Details
-
SequentialParser
public SequentialParser()
-
-
Method Details
-
succeed
@Contract("-> true") protected boolean succeed() -
startStep
-
parseRecursively
Recursively parses a new input string, then restores the previous state of this parser.- Parameters:
input- The input string to parse- Returns:
trueif the recursive parsing was successful.
-
recursiveStep
Executes a function and restores the previous state of this parser.- Type Parameters:
R- The return type of the function- Parameters:
callback- The function to call- Returns:
- The return value of the function.
-
setInput
Sets the input string and moves the cursor to the first character.- Parameters:
input- The input string
-
getInput
Returns the input string.- Returns:
- The input string.
-
isMethodCall
-
readBetweenParentheses
-
readBetweenSquareBrackets
-
readBetweenCharacters
-
readWhile
Returns the sequence of characters constructed by validating the predicate and moving the cursor by one each time it is true.- Parameters:
predicate- The predicate- Returns:
- The string of characters.
-
skipWhitespace
protected void skipWhitespace()Moves the cursor to the next character that is not whitespace. -
skipUntilAnyChar
protected void skipUntilAnyChar(char... characters) Moves the cursor until it points to one of the given characters.- Parameters:
characters- The characters to look for
-
skipUntilChar
protected void skipUntilChar(char character) Moves the cursor until it points to the given character.- Parameters:
character- The character to look for
-
skipUntil
Moves the cursor until the predicate evaluates totrue.- Parameters:
predicate- The predicate
-
skipIfChar
protected void skipIfChar(char character) Moves the cursor by one if the current character is equal to the given character.- Parameters:
character- The character to check for
-
skipIf
Moves the cursor by one of the predicate evaluates totruefor the current character.- Parameters:
predicate- The predicate
-
isNotChar
protected boolean isNotChar(char character) Checks if the cursor points to a character that is not equal to the given character.- Parameters:
character- The character to check for- Returns:
- true if the cursor points to a character that is not equal to
character.
-
isChar
protected boolean isChar(char character) Checks if the cursor points to a character that is equal to the given character.- Parameters:
character- The character to check for- Returns:
- true if the cursor points to a character that is equal to
character.
-
getRemainingInput
-
getChar
protected char getChar()Returns the character the cursor is pointing to.- Returns:
- The character the cursor is pointing to.
-
resetCursor
protected void resetCursor()Moves the cursor to the start. -
moveCursorToEnd
protected void moveCursorToEnd() -
moveCursor
protected void moveCursor()Moves the cursor by one. -
moveCursor
protected void moveCursor(int amount) Moves the cursor by a given amount.- Parameters:
amount- The amount to move
-
getCursor
protected final int getCursor()Returns the position of the cursor.- Returns:
- The position of the cursor.
-
setCursor
public void setCursor(int cursor) Moves the cursor to a given position- Parameters:
cursor- The position to move the cursor to
-
endOfInput
protected boolean endOfInput()Checks if the cursor is at the end of the input and therefore not pointing to any character.- Returns:
trueif the cursor is at the end of the input.
-
getCharCount
protected int getCharCount()Returns the amount of characters in the input string.- Returns:
- The amount of characters in the input string.
-