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

public abstract class SequentialParser<T> extends Parser<T>
  • Field Details

    • intermediate

      protected T intermediate
  • Constructor Details

    • SequentialParser

      public SequentialParser()
  • Method Details

    • succeed

      @Contract("-> true") protected boolean succeed()
    • startStep

      protected void startStep(String input, T intermediate)
    • parseRecursively

      protected boolean parseRecursively(String input)
      Recursively parses a new input string, then restores the previous state of this parser.
      Parameters:
      input - The input string to parse
      Returns:
      true if the recursive parsing was successful.
    • recursiveStep

      protected <R> R recursiveStep(Supplier<R> callback)
      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

      protected void setInput(String input)
      Sets the input string and moves the cursor to the first character.
      Parameters:
      input - The input string
    • getInput

      protected String getInput()
      Returns the input string.
      Returns:
      The input string.
    • isMethodCall

      protected boolean isMethodCall(String methodName)
    • readBetweenParentheses

      protected String readBetweenParentheses()
    • readBetweenSquareBrackets

      protected String readBetweenSquareBrackets()
    • readBetweenCharacters

      protected String readBetweenCharacters(char before, char after)
    • readWhile

      protected String readWhile(SequentialParser.CharPredicate predicate)
      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

      protected void skipUntil(SequentialParser.CharPredicate predicate)
      Moves the cursor until the predicate evaluates to true.
      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

      protected void skipIf(SequentialParser.CharPredicate predicate)
      Moves the cursor by one of the predicate evaluates to true for 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

      protected String 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:
      true if 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.