KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > Map4Parser


1 /**
2  *
3  */

4 package jfun.parsec;
5
6 final class Map4Parser<R, A, B, C, D> extends Parser<R> {
7   private final Map4<? super A, ? super B, ? super C, ? super D, R> m4;
8
9   private final Parser<C> p3;
10
11   private final Parser<B> p2;
12
13   private final Parser<A> p1;
14
15   private final Parser<D> p4;
16
17   Map4Parser(String JavaDoc n, Map4<? super A, ? super B, ? super C, ? super D, R> m4, Parser<C> p3, Parser<B> p2, Parser<A> p1, Parser<D> p4) {
18     super(n);
19     this.m4 = m4;
20     this.p3 = p3;
21     this.p2 = p2;
22     this.p1 = p1;
23     this.p4 = p4;
24   }
25
26   boolean apply(final ParseContext ctxt) {
27     final boolean r1 = p1.parse(ctxt);
28     if (!r1)
29       return false;
30     final A o1 = p1.getReturn(ctxt);
31     final boolean r2 = p2.parse(ctxt);
32     if (!r2)
33       return false;
34     final B o2 = p2.getReturn(ctxt);
35     final boolean r3 = p3.parse(ctxt);
36     if (!r3)
37       return false;
38     final C o3 = p3.getReturn(ctxt);
39     final boolean r4 = p4.parse(ctxt);
40     if (!r4)
41       return false;
42     final D o4 = p4.getReturn(ctxt);
43     ctxt.setReturn(m4.map(o1, o2, o3, o4));
44     return true;
45   }
46 }
Popular Tags