KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > IsTokenOfType


1 /**
2  *
3  */

4 package jfun.parsec;
5
6 import jfun.parsec.tokens.TypedToken;
7
8 abstract class IsTokenOfType<R> implements FromToken<R> {
9   private final FromString<R> f;
10
11   IsTokenOfType(FromString<R> f) {
12     super();
13     this.f = f;
14   }
15
16   public R fromToken(final Tok ptok){
17     final Object JavaDoc t = ptok.getToken();
18     if(t instanceof TypedToken){
19       final TypedToken c = (TypedToken)t;
20       if(!isOfType(c.getType()))
21         return null;
22       return f.fromString(ptok.getIndex(), ptok.getLength(), c.getName());
23     }
24     else return null;
25   }
26   public abstract boolean isOfType(Object JavaDoc type);
27 }
Popular Tags