KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > ManyAccumMinMaxParser


1 /**
2  *
3  */

4 package jfun.parsec;
5
6 final class ManyAccumMinMaxParser<R, From, To, A extends From> extends Parser<R> {
7   private final int max;
8
9   private final Parser<A> p;
10
11   private final int min;
12
13   private final Accumulatable<From, To> accm;
14
15   ManyAccumMinMaxParser(String JavaDoc n, int max, Parser<A> p, int min, Accumulatable<From, To> accm) {
16     super(n);
17     this.max = max;
18     this.p = p;
19     this.min = min;
20     this.accm = accm;
21   }
22
23   boolean apply(final ParseContext ctxt) {
24     final Accumulator<From, To> acc = accm.getAccumulator();
25     if (!ParserInternals.accm_repeat(acc, min, p, ctxt))
26       return false;
27     if (ParserInternals.accm_some(acc, max - min, p, ctxt))
28       return ParserInternals.returnValue(acc.getResult(), ctxt);
29     else
30       return false;
31   }
32 }
Popular Tags