Class RegularExpressionParser<E>

java.lang.Object
edu.washington.cs.knowitall.regex.RegularExpressionParser<E>
Type Parameters:
E - the type of the sequence elements
All Implemented Interfaces:
com.google.common.base.Function<String,RegularExpression<E>>, Function<String,RegularExpression<E>>

public abstract class RegularExpressionParser<E> extends Object implements com.google.common.base.Function<String,RegularExpression<E>>
A regular expression parser turns strings into RegularExpression objects.
  • Constructor Details

    • RegularExpressionParser

      public RegularExpressionParser()
  • Method Details

    • factory

      public abstract Expression.BaseExpression<E> factory(String token)
      The factory method creates an expression from the supplied token string.
      Parameters:
      token - a string representation of a token
      Returns:
      an evaluatable representation of a token
    • parse

      public RegularExpression<E> parse(String string)
    • apply

      public RegularExpression<E> apply(String string)
      Specified by:
      apply in interface com.google.common.base.Function<String,RegularExpression<E>>
      Specified by:
      apply in interface Function<String,RegularExpression<E>>
    • readToken

      public String readToken(String remaining)
      Read a token from the remaining text and return it. This is a default implementation that is overridable. In the default implementation, the starting and ending token characters are not escapable. If this implemenation is overridden, A token MUST ALWAYS start with '<' or '[' and end with '>' or ']'.
      Parameters:
      remaining -
      Returns:
    • tokenize

      public List<Expression<E>> tokenize(String string)
      Convert a list of tokens (<...>) to a list of expressions.
      Parameters:
      tokens -
      factory - Factory class to create a BaseExpression from the text between angled brackets.
      Returns:
    • indexOfClose

      private static int indexOfClose(String string, int start, char open, char close)