Mercurial > projects > dwt-addons
annotate dwtx/jface/text/rules/WhitespaceRule.d @ 199:eb98a5cbfd78
Fix: potential problem with synchronized, thx torhu.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 13 Mar 2009 17:03:26 +0100 |
parents | 1a5b8f8129df |
children |
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.WhitespaceRule; |
16 | |
131 | 17 import dwtx.jface.text.rules.FastPartitioner; // packageimport |
18 import dwtx.jface.text.rules.ITokenScanner; // packageimport | |
19 import dwtx.jface.text.rules.Token; // packageimport | |
20 import dwtx.jface.text.rules.RuleBasedScanner; // packageimport | |
21 import dwtx.jface.text.rules.EndOfLineRule; // packageimport | |
22 import dwtx.jface.text.rules.WordRule; // 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.RuleBasedDamagerRepairer; // packageimport | |
30 import dwtx.jface.text.rules.ICharacterScanner; // packageimport | |
31 import dwtx.jface.text.rules.IRule; // packageimport | |
32 import dwtx.jface.text.rules.DefaultDamagerRepairer; // packageimport | |
33 import dwtx.jface.text.rules.IToken; // packageimport | |
34 import dwtx.jface.text.rules.IPartitionTokenScanner; // packageimport | |
35 import dwtx.jface.text.rules.MultiLineRule; // packageimport | |
36 import dwtx.jface.text.rules.RuleBasedPartitioner; // packageimport | |
37 import dwtx.jface.text.rules.RuleBasedPartitionScanner; // packageimport | |
38 import dwtx.jface.text.rules.BufferedRuleBasedScanner; // packageimport | |
39 import dwtx.jface.text.rules.IWhitespaceDetector; // packageimport | |
40 | |
129 | 41 import dwt.dwthelper.utils; |
42 | |
43 | |
44 import dwtx.core.runtime.Assert; | |
45 | |
46 | |
47 /** | |
48 * An implementation of <code>IRule</code> capable of detecting whitespace. | |
49 * A whitespace rule uses a whitespace detector in order to find out which | |
50 * characters are whitespace characters. | |
51 * | |
52 * @see IWhitespaceDetector | |
53 */ | |
54 public class WhitespaceRule : IRule { | |
55 | |
56 /** The whitespace detector used by this rule */ | |
57 protected IWhitespaceDetector fDetector; | |
58 | |
59 /** | |
60 * Creates a rule which, with the help of an | |
61 * whitespace detector, will return a whitespace | |
62 * token when a whitespace is detected. | |
63 * | |
64 * @param detector the rule's whitespace detector, may not be <code>null</code> | |
65 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
66 public this(IWhitespaceDetector detector) { |
162 | 67 Assert.isNotNull(cast(Object)detector); |
129 | 68 fDetector= detector; |
69 } | |
70 | |
71 /* | |
72 * @see IRule#evaluate(ICharacterScanner) | |
73 */ | |
74 public IToken evaluate(ICharacterScanner scanner) { | |
75 int c= scanner.read(); | |
162 | 76 if (fDetector.isWhitespace(cast(char) c)) { |
129 | 77 do { |
78 c= scanner.read(); | |
162 | 79 } while (fDetector.isWhitespace(cast(char) c)); |
129 | 80 scanner.unread(); |
81 return Token.WHITESPACE; | |
82 } | |
83 | |
84 scanner.unread(); | |
85 return Token.UNDEFINED; | |
86 } | |
87 } |