KickJava   Java API By Example, From Geeks To Geeks.

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


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-15
10  *
11  * Author Ben Yu
12  */

13 package jfun.parsec.tokens;
14
15 /**
16  * This class create some basic tokens.
17  * @author Ben Yu
18  *
19  * 2004-11-15
20  */

21 public final class Tokens {
22   /**
23    * Create a typed token.
24    * @param text the token text.
25    * @param type the token type.
26    * @return the TypedToken object.
27    * @since version 1.1
28    */

29   public static <T> TypedToken<T> createTypedToken(final String JavaDoc text, T type){
30     return new TypedToken<T>(text, type);
31   }
32   /**
33    * create a TokenReserved object.
34    * @param n the reserved word.
35    * @return the token object.
36    */

37   public static TokenReserved reserved(final String JavaDoc n){
38     return new TokenReserved(n);
39   }
40   /**
41    * create a TokenWord object.
42    * @param n the word.
43    * @return the token object.
44    */

45   public static TokenWord word(final String JavaDoc n){return new TokenWord(n);}
46   
47   /**
48    * Create a MyToken object.
49    * @param text the text.
50    * @param kind the kind.
51    * @return the token object.
52    */

53   @Deprecated JavaDoc
54   public static MyToken my(final String JavaDoc text, final int kind){
55     return new MyToken(text, kind);
56   }
57   /**
58    * create a decimal literal token object.
59    * @param s the decimal string representation.
60    * @return the token object.
61    */

62   public static TokenDecimal decimal_literal(final String JavaDoc s){
63     return new TokenDecimal(s);
64   }
65   /**
66    * create a character literal token.
67    * @param c the character.
68    * @return the token object.
69    */

70   public static Character JavaDoc char_literal(final char c){
71     return new Character JavaDoc(c);
72   }
73   /**
74    * Create a integer litgeral token
75    * @param n the number
76    * @return the token object.
77    * @deprecated use {@link #long_literal(long)} instead.
78    */

79   public static Long JavaDoc int_literal(final long n){
80     return long_literal(n);
81   }
82   /**
83    * Create a integer literal token whose value is within the range of a long integer.
84    * @param n the number
85    * @return the token object.
86    * @since version 0.6
87    */

88   public static Long JavaDoc long_literal(final long n){
89     return new Long JavaDoc(n);
90   }
91   /**
92    * Create a quoted string token.
93    * @param open the open quote
94    * @param close the close quote
95    * @param s the quoted string
96    * @return the token object.
97    */

98   public static TokenQuoted quoted_string(final String JavaDoc open, final String JavaDoc close, final String JavaDoc s){
99     return new TokenQuoted(open, close, s);
100   }
101   /**
102    * Create a string literal token.
103    * @param s the string literal.
104    * @return the token object.
105    */

106   public static String JavaDoc str_literal(final String JavaDoc s){
107     return s;
108   }
109   /**
110    * Get a token instance for eof.
111    * @since version 1.1
112    */

113   public static TokenEof eof(){
114     return TokenEof.instance();
115   }
116 }
117
118
Popular Tags