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