129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13
|
|
14 module dwtx.jface.text.rules.Token;
|
|
15
|
|
16 import dwt.dwthelper.utils;
|
|
17
|
|
18 import dwtx.core.runtime.Assert;
|
|
19
|
|
20
|
|
21 /**
|
|
22 * Standard implementation of <code>IToken</code>.
|
|
23 */
|
|
24 public class Token : IToken {
|
|
25
|
|
26 /** Internal token type: Undefined */
|
|
27 private static final int T_UNDEFINED= 0;
|
|
28 /** Internal token type: EOF */
|
|
29 private static final int T_EOF= 1;
|
|
30 /** Internal token type: Whitespace */
|
|
31 private static final int T_WHITESPACE= 2;
|
|
32 /** Internal token type: Others */
|
|
33 private static final int T_OTHER= 3;
|
|
34
|
|
35
|
|
36 /**
|
|
37 * Standard token: Undefined.
|
|
38 */
|
|
39 public static final IToken UNDEFINED= new Token(T_UNDEFINED);
|
|
40 /**
|
|
41 * Standard token: End Of File.
|
|
42 */
|
|
43 public static final IToken EOF= new Token(T_EOF);
|
|
44 /**
|
|
45 * Standard token: Whitespace.
|
|
46 */
|
|
47 public static final IToken WHITESPACE= new Token(T_WHITESPACE);
|
|
48
|
|
49 /**
|
|
50 * Standard token: Neither {@link #UNDEFINED}, {@link #WHITESPACE}, nor {@link #EOF}.
|
|
51 * @deprecated will be removed
|
|
52 */
|
|
53 public static final IToken OTHER= new Token(T_OTHER);
|
|
54
|
|
55 /** The type of this token */
|
|
56 private int fType;
|
|
57 /** The data associated with this token */
|
|
58 private Object fData;
|
|
59
|
|
60 /**
|
|
61 * Creates a new token according to the given specification which does not
|
|
62 * have any data attached to it.
|
|
63 *
|
|
64 * @param type the type of the token
|
|
65 * @since 2.0
|
|
66 */
|
|
67 private Token(int type) {
|
|
68 fType= type;
|
|
69 fData= null;
|
|
70 }
|
|
71
|
|
72 /**
|
|
73 * Creates a new token which represents neither undefined, whitespace, nor EOF.
|
|
74 * The newly created token has the given data attached to it.
|
|
75 *
|
|
76 * @param data the data attached to the newly created token
|
|
77 */
|
|
78 public Token(Object data) {
|
|
79 fType= T_OTHER;
|
|
80 fData= data;
|
|
81 }
|
|
82
|
|
83 /**
|
|
84 * Re-initializes the data of this token. The token may not represent
|
|
85 * undefined, whitespace, or EOF.
|
|
86 *
|
|
87 * @param data to be attached to the token
|
|
88 * @since 2.0
|
|
89 */
|
|
90 public void setData(Object data) {
|
|
91 Assert.isTrue(isOther());
|
|
92 fData= data;
|
|
93 }
|
|
94
|
|
95 /*
|
|
96 * @see IToken#getData()
|
|
97 */
|
|
98 public Object getData() {
|
|
99 return fData;
|
|
100 }
|
|
101
|
|
102 /*
|
|
103 * @see IToken#isOther()
|
|
104 */
|
|
105 public bool isOther() {
|
|
106 return (fType is T_OTHER);
|
|
107 }
|
|
108
|
|
109 /*
|
|
110 * @see IToken#isEOF()
|
|
111 */
|
|
112 public bool isEOF() {
|
|
113 return (fType is T_EOF);
|
|
114 }
|
|
115
|
|
116 /*
|
|
117 * @see IToken#isWhitespace()
|
|
118 */
|
|
119 public bool isWhitespace() {
|
|
120 return (fType is T_WHITESPACE);
|
|
121 }
|
|
122
|
|
123 /*
|
|
124 * @see IToken#isUndefined()
|
|
125 */
|
|
126 public bool isUndefined() {
|
|
127 return (fType is T_UNDEFINED);
|
|
128 }
|
|
129 }
|