T - public class Sequence<T> extends Parser<T>
Sequence parser matches if its left parser
matches the prefix of the parse buffer and then its right
parser matches (in sequence) the prefix of whatever remains in the parse
buffer. Contrast this with the Alternative and
Intersection parsers which apply their sub-parsers to the same
portion of the parse buffer.
The following matches a string composed of letters followed by digits:
Parser p = Parser.sequence(Chset.ALPHA.plus(), Chset.DIGIT.plus());
p.parse("a0") -> matches "a0"
p.parse("aaa0") -> matches "aaa0"
p.parse("aaa000") -> matches "aaa0000"
p.parse("a1a") -> matches "a1"
p.parse("a") -> no match, does not end in a digit
p.parse("0") -> no match, does not start with a letterParser| Constructor and Description |
|---|
Sequence(Parser<? super T> left,
Parser<? super T> right)
Class constructor.
|
| Modifier and Type | Method and Description |
|---|---|
int |
parse(char[] buf,
int start,
int end,
T data)
Matches the prefix of the buffer (
buf[start,end)) being
parsed against the left and right sub-parsers in
sequence. |
public int parse(char[] buf,
int start,
int end,
T data)
buf[start,end)) being
parsed against the left and right sub-parsers in
sequence.parse in class Parser<T>buf - The character array to match against.start - The start offset of data within the character array to match
against.end - The end offset of data within the character array to match
against.data - User defined object that is passed to
Callback.handle when an Action fires.Parser.parse(char[], int, int, T)