KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > syntax > Token


1 /*
2  * Token.java - Syntax token
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 1998, 1999, 2000, 2001, 2002 Slava Pestov
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */

22 package org.gjt.sp.jedit.syntax;
23
24 import java.lang.reflect.Field JavaDoc;
25
26 /**
27  * A linked list of syntax tokens.
28  *
29  * @author Slava Pestov
30  * @version $Id: Token.java 5354 2006-03-03 16:18:06Z ezust $
31  */

32 public class Token
33 {
34     //{{{ stringToToken() method
35
/**
36      * Converts a token type string to a token type constant.
37      * @param value The token type
38      * @since jEdit 4.1pre1
39      */

40     public static byte stringToToken(String JavaDoc value)
41     {
42         try
43         {
44             Field JavaDoc f = Token.class.getField(value);
45             return f.getByte(null);
46         }
47         catch(Exception JavaDoc e)
48         {
49             return -1;
50         }
51     } //}}}
52

53     //{{{ tokenToString() method
54
/**
55      * Converts a token type constant to a token type string.
56      * @since jEdit 4.2pre1
57      */

58     public static String JavaDoc tokenToString(byte token)
59     {
60         return TOKEN_TYPES[token];
61     } //}}}
62

63     //{{{ Token types
64
public static final String JavaDoc[] TOKEN_TYPES = new String JavaDoc[] {
65         "NULL",
66         "COMMENT1",
67         "COMMENT2",
68         "COMMENT3",
69         "COMMENT4",
70         "DIGIT",
71         "FUNCTION",
72         "INVALID",
73         "KEYWORD1",
74         "KEYWORD2",
75         "KEYWORD3",
76         "KEYWORD4",
77         "LABEL",
78         "LITERAL1",
79         "LITERAL2",
80         "LITERAL3",
81         "LITERAL4",
82         "MARKUP",
83         "OPERATOR"
84     };
85
86     public static final byte NULL = 0;
87
88     public static final byte COMMENT1 = 1;
89     public static final byte COMMENT2 = 2;
90     public static final byte COMMENT3 = 3;
91     public static final byte COMMENT4 = 4;
92     public static final byte DIGIT = 5;
93     public static final byte FUNCTION = 6;
94     public static final byte INVALID = 7;
95     public static final byte KEYWORD1 = 8;
96     public static final byte KEYWORD2 = 9;
97     public static final byte KEYWORD3 = 10;
98     public static final byte KEYWORD4 = 11;
99     public static final byte LABEL = 12;
100     public static final byte LITERAL1 = 13;
101     public static final byte LITERAL2 = 14;
102     public static final byte LITERAL3 = 15;
103     public static final byte LITERAL4 = 16;
104     public static final byte MARKUP = 17;
105     public static final byte OPERATOR = 18;
106     //}}}
107

108     public static final byte ID_COUNT = 19;
109
110     // Special:
111
public static final byte END = 127;
112
113     //{{{ Instance variables
114
/**
115      * The id of this token.
116      */

117     public byte id;
118
119     /**
120      * The start offset of this token.
121      */

122     public int offset;
123
124     /**
125      * The length of this token.
126      */

127     public int length;
128
129     /**
130      * The rule set of this token.
131      */

132     public ParserRuleSet rules;
133
134     /**
135      * The next token in the linked list.
136      */

137     public Token next;
138     //}}}
139

140     //{{{ Token constructor
141
/**
142      * Creates a new token.
143      * @param id The id of the token
144      * @param offset The start offset of the token
145      * @param length The length of the token
146      * @param rules The parser rule set that generated this token
147      */

148     public Token(byte id, int offset, int length, ParserRuleSet rules)
149     {
150         this.id = id;
151         this.offset = offset;
152         this.length = length;
153         this.rules = rules;
154     } //}}}
155

156     //{{{ toString() method
157
/**
158      * Returns a string representation of this token.
159      */

160     public String JavaDoc toString()
161     {
162         return "[id=" + id + ",offset=" + offset + ",length=" + length + "]";
163     } //}}}
164
}
165
Popular Tags