Class Parser<T>

java.lang.Object
dev.prozilla.pine.common.util.Parser<T>
Type Parameters:
T - The type of the result.
All Implemented Interfaces:
Printable
Direct Known Subclasses:
ColorParser, CSSParser, DimensionParser, DualDimensionParser, EnumParser

public abstract class Parser<T> extends Object implements Printable
Abstract class for a stateful parser.
  • Constructor Details

    • Parser

      public Parser()
  • Method Details

    • read

      public T read(String input)
      Parses an input string and throws an exception if the parsing fails.
      Parameters:
      input - The input string to parse
      Returns:
      The parsed value or null, if the parsing failed.
    • getResult

      public T getResult()
      Returns the result or null, if the parsing failed.
      Returns:
      The result
    • getError

      public String getError()
      Returns the error message or null, if the parsing succeeded.
      Returns:
      The error message
    • parse

      public abstract boolean parse(String input)
      Parses a string.
      Parameters:
      input - The input string to parse
      Returns:
      true if the parsing succeeded.
    • succeed

      protected boolean succeed(T result)
    • fail

      protected boolean fail()
    • fail

      protected boolean fail(String errorMessage)
    • toString

      public String toString()
      Description copied from interface: Printable
      Returns a string representation of this object.
      Specified by:
      toString in interface Printable
      Overrides:
      toString in class Object
      Returns:
      String representation of this object.