KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > IsTokenParser


1 /**
2  *
3  */

4 package jfun.parsec;
5
6 final class IsTokenParser<R> extends Parser<R> {
7   private final FromToken<R> ft;
8
9   IsTokenParser(String JavaDoc n, FromToken<R> ft) {
10     super(n);
11     this.ft = ft;
12   }
13
14   boolean apply(final ParseContext ctxt) {
15     if (ctxt.isEof()) {
16       ctxt.setError(ctxt.getSysUnexpected());
17       return false;
18     }
19     final Tok ptok = ctxt.getToken();
20     final Object JavaDoc v = ft.fromToken(ptok);
21     if (v == null) {
22       ctxt.setError(ctxt.getSysUnexpected());
23       return false;
24     }
25     ctxt.setReturn(v);
26     ctxt.next();
27     return true;
28   }
29 }
Popular Tags