public abstract class Pattern
extends java.lang.Object
implements java.io.Serializable
Pattern object is used for terminal level parsers. A Pattern differs from a Parser in that it does not return object, and it simply reports mismatch whenenver fails. While Parser cannot be implemented directly, Pattern can be implemented directly by user code.
Modifier and Type | Field and Description |
---|---|
static int |
MISMATCH
returned by match() method when match fails.
|
Constructor and Description |
---|
Pattern() |
Modifier and Type | Method and Description |
---|---|
Pattern |
ifelse(Pattern yes,
Pattern no)
If this pattern matches,
match the remaining input against Pattern object yes.
|
Pattern |
many()
Matches this pattern for 0 or more times.
|
Pattern |
many(int min)
Matches this pattern for at least min times.
|
Pattern |
many1()
Matches this pattern for 1 or more times.
|
abstract int |
match(java.lang.CharSequence src,
int len,
int from)
The actual length of the pattern string is len - from.
|
Pattern |
not()
If this pattern matches, return mismatch.
|
Pattern |
optional()
Match with 0 length even if this pattern mismatches.
|
Pattern |
peek()
Matches with match length 0 if this Pattern object matches.
|
Pattern |
repeat(int n)
Matches the input against this pattern for n times.
|
Pattern |
seq(Pattern p2)
First matches this pattern.
|
Pattern |
some(int max)
Matches this pattern for up to max times.
|
Pattern |
some(int min,
int max)
Matches this pattern for at least min times
and at most max times.
|
public static final int MISMATCH
public abstract int match(java.lang.CharSequence src, int len, int from)
src
- the source string.len
- the length of the sequence.
NOTE: the range is [from, len], not [from,from+len].from
- the starting index in the sequence.public final Pattern seq(Pattern p2)
p2
- the next Pattern object to match.public final Pattern optional()
public final Pattern many()
public final Pattern many(int min)
min
- the minimal number of times to match.public final Pattern many1()
public final Pattern some(int max)
max
- the maximal number of times to match.public final Pattern some(int min, int max)
min
- the minimal number of times to match.max
- the maximal number of times to match.public final Pattern not()
public final Pattern peek()
public final Pattern ifelse(Pattern yes, Pattern no)
yes
- the true Pattern.no
- the false Pattern.public final Pattern repeat(int n)
n
- the number of times to match.