T
- public class Alternative<T> extends Parser<T>
Alternative
parser parses either the left
or
right
sub-parsers. If the left
parser matches, the
right
parser is not invoked. This short-circuiting is similar
to the way the evaluation of the logical-or (||
) operator is
short-circuited in C++ and Java. It is important to be aware of the
short-circuiting in cases where the right
parser contains a
Action
.
The following is a complicated way of constructing a parser which matches
letters:
Parser p = Parser.alternative(Chset.LOWER, Chset.UPPER);
p.parse("a") -> matches "a"
p.parse("A") -> matches "A"Parser
Constructor and Description |
---|
Alternative(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 current prefix of the buffer being parsed
buf[start,end] against left or
right sub-parsers. |
public int parse(char[] buf, int start, int end, T data)
buf[start,end]
against left
or
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)