V
 the type parameter of the parserpublic abstract class RangeMatcherBuilder<V> extends Object
This class allows to specify a number of times which a given rule should be repeated:
When appropriate, the returned rule is a simplified version; for instance,
a rule repeated "exactly once" is the rule itself. See range(Range)
for more details.
JoinMatcherBuilder
,
RepeatMatcherBuilder
Modifier and Type  Field and Description 

protected BaseParser<V> 
parser 
protected Rule 
rule 
Modifier  Constructor and Description 

protected 
RangeMatcherBuilder(BaseParser<V> parser,
Rule rule) 
Modifier and Type  Method and Description 

protected abstract Rule 
boundedBoth(int minCycles,
int maxCycles)
Build a rule which is expected to match a number of times between two
end points

protected abstract Rule 
boundedDown(int minCycles)
Build a rule which is expected to match a minimum number of times

protected abstract Rule 
boundedUp(int maxCycles)
Build a rule which is expected to match a maximum number of times

protected abstract Rule 
exactly(int nrCycles)
Build a rule which is expected to match a fixed number of times

Rule 
max(int nrCycles)
Return a rule with a maximum number of cycles to run

Rule 
min(int nrCycles)
Return a rule with a minimum number of cycles to run

Rule 
range(Range<Integer> range)
Core method for building a repeating matcher

Rule 
times(int nrCycles)
Return a rule with an exact number of cycles to run

Rule 
times(int minCycles,
int maxCycles)
Return a rule with both lower and upper bounds on the number of cycles

protected final BaseParser<V> parser
protected final Rule rule
protected RangeMatcherBuilder(BaseParser<V> parser, Rule rule)
public Rule min(int nrCycles)
nrCycles
 the number of cyclesIllegalArgumentException
 nrCycles
is less than 0Range.atLeast(Comparable)
public Rule max(int nrCycles)
nrCycles
 the number of cyclesIllegalArgumentException
 nrCycles
is less than 0Range.atMost(Comparable)
public Rule times(int nrCycles)
nrCycles
 the number of cyclesIllegalArgumentException
 nrCycles
is less than 0Range.singleton(Comparable)
public Rule times(int minCycles, int maxCycles)
Note that the range of cycles to run is closed on both ends (that is, the minimum and maximum number of cycles) are inclusive.
minCycles
 the minimum number of cyclesmaxCycles
 the maximum number of cyclesIllegalArgumentException
 minimum number of cycles is negative; or
maximum number of cycles is less than the minimumRange.closed(Comparable, Comparable)
@Cached @DontLabel public Rule range(Range<Integer> range)
This is the method which all other methods (min, max, times) delegate to; among other things it is responsible for the logic of simplifying matchers where possible.
The simplifications are as follows:
EmptyMatcher
;OptionalMatcher
with the rule as a
submatcher;If none of these apply, this method delegates as follows:
boundedDown(int)
;
boundedUp(int)
;exactly(int)
;boundedBoth(int, int)
.range
 the rangeprotected abstract Rule boundedDown(int minCycles)
The returned matcher will attempt to match indefinitely its input until it fails. Success should be declared if and only if the number of times the matcher has succeeded is greater than, or equal to, the number of cycles given as an argument (including 0).
minCycles
 the minimum number of cycles (inclusive)protected abstract Rule boundedUp(int maxCycles)
The returned matcher will attempt to match repeatedly up to, and including, the number of cycles returned as an argument. Note that the argument will always be greater than or equal to 2.
One consequence is that this matcher always succeeds.
maxCycles
 the maximum number of cycles (inclusive)protected abstract Rule exactly(int nrCycles)
The returned matcher will attempt to match repeatedly up to, and including, the number of cycles given as an argument. Success should be declared if and only if the number of cycles matched is exactly this number.
nrCycles
 the number of cycles (inclusive)protected abstract Rule boundedBoth(int minCycles, int maxCycles)
The returned matcher will attempt to match repeatedly up to, and including, the maximum number of cycles specified as the second argument. Success should be declared if and only if the number of cycles performed is at least equal to the number of cycles specified as the first argument.
Note that the first argument will always be strictly greater than 0, and that the second argument will always be strictly greater than the first.
minCycles
 the minimum number of cycles (inclusive)maxCycles
 the maximum number of cycles (exclusive)