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