KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > AllBinders


1 /**
2  *
3  */

4 package jfun.parsec;
5
6 final class AllBinders<T> implements ToParser<T, T> {
7   private final String JavaDoc name;
8
9   private final ToParser<T, T>[] binders;
10
11   AllBinders(String JavaDoc name, ToParser<T, T>[] binders) {
12     super();
13     this.name = name;
14     this.binders = binders;
15   }
16
17   public Parser<T> toParser(final T v) {
18     return new Parser<T>(name) {
19       boolean apply(final ParseContext ctxt) {
20         T val = v;
21         for (int i = 0; i < binders.length; i++) {
22           final ToParser<T, T> pb = binders[i];
23           final Parser<T> p = pb.toParser(val);
24           if (!p.parse(ctxt))
25             return false;
26           val = p.getReturn(ctxt);
27         }
28         return true;
29       }
30     };
31   }
32 }
Popular Tags