KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > MapParser


1 /**
2  *
3  */

4 package jfun.parsec;
5
6 final class MapParser<R, From> extends Parser<R> {
7   private final Parser<From> p;
8
9   private final Map<? super From, R> m;
10
11   MapParser(String JavaDoc n, Parser<From> p, Map<? super From, R> m) {
12     super(n);
13     this.p = p;
14     this.m = m;
15   }
16
17   boolean apply(final ParseContext ctxt) {
18     final boolean r = p.parse(ctxt);
19     if (r) {
20       ctxt.setReturn(m.map(p.getReturn(ctxt)));
21     }
22     return r;
23   }
24 }
Popular Tags