T - public class Intersection<T> extends Parser<T>
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+Parser| Constructor and Description |
|---|
Intersection(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. |
public Intersection(Parser<? super T> left, Parser<? super T> right)
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.public int parse(char[] buf,
int start,
int end,
T data)
buf[start,end)) being
parsed against the left and right sub-parsers.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)