KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > Map3Parser


1 /**
2  *
3  */

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