Mercurial > projects > dwt-addons
annotate dwtx/jface/text/rules/Token.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | eb21d3dfc767 |
children | eb98a5cbfd78 |
rev | line source |
---|---|
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 | |
131 | 14 |
151 | 15 module dwtx.jface.text.rules.Token; |
16 | |
131 | 17 import dwtx.jface.text.rules.FastPartitioner; // packageimport |
18 import dwtx.jface.text.rules.ITokenScanner; // packageimport | |
19 import dwtx.jface.text.rules.RuleBasedScanner; // packageimport | |
20 import dwtx.jface.text.rules.EndOfLineRule; // packageimport | |
21 import dwtx.jface.text.rules.WordRule; // packageimport | |
22 import dwtx.jface.text.rules.WhitespaceRule; // packageimport | |
23 import dwtx.jface.text.rules.WordPatternRule; // packageimport | |
24 import dwtx.jface.text.rules.IPredicateRule; // packageimport | |
25 import dwtx.jface.text.rules.DefaultPartitioner; // packageimport | |
26 import dwtx.jface.text.rules.NumberRule; // packageimport | |
27 import dwtx.jface.text.rules.SingleLineRule; // packageimport | |
28 import dwtx.jface.text.rules.PatternRule; // packageimport | |
29 import dwtx.jface.text.rules.IWordDetector; // packageimport | |
30 import dwtx.jface.text.rules.RuleBasedDamagerRepairer; // packageimport | |
31 import dwtx.jface.text.rules.ICharacterScanner; // packageimport | |
32 import dwtx.jface.text.rules.IRule; // packageimport | |
33 import dwtx.jface.text.rules.DefaultDamagerRepairer; // packageimport | |
34 import dwtx.jface.text.rules.IToken; // packageimport | |
35 import dwtx.jface.text.rules.IPartitionTokenScanner; // packageimport | |
36 import dwtx.jface.text.rules.MultiLineRule; // packageimport | |
37 import dwtx.jface.text.rules.RuleBasedPartitioner; // packageimport | |
38 import dwtx.jface.text.rules.RuleBasedPartitionScanner; // packageimport | |
39 import dwtx.jface.text.rules.BufferedRuleBasedScanner; // packageimport | |
40 import dwtx.jface.text.rules.IWhitespaceDetector; // packageimport | |
41 | |
129 | 42 import dwt.dwthelper.utils; |
43 | |
44 import dwtx.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 */ | |
147 | 53 private static const int T_UNDEFINED= 0; |
129 | 54 /** Internal token type: EOF */ |
147 | 55 private static const int T_EOF= 1; |
129 | 56 /** Internal token type: Whitespace */ |
147 | 57 private static const int T_WHITESPACE= 2; |
129 | 58 /** Internal token type: Others */ |
147 | 59 private static const int T_OTHER= 3; |
129 | 60 |
61 | |
62 /** | |
63 * Standard token: Undefined. | |
64 */ | |
162 | 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 } | |
129 | 76 /** |
77 * Standard token: End Of File. | |
78 */ | |
162 | 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 } | |
129 | 90 /** |
91 * Standard token: Whitespace. | |
92 */ | |
162 | 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 } | |
129 | 104 |
105 /** | |
106 * Standard token: Neither {@link #UNDEFINED}, {@link #WHITESPACE}, nor {@link #EOF}. | |
107 * @deprecated will be removed | |
108 */ | |
162 | 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 } | |
129 | 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
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
133 private this(int type) { |
129 | 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 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
144 public this(Object data) { |
129 | 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 } |