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<java.lang.String,RegularExpression<E>>
,java.util.function.Function<java.lang.String,RegularExpression<E>>
public abstract class RegularExpressionParser<E> extends java.lang.Object implements com.google.common.base.Function<java.lang.String,RegularExpression<E>>
A regular expression parser turns strings into RegularExpression objects.
-
-
Constructor Summary
Constructors Constructor Description RegularExpressionParser()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description RegularExpression<E>
apply(java.lang.String string)
abstract Expression.BaseExpression<E>
factory(java.lang.String token)
The factory method creates an expression from the supplied token string.private static int
indexOfClose(java.lang.String string, int start, char open, char close)
RegularExpression<E>
parse(java.lang.String string)
java.lang.String
readToken(java.lang.String remaining)
Read a token from the remaining text and return it.java.util.List<Expression<E>>
tokenize(java.lang.String string)
Convert a list of tokens (<...>) to a list of expressions.
-
-
-
Method Detail
-
factory
public abstract Expression.BaseExpression<E> factory(java.lang.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(java.lang.String string)
-
apply
public RegularExpression<E> apply(java.lang.String string)
- Specified by:
apply
in interfacecom.google.common.base.Function<java.lang.String,RegularExpression<E>>
- Specified by:
apply
in interfacejava.util.function.Function<java.lang.String,RegularExpression<E>>
-
readToken
public java.lang.String readToken(java.lang.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 java.util.List<Expression<E>> tokenize(java.lang.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(java.lang.String string, int start, char open, char close)
-
-