com.google.gdata.util.parser
Class Intersection<T>
java.lang.Object
com.google.gdata.util.parser.Parser<T>
com.google.gdata.util.parser.Intersection<T>
- Type Parameters:
T
-
public class Intersection<T>
- extends Parser<T>
The Intersection
parser provides one of the more powerful
pieces of functionality in the parser framework. It returns a successful
match only if both the left
and right
sub-parsers
match. Additionally, the amount of parse data passed to the
right
parser is restricted to the size of the match for the
left
parser. This allows certain types of recursively defined
grammars to be more easily specified. Note that this definition of
intersection is not the same as a set-theoretic definition. In particular,
this definition is not commutative.
Parser i = Parser.intersection(Chset.ALPHA.plus(), Chset.ALNUM.plus());
i.parse("a", null) -> matches "a"
i.parse("a1", null) -> matches "a"
Parser j = Parser.intersection(Chset.ALNUM.plus(), Chset.ALPHA.plus());
j.parse("a", null) -> matches "a"
j.parse("a1", null) -> no match, because ALNUM+ matches "a1" which doesn't
match ALPHA+
- 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. |
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 |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Intersection
public Intersection(Parser<? super T> left,
Parser<? super T> right)
- Class constructor.
- Parameters:
left
- The Parser
that is first matched against the
parse buffer. It restricts the region of the parse buffer that is matched
against the right
parser.right
- The Parser
that is matched against the parse
buffer if the left
parses has already 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.
- 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)