KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > AtomicParser


1 /**
2  *
3  */

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