Mercurial > projects > dwt-addons
annotate dwtx/jface/text/rules/NumberRule.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.NumberRule; |
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.WhitespaceRule; // packageimport | |
24 import dwtx.jface.text.rules.WordPatternRule; // packageimport | |
25 import dwtx.jface.text.rules.IPredicateRule; // packageimport | |
26 import dwtx.jface.text.rules.DefaultPartitioner; // 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 import dwtx.core.runtime.Assert; | |
44 | |
45 | |
46 /** | |
47 * An implementation of <code>IRule</code> detecting a numerical value. | |
48 */ | |
49 public class NumberRule : IRule { | |
50 | |
51 /** Internal setting for the un-initialized column constraint */ | |
162 | 52 protected static const int UNDEFINED= -1; |
129 | 53 /** The token to be returned when this rule is successful */ |
54 protected IToken fToken; | |
55 /** The column constraint */ | |
56 protected int fColumn= UNDEFINED; | |
57 | |
58 /** | |
59 * Creates a rule which will return the specified | |
60 * token when a numerical sequence is detected. | |
61 * | |
62 * @param token the token to be returned | |
63 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
64 public this(IToken token) { |
162 | 65 Assert.isNotNull(cast(Object)token); |
129 | 66 fToken= token; |
67 } | |
68 | |
69 /** | |
70 * Sets a column constraint for this rule. If set, the rule's token | |
71 * will only be returned if the pattern is detected starting at the | |
72 * specified column. If the column is smaller then 0, the column | |
73 * constraint is considered removed. | |
74 * | |
75 * @param column the column in which the pattern starts | |
76 */ | |
77 public void setColumnConstraint(int column) { | |
78 if (column < 0) | |
79 column= UNDEFINED; | |
80 fColumn= column; | |
81 } | |
82 | |
83 /* | |
84 * @see IRule#evaluate(ICharacterScanner) | |
85 */ | |
86 public IToken evaluate(ICharacterScanner scanner) { | |
87 int c= scanner.read(); | |
162 | 88 if (Character.isDigit(cast(char)c)) { |
129 | 89 if (fColumn is UNDEFINED || (fColumn is scanner.getColumn() - 1)) { |
90 do { | |
91 c= scanner.read(); | |
162 | 92 } while (Character.isDigit(cast(char) c)); |
129 | 93 scanner.unread(); |
94 return fToken; | |
95 } | |
96 } | |
97 | |
98 scanner.unread(); | |
99 return Token.UNDEFINED; | |
100 } | |
101 } |