Class GenericParser

java.lang.Object
dev.roanh.gmark.lang.generic.GenericParser
Direct Known Subclasses:
ParserCPQ, ParserRPQ

public abstract class GenericParser extends Object
Class with generic query language parsing utilities.
  • Constructor Details

    • GenericParser

      protected GenericParser()
      Hide constructor.
  • Method Details

    • split

      protected static List<String> split(String str, char symbol) throws IllegalArgumentException
      Splits the given string into parts on the given character. The given character will not be returned in any parts and the found parts will be trimmed of leading and trailing whitespace. This method will ignore any regions of the input string that are enclosed in (nested) round brackets.
      Parameters:
      str - The string to split.
      symbol - The character to split on.
      Returns:
      The input string split on the given character.
      Throws:
      IllegalArgumentException - When brackets are present in the given string, but not balanced properly.
    • parsePredicate

      protected static Predicate parsePredicate(String query, Map<String,Predicate> labels, char inverse) throws IllegalArgumentException
      Attempts to parse an (inverse) predicate/label from the given query string.
      Parameters:
      query - The query string to parse.
      labels - The set of predicates encountered so far. Used to reuse existing labels and to register newly detected predicates.
      inverse - The symbol used to denote inverse labels.
      Returns:
      The predicate that was parsed.
      Throws:
      IllegalArgumentException - When the given query string does not represent a valid predicate.