T
- public class Repeat<T> extends Parser<T>
Repeat
parser returns a successful match if its
subject
parser matches at least min
times, but not
more than max
times. The Repeat
parser is used to
implement the Parser.star()
and Parser.plus()
methods by specifying appropriate values for min
and
max
.
The following matches a string of 1 to 3 letters:
Parse p = Chset.ALPHA.repeat(1, 3);
p.parse("") -> no match
p.parse("a") -> matches "a"
p.parse("aa") -> matches "aa"
p.parse("aaa") -> matches "aaa"
p.parse("aaaa") -> matches "aaa"Constructor and Description |
---|
Repeat(Parser<T> subject,
int min)
Class constructor that is used for creating a
Repeat object
that will match its subject min or more times. |
Repeat(Parser<T> subject,
int min,
int max)
Class constructor that is used for creating a
Repeat object
that will match its subject at least min times
but not more than max times. |
Modifier and Type | Method and Description |
---|---|
int |
parse(char[] buf,
int start,
int end,
T data)
Matches the
subject parser against the prefix of the buffer
(buf[start,end) ) being parsed if the subject
parser matches at least min times and not more than
max times in sequence. |
public Repeat(Parser<T> subject, int min)
Repeat
object
that will match its subject
min
or more times.subject
- The Parse
that this parser will repeatedly
match.min
- The minimum number of times the subject
parser
must match.public Repeat(Parser<T> subject, int min, int max)
Repeat
object
that will match its subject
at least min
times
but not more than max
times. Specifying -1
for
max
causes the parser to match as many times as possible.subject
- The Parse
that this parser will repeatedly
match.min
- The minimum number of times the subject
parser
must match.max
- The maximum number of times the subject
parser can
match.public int parse(char[] buf, int start, int end, T data)
subject
parser against the prefix of the buffer
(buf[start,end)
) being parsed if the subject
parser matches at least min
times and not more than
max
times 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)