comparison org.eclipse.jface.text/src/org/eclipse/jface/text/rules/Token.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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
15 module org.eclipse.jface.text.rules.Token;
16
17 import org.eclipse.jface.text.rules.FastPartitioner; // packageimport
18 import org.eclipse.jface.text.rules.ITokenScanner; // packageimport
19 import org.eclipse.jface.text.rules.RuleBasedScanner; // packageimport
20 import org.eclipse.jface.text.rules.EndOfLineRule; // packageimport
21 import org.eclipse.jface.text.rules.WordRule; // packageimport
22 import org.eclipse.jface.text.rules.WhitespaceRule; // packageimport
23 import org.eclipse.jface.text.rules.WordPatternRule; // packageimport
24 import org.eclipse.jface.text.rules.IPredicateRule; // packageimport
25 import org.eclipse.jface.text.rules.DefaultPartitioner; // packageimport
26 import org.eclipse.jface.text.rules.NumberRule; // packageimport
27 import org.eclipse.jface.text.rules.SingleLineRule; // packageimport
28 import org.eclipse.jface.text.rules.PatternRule; // packageimport
29 import org.eclipse.jface.text.rules.RuleBasedDamagerRepairer; // packageimport
30 import org.eclipse.jface.text.rules.ICharacterScanner; // packageimport
31 import org.eclipse.jface.text.rules.IRule; // packageimport
32 import org.eclipse.jface.text.rules.DefaultDamagerRepairer; // packageimport
33 import org.eclipse.jface.text.rules.IToken; // packageimport
34 import org.eclipse.jface.text.rules.IPartitionTokenScanner; // packageimport
35 import org.eclipse.jface.text.rules.MultiLineRule; // packageimport
36 import org.eclipse.jface.text.rules.RuleBasedPartitioner; // packageimport
37 import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; // packageimport
38 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner; // packageimport
39 import org.eclipse.jface.text.rules.IWhitespaceDetector; // packageimport
40
41 import java.lang.all;
42 import java.util.Set;
43
44 import org.eclipse.core.runtime.Assert;
45
46
47 /**
48 * Standard implementation of <code>IToken</code>.
49 */
50 public class Token : IToken {
51
52 /** Internal token type: Undefined */
53 private static const int T_UNDEFINED= 0;
54 /** Internal token type: EOF */
55 private static const int T_EOF= 1;
56 /** Internal token type: Whitespace */
57 private static const int T_WHITESPACE= 2;
58 /** Internal token type: Others */
59 private static const int T_OTHER= 3;
60
61
62 /**
63 * Standard token: Undefined.
64 */
65 public static IToken UNDEFINED_;
66 public static IToken UNDEFINED(){
67 if( UNDEFINED_ is null ){
68 synchronized( Token.classinfo ){
69 if( UNDEFINED_ is null ){
70 UNDEFINED_ = new Token(T_UNDEFINED);
71 }
72 }
73 }
74 return UNDEFINED_;
75 }
76 /**
77 * Standard token: End Of File.
78 */
79 public static IToken EOF_;
80 public static IToken EOF(){
81 if( EOF_ is null ){
82 synchronized( Token.classinfo ){
83 if( EOF_ is null ){
84 EOF_ = new Token(T_EOF);
85 }
86 }
87 }
88 return EOF_;
89 }
90 /**
91 * Standard token: Whitespace.
92 */
93 public static IToken WHITESPACE_;
94 public static IToken WHITESPACE(){
95 if( WHITESPACE_ is null ){
96 synchronized( Token.classinfo ){
97 if( WHITESPACE_ is null ){
98 WHITESPACE_ = new Token(T_WHITESPACE);
99 }
100 }
101 }
102 return WHITESPACE_;
103 }
104
105 /**
106 * Standard token: Neither {@link #UNDEFINED}, {@link #WHITESPACE}, nor {@link #EOF}.
107 * @deprecated will be removed
108 */
109 public static IToken OTHER_;
110 public static IToken OTHER(){
111 if( OTHER_ is null ){
112 synchronized( Token.classinfo ){
113 if( OTHER_ is null ){
114 OTHER_ = new Token(T_OTHER);
115 }
116 }
117 }
118 return OTHER_;
119 }
120
121 /** The type of this token */
122 private int fType;
123 /** The data associated with this token */
124 private Object fData;
125
126 /**
127 * Creates a new token according to the given specification which does not
128 * have any data attached to it.
129 *
130 * @param type the type of the token
131 * @since 2.0
132 */
133 private this(int type) {
134 fType= type;
135 fData= null;
136 }
137
138 /**
139 * Creates a new token which represents neither undefined, whitespace, nor EOF.
140 * The newly created token has the given data attached to it.
141 *
142 * @param data the data attached to the newly created token
143 */
144 public this(Object data) {
145 fType= T_OTHER;
146 fData= data;
147 }
148
149 /**
150 * Re-initializes the data of this token. The token may not represent
151 * undefined, whitespace, or EOF.
152 *
153 * @param data to be attached to the token
154 * @since 2.0
155 */
156 public void setData(Object data) {
157 Assert.isTrue(isOther());
158 fData= data;
159 }
160
161 /*
162 * @see IToken#getData()
163 */
164 public Object getData() {
165 return fData;
166 }
167
168 /*
169 * @see IToken#isOther()
170 */
171 public bool isOther() {
172 return (fType is T_OTHER);
173 }
174
175 /*
176 * @see IToken#isEOF()
177 */
178 public bool isEOF() {
179 return (fType is T_EOF);
180 }
181
182 /*
183 * @see IToken#isWhitespace()
184 */
185 public bool isWhitespace() {
186 return (fType is T_WHITESPACE);
187 }
188
189 /*
190 * @see IToken#isUndefined()
191 */
192 public bool isUndefined() {
193 return (fType is T_UNDEFINED);
194 }
195 }