Source code: alice/util/jedit/Token.java
1 /*
2 * Token.java - Generic token
3 * Copyright (C) 1998, 1999 Slava Pestov
4 *
5 * You may use and modify this package for any purpose. Redistribution is
6 * permitted, in both source and binary form, provided that this notice
7 * remains intact in all source distributions of this package.
8 */
9 package alice.util.jedit;
10
11 /**
12 * A linked list of tokens. Each token has three fields - a token
13 * identifier, which is a byte value that can be looked up in the
14 * array returned by <code>SyntaxDocument.getColors()</code>
15 * to get a color value, a length value which is the length of the
16 * token in the text, and a pointer to the next token in the list.
17 *
18 * @author Slava Pestov
19 * @version $Id: Token.java,v 1.12 1999/12/13 03:40:30 sp Exp $
20 */
21 public class Token
22 {
23 /**
24 * Normal text token id. This should be used to mark
25 * normal text.
26 */
27 public static final byte NULL = 0;
28
29 /**
30 * Comment 1 token id. This can be used to mark a comment.
31 */
32 public static final byte COMMENT1 = 1;
33
34 /**
35 * Comment 2 token id. This can be used to mark a comment.
36 */
37 public static final byte COMMENT2 = 2;
38
39
40 /**
41 * Literal 1 token id. This can be used to mark a string
42 * literal (eg, C mode uses this to mark "..." literals)
43 */
44 public static final byte LITERAL1 = 3;
45
46 /**
47 * Literal 2 token id. This can be used to mark an object
48 * literal (eg, Java mode uses this to mark true, false, etc)
49 */
50 public static final byte LITERAL2 = 4;
51
52 /**
53 * Label token id. This can be used to mark labels
54 * (eg, C mode uses this to mark ...: sequences)
55 */
56 public static final byte LABEL = 5;
57
58 /**
59 * Keyword 1 token id. This can be used to mark a
60 * keyword. This should be used for general language
61 * constructs.
62 */
63 public static final byte KEYWORD1 = 6;
64
65 /**
66 * Keyword 2 token id. This can be used to mark a
67 * keyword. This should be used for preprocessor
68 * commands, or variables.
69 */
70 public static final byte KEYWORD2 = 7;
71
72 /**
73 * Keyword 3 token id. This can be used to mark a
74 * keyword. This should be used for data types.
75 */
76 public static final byte KEYWORD3 = 8;
77
78 /**
79 * Operator token id. This can be used to mark an
80 * operator. (eg, SQL mode marks +, -, etc with this
81 * token type)
82 */
83 public static final byte OPERATOR = 9;
84
85 /**
86 * Invalid token id. This can be used to mark invalid
87 * or incomplete tokens, so the user can easily spot
88 * syntax errors.
89 */
90 public static final byte INVALID = 10;
91
92 /**
93 * The total number of defined token ids.
94 */
95 public static final byte ID_COUNT = 11;
96
97 /**
98 * The first id that can be used for internal state
99 * in a token marker.
100 */
101 public static final byte INTERNAL_FIRST = 100;
102
103 /**
104 * The last id that can be used for internal state
105 * in a token marker.
106 */
107 public static final byte INTERNAL_LAST = 126;
108
109 /**
110 * The token type, that along with a length of 0
111 * marks the end of the token list.
112 */
113 public static final byte END = 127;
114
115 /**
116 * The length of this token.
117 */
118 public int length;
119
120 /**
121 * The id of this token.
122 */
123 public byte id;
124
125 /**
126 * The next token in the linked list.
127 */
128 public Token next;
129
130 /**
131 * Creates a new token.
132 * @param length The length of the token
133 * @param id The id of the token
134 */
135 public Token(int length, byte id)
136 {
137 this.length = length;
138 this.id = id;
139 }
140
141 /**
142 * Returns a string representation of this token.
143 */
144 public String toString()
145 {
146 return "[id=" + id + ",length=" + length + "]";
147 }
148 }