com.google.gdata.util.parser
Class Sequence<T>
java.lang.Object
com.google.gdata.util.parser.Parser<T>
com.google.gdata.util.parser.Sequence<T>
- Type Parameters:
T
-
public class Sequence<T>
- extends Parser<T>
The 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 letter
- See Also:
Parser
Fields inherited from class com.google.gdata.util.parser.Parser |
NO_MATCH |
Method Summary |
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. |
Methods inherited from class com.google.gdata.util.parser.Parser |
action, alternative, difference, intersection, list, optional, parse, parse, parse, plus, repeat, repeat, sequence, sequence, sequence, sequence, star |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Sequence
public Sequence(Parser<? super T> left,
Parser<? super T> right)
- Class constructor.
- Parameters:
left
- The Parser
that is matched against the parse
buffer first.right
- The Parser
that is matched against what remains
of the parse buffer if the left
parser matched.
parse
public 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.
- Specified by:
parse
in class Parser<T>
- Parameters:
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.- See Also:
Parser.parse(char[], int, int, T)