1 package io.github.reggert.reb4j; 2 3 import java.io.Serializable; 4 import java.util.regex.Pattern; 5 6 import fj.data.LazyString; 7 8 /** 9 * Basic abstraction of a regular expression. 10 * 11 * All implementations of this can be converted directly into a 12 * {@link Pattern} object without risk of throwing an exception. 13 * 14 * This interface is not intended to be implemented by clients, 15 * and doing so will result in unpredictable behavior. 16 */ 17 public interface Expression extends Serializable 18 { 19 /** 20 * Returns the regular expression represented by this object. 21 */ 22 LazyString expression(); 23 24 /** 25 * Passes the regular expression represented by this object to 26 * {@link java.util.regex.Pattern} and returns the result. 27 */ 28 Pattern toPattern(); 29 30 /** 31 * Indicates the computed maximum length of the expression, if one can be 32 * determined. 33 * 34 * @return the computed maximum length, or null if it is unbounded. 35 */ 36 Integer boundedLength(); 37 38 /** 39 * Indicates whether applying repetition to the expression invalidates the 40 * boundedness computation. This generally indicates that the expression may 41 * match a zero-repetition ({0, n} or ?). 42 * 43 * This is used to determine boundedness of enclosing expressions. 44 */ 45 boolean repetitionInvalidatesBounds(); 46 47 /** 48 * Indicates whether the expression may possibly be zero length. 49 * 50 * Used in some cases for determining repetitionInvalidatesBounds. 51 */ 52 boolean possiblyZeroLength(); 53 }