jfun.parsec.pattern
public abstract class Pattern extends Object implements 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.
| Field Summary | |
|---|---|
| static int | MISMATCH
returned by match() method when match fails. |
| 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(CharSequence src, int len, int from)
The actual length of the pattern string is len - from. |
| Pattern | not()
If this pattern matches, return mismatch.
return match length 0 otherwise. |
| 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.
|
Parameters: yes the true Pattern. no the false Pattern.
Returns: the new Pattern object.
Returns: the new Pattern object.
Parameters: min the minimal number of times to match.
Returns: the new Pattern object.
Returns: the new Pattern object.
Parameters: 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.
Returns: the number of characters matched. MISMATCH otherwise.
Returns: the new Pattern object.
Returns: the new Pattern object.
Returns: the new Pattern object.
Parameters: n the number of times to match.
Returns: the new Pattern object.
Parameters: p2 the next Pattern object to match.
Returns: the new Pattern object.
Parameters: max the maximal number of times to match.
Returns: the new Pattern object.
Parameters: min the minimal number of times to match. max the maximal number of times to match.
Returns: the new Pattern object.