KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > NotConsumedParser


1 /**
2  *
3  */

4 package jfun.parsec;
5
6 final class NotConsumedParser<R> extends Parser<R> {
7   private final Parser<R> p;
8
9   private final String JavaDoc err;
10
11   NotConsumedParser(String JavaDoc n, Parser<R> p, String JavaDoc err) {
12     super(n);
13     this.p = p;
14     this.err = err;
15   }
16
17   boolean apply(final ParseContext ctxt) {
18     final int step = ctxt.getStep();
19     final int at = ctxt.getAt();
20     if (!p.parse(ctxt))
21       return false;
22     if (ctxt.getAt() == at)
23       return true;
24     ctxt.setAt(step, at);
25     return ParserInternals.raiseRaw(err, ctxt);
26   }
27 }
Popular Tags