|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjfun.parsec.pattern.Pattern
public abstract class Pattern
A Pattern object encapsulates an algorithm to recognize certain string pattern. When fed with a character range, a Pattern object either fails to match, or matches with the match length returned.
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.
| Field Summary | |
|---|---|
static int |
MISMATCH
returned by match() method when match fails. |
| Constructor Summary | |
|---|---|
Pattern()
|
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int MISMATCH
| Constructor Detail |
|---|
public Pattern()
| Method Detail |
|---|
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.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||