Organized imports
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.js.core / src / net / sourceforge / phpeclipse / js / core / parser / PredicateWordRule.java
1 /*
2  * Created on May 13, 2003
3  *========================================================================
4  * Modifications history
5  *========================================================================
6  * $Log: not supported by cvs2svn $
7  * Revision 1.1  2004/09/02 18:14:38  jsurfer
8  * intial source from ttp://www.sf.net/projects/wdte
9  *
10  * Revision 1.1  2004/02/26 02:25:42  agfitzp
11  * renamed packages to match xml & css
12  *
13  * Revision 1.1  2004/02/05 03:10:08  agfitzp
14  * Initial Submission
15  *
16  * Revision 1.1.2.1  2003/12/12 21:37:24  agfitzp
17  * Experimental work for Classes view
18  *
19  * Revision 1.2  2003/05/30 20:53:09  agfitzp
20  * 0.0.2 : Outlining is now done as the user types. Some other bug fixes.
21  *
22  *========================================================================
23  */
24 package net.sourceforge.phpeclipse.js.core.parser;
25
26 import org.eclipse.jface.text.rules.ICharacterScanner;
27 import org.eclipse.jface.text.rules.IPredicateRule;
28 import org.eclipse.jface.text.rules.IToken;
29 import org.eclipse.jface.text.rules.IWordDetector;
30 import org.eclipse.jface.text.rules.Token;
31 import org.eclipse.jface.text.rules.WordRule;
32
33 /**
34  * @author fitzpata
35  */
36 public class PredicateWordRule extends WordRule implements IPredicateRule {
37
38         /* (non-Javadoc)
39          * @see org.eclipse.jface.text.rules.IPredicateRule#getSuccessToken()
40          */
41          
42         protected IToken successToken = Token.UNDEFINED;
43          
44         public void addWords(String[] tokens, IToken token)
45         {
46                 for (int i = 0; i < tokens.length; i++) {
47                         addWord(tokens[i], token);
48                 }
49                 
50         }
51          
52         public IToken getSuccessToken() {
53                 return successToken;
54         }
55
56         /* (non-Javadoc)
57          * @see org.eclipse.jface.text.rules.IPredicateRule#evaluate(org.eclipse.jface.text.rules.ICharacterScanner, boolean)
58          */
59         public IToken evaluate(ICharacterScanner scanner, boolean resume) {
60                 successToken = this.evaluate(scanner, resume);//true);
61                 return successToken;
62         }
63         
64         /**
65          * Creates a rule which, with the help of an word detector, will return the token
66          * associated with the detected word. If no token has been associated, the scanner 
67          * will be rolled back and an undefined token will be returned in order to allow 
68          * any subsequent rules to analyze the characters.
69          *
70          * @param detector the word detector to be used by this rule, may not be <code>null</code>
71          *
72          * @see #addWord
73          */
74
75         public PredicateWordRule(IWordDetector detector) {
76                 super(detector);
77         }
78
79         /**
80          * Creates a rule which, with the help of an word detector, will return the token
81          * associated with the detected word. If no token has been associated, the
82          * specified default token will be returned.
83          *
84          * @param detector the word detector to be used by this rule, may not be <code>null</code>
85          * @param defaultToken the default token to be returned on success 
86          *              if nothing else is specified, may not be <code>null</code>
87          *
88          * @see #addWord
89          */
90         public PredicateWordRule(IWordDetector detector, IToken defaultToken) {
91                 super(detector, defaultToken);
92         }
93
94
95         public PredicateWordRule(IWordDetector detector, String tokenString, IToken tokenType) {
96                 super(detector);
97                 this.addWord(tokenString, tokenType);
98         }
99         
100         public PredicateWordRule(IWordDetector detector, String[] tokens, IToken tokenType) {
101                 super(detector);
102                 this.addWords(tokens, tokenType);
103         }
104
105         public PredicateWordRule(IWordDetector detector, IToken defaultToken, String[] tokens, IToken tokenType) {
106                 super(detector, defaultToken);
107                 this.addWords(tokens, tokenType);
108         }
109
110 }