KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jedit.syntax;
2
3 /*
4  * Token.java - Generic token
5  * Copyright (C) 1998, 1999 Slava Pestov
6  *
7  * You may use and modify this package for any purpose. Redistribution is
8  * permitted, in both source and binary form, provided that this notice
9  * remains intact in all source distributions of this package.
10  */

11
12 /**
13  * A linked list of tokens. Each token has three fields - a token
14  * identifier, which is a byte value that can be looked up in the
15  * array returned by <code>SyntaxDocument.getColors()</code>
16  * to get a color value, a length value which is the length of the
17  * token in the text, and a pointer to the next token in the list.
18  *
19  * @author Slava Pestov
20  * @version $Id: Token.java,v 1.1 2003/12/14 16:29:49 daggerrz Exp $
21  */

22 public class Token
23 {
24    /**
25     * Normal text token id. This should be used to mark
26     * normal text.
27     */

28    public static final byte NULL = 0;
29
30    /**
31     * Comment 1 token id. This can be used to mark a comment.
32     */

33    public static final byte COMMENT1 = 1;
34
35    /**
36     * Comment 2 token id. This can be used to mark a comment.
37     */

38    public static final byte COMMENT2 = 2;
39
40    
41    /**
42     * Literal 1 token id. This can be used to mark a string
43     * literal (eg, C mode uses this to mark "..." literals)
44     */

45    public static final byte LITERAL1 = 3;
46
47    /**
48     * Literal 2 token id. This can be used to mark an object
49     * literal (eg, Java mode uses this to mark true, false, etc)
50     */

51    public static final byte LITERAL2 = 4;
52
53    /**
54     * Label token id. This can be used to mark labels
55     * (eg, C mode uses this to mark ...: sequences)
56     */

57    public static final byte LABEL = 5;
58
59    /**
60     * Keyword 1 token id. This can be used to mark a
61     * keyword. This should be used for general language
62     * constructs.
63     */

64    public static final byte KEYWORD1 = 6;
65
66    /**
67     * Keyword 2 token id. This can be used to mark a
68     * keyword. This should be used for preprocessor
69     * commands, or variables.
70     */

71    public static final byte KEYWORD2 = 7;
72
73    /**
74     * Keyword 3 token id. This can be used to mark a
75     * keyword. This should be used for data types.
76     */

77    public static final byte KEYWORD3 = 8;
78
79    /**
80     * Operator token id. This can be used to mark an
81     * operator. (eg, SQL mode marks +, -, etc with this
82     * token type)
83     */

84    public static final byte OPERATOR = 9;
85
86    /**
87     * Invalid token id. This can be used to mark invalid
88     * or incomplete tokens, so the user can easily spot
89     * syntax errors.
90     */

91    public static final byte INVALID = 10;
92
93    /**
94     * The total number of defined token ids.
95     */

96    public static final byte ID_COUNT = 11;
97
98    /**
99     * The first id that can be used for internal state
100     * in a token marker.
101     */

102    public static final byte INTERNAL_FIRST = 100;
103
104    /**
105     * The last id that can be used for internal state
106     * in a token marker.
107     */

108    public static final byte INTERNAL_LAST = 126;
109
110    /**
111     * The token type, that along with a length of 0
112     * marks the end of the token list.
113     */

114    public static final byte END = 127;
115
116    /**
117     * The length of this token.
118     */

119    public int length;
120
121    /**
122     * The id of this token.
123     */

124    public byte id;
125
126    /**
127     * The next token in the linked list.
128     */

129    public Token next;
130
131    /**
132     * Creates a new token.
133     * @param length The length of the token
134     * @param id The id of the token
135     */

136    public Token(int length, byte id)
137    {
138       this.length = length;
139       this.id = id;
140    }
141
142    /**
143     * Returns a string representation of this token.
144     */

145    public String JavaDoc toString()
146    {
147       return "[id=" + id + ",length=" + length + "]";
148    }
149 }
150
Popular Tags