KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > syntax > jedit > tokenmarker > Token


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * Token.java
28  *
29  */

30
31 package org.syntax.jedit.tokenmarker;
32
33 /**
34  * A linked list of tokens. Each token has three fields - a token
35  * identifier, which is a byte value that can be looked up in the
36  * array returned by <code>SyntaxDocument.getColors()</code>
37  * to get a color value, a length value which is the length of the
38  * token in the text, and a pointer to the next token in the list.
39  *
40  * @author Slava Pestov
41  * @version $Id: Token.java 932 2006-10-20 09:32:45Z gtoffoli $
42  */

43
44 public class Token
45 {
46     /**
47      * Normal text token id. This should be used to mark
48      * normal text.
49      */

50     public static final byte NULL = 0;
51
52     /**
53      * Comment 1 token id. This can be used to mark a comment.
54      */

55     public static final byte COMMENT1 = 1;
56
57     /**
58      * Comment 2 token id. This can be used to mark a comment.
59      */

60     public static final byte COMMENT2 = 2;
61
62     
63     /**
64      * Literal 1 token id. This can be used to mark a string
65      * literal (eg, C mode uses this to mark "..." literals)
66      */

67     public static final byte LITERAL1 = 3;
68
69     /**
70      * Literal 2 token id. This can be used to mark an object
71      * literal (eg, Java mode uses this to mark true, false, etc)
72      */

73     public static final byte LITERAL2 = 4;
74
75     /**
76      * Label token id. This can be used to mark labels
77      * (eg, C mode uses this to mark ...: sequences)
78      */

79     public static final byte LABEL = 5;
80
81     /**
82      * Keyword 1 token id. This can be used to mark a
83      * keyword. This should be used for general language
84      * constructs.
85      */

86     public static final byte KEYWORD1 = 6;
87
88     /**
89      * Keyword 2 token id. This can be used to mark a
90      * keyword. This should be used for preprocessor
91      * commands, or variables.
92      */

93     public static final byte KEYWORD2 = 7;
94
95     /**
96      * Keyword 3 token id. This can be used to mark a
97      * keyword. This should be used for data types.
98      */

99     public static final byte KEYWORD3 = 8;
100
101     /**
102      * Operator token id. This can be used to mark an
103      * operator. (eg, SQL mode marks +, -, etc with this
104      * token type)
105      */

106     public static final byte OPERATOR = 9;
107
108     /**
109      * Invalid token id. This can be used to mark invalid
110      * or incomplete tokens, so the user can easily spot
111      * syntax errors.
112      */

113     public static final byte INVALID = 10;
114
115     public static final byte PARAMETER = 11;
116     public static final byte PARAMETER_OK = 12;
117
118     /**
119      * The total number of defined token ids.
120      */

121     public static final byte ID_COUNT = 13;
122
123     /**
124      * The first id that can be used for internal state
125      * in a token marker.
126      */

127     public static final byte INTERNAL_FIRST = 100;
128
129     /**
130      * The last id that can be used for internal state
131      * in a token marker.
132      */

133     public static final byte INTERNAL_LAST = 126;
134
135     /**
136      * The token type, that along with a length of 0
137      * marks the end of the token list.
138      */

139     public static final byte END = 127;
140
141     /**
142      * The length of this token.
143      */

144     public int length;
145
146     /**
147      * The id of this token.
148      */

149     public byte id;
150
151     /**
152      * The next token in the linked list.
153      */

154     public Token next;
155
156     /**
157      * Creates a new token.
158      * @param length The length of the token
159      * @param id The id of the token
160      */

161     public Token(int length, byte id)
162     {
163         this.length = length;
164         this.id = id;
165     }
166
167     /**
168      * Returns a string representation of this token.
169      */

170     public String JavaDoc toString()
171     {
172         return "[id=" + id + ",length=" + length + "]";
173     }
174 }
175
Popular Tags