KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > MapnParser


1 /**
2  *
3  */

4 package jfun.parsec;
5
6 final class MapnParser<R> extends Parser<R> {
7   private final Mapn<R> mn;
8
9   private final ArrayFactory<?> af;
10
11   private final Parser<?>[] ps;
12
13   MapnParser(String JavaDoc n, Mapn<R> mn, ArrayFactory<?> af, Parser<?>[] ps) {
14     super(n);
15     this.mn = mn;
16     this.af = af;
17     this.ps = ps;
18   }
19
20   boolean apply(final ParseContext ctxt) {
21     final Object JavaDoc[] ret = af.createArray(ps.length);
22     for (int i = 0; i < ps.length; i++) {
23       final Parser<?> p = ps[i];
24       if (!p.parse(ctxt))
25         return false;
26       ret[i] = p.getReturn(ctxt);
27     }
28     ctxt.setReturn(mn.map(ret));
29     return true;
30   }
31 }
Popular Tags