KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > tokens > TokenCharLiteral


1 /*****************************************************************************
2  * Copyright (C) Zephyr Business Solutions Corp. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8 /*
9  * Created on 2004-11-7
10  *
11  * Author Ben Yu
12  */

13 package jfun.parsec.tokens;
14
15 import jfun.parsec.Tokenizer;
16
17 /**
18  * Represents a character.
19  * @author Ben Yu
20  *
21  * 2004-11-7
22  */

23 @Deprecated JavaDoc
24 public class TokenCharLiteral implements java.io.Serializable JavaDoc{
25   /**
26    * convert the characters contained in range [from, from+len)
27    * to a character.
28    * @param cs the character sequence.
29    * @param from the starting index.
30    * @param len the length of the range.
31    * @return the character.
32    */

33   public static char tokenize(final CharSequence JavaDoc cs,
34       final int from, final int len){
35     if(len == 3){
36       return cs.charAt(from+1);
37     }
38     else if(len == 4){
39       return cs.charAt(from+2);
40     }
41     else throw new IllegalStateException JavaDoc("illegal char");
42   }
43   private TokenCharLiteral(){}
44   private static final Tokenizer cTokenizer = new Tokenizer(){
45     public Object JavaDoc toToken(final CharSequence JavaDoc cs,
46         final int from, final int len){
47       return new Character JavaDoc(tokenize(cs, from, len));
48     };
49   };
50   /**
51    * Creates a tokenizer that's gonna tokenize a single quoted character literal possibly with escape character '\'
52    * @return the tokenizer instance.
53    */

54   public static Tokenizer getTokenizer(){return cTokenizer;}
55 }
56
Popular Tags