f5a05aeee026701d32ed559f201cd28b1ed3f699
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.js.core / src / net / sourceforge / phpeclipse / js / core / parser / JSPartitionScanner.java
1 /*
2  * $RCSfile: JSPartitionScanner.java,v $
3  *
4  * Copyright 2002
5  * CH-1700 Fribourg, Switzerland
6  * All rights reserved.
7  *
8  *========================================================================
9  * Modifications history
10  *========================================================================
11  * $Log: not supported by cvs2svn $
12  * Revision 1.1  2004/02/26 02:25:42  agfitzp
13  * renamed packages to match xml & css
14  *
15  * Revision 1.1  2004/02/05 03:10:08  agfitzp
16  * Initial Submission
17  *
18  * Revision 1.1.2.1  2003/12/12 21:37:24  agfitzp
19  * Experimental work for Classes view
20  *
21  * Revision 1.3  2003/05/30 20:53:09  agfitzp
22  * 0.0.2 : Outlining is now done as the user types. Some other bug fixes.
23  *
24  * Revision 1.2  2003/05/28 20:47:58  agfitzp
25  * Outline the document, not the file.
26  *
27  * Revision 1.1  2003/05/28 15:17:12  agfitzp
28  * net.sourceforge.phpeclipse.js.core 0.0.1 code base
29  *
30  *========================================================================
31 */
32
33 package net.sourceforge.phpeclipse.js.core.parser;
34
35 import java.util.ArrayList;
36 import java.util.List;
37 //import org.eclipse.jface.text.IDocument;
38 import org.eclipse.jface.text.rules.*;
39
40 /**
41  * 
42  *
43  * @author $Author: jsurfer $, $Date: 2004-09-02 18:14:38 $
44  *
45  * @version $Revision: 1.1 $
46  */
47 public class JSPartitionScanner extends RuleBasedPartitionScanner {
48         public final static String JS_DEFAULT = "__js_default";
49         public final static String JS_COMMENT = "__js_comment";
50         public final static String JS_KEYWORD = "__js_keyword";
51         public final static String JS_STRING = "__js_string";
52
53         public final static IToken TOKEN_STRING = new Token(JS_STRING);
54         public final static IToken TOKEN_COMMENT = new Token(JS_COMMENT);
55         public final static IToken TOKEN_DEFAULT = new Token(JS_DEFAULT);
56         public final static IToken TOKEN_KEYWORD = new Token(JS_KEYWORD);
57
58         /**
59          * Array of keyword token strings.
60          */
61         private static String[] keywordTokens= {
62                 "break", 
63                 "case", "catch", "continue", 
64                 "default", "do", 
65                 "else", 
66                 "for", "function",
67                 "goto", 
68                 "if", "in", 
69                 "new", 
70                 "return",
71                 "switch",
72                 "this", "throw", "try",
73                 "var", "void",
74                 "while", "with"
75         };
76
77         /**
78          * Array of constant token strings.
79          */
80         private static String[] constantTokens= { "false", "null", "true" };
81
82
83         /**
84          * Creates a new JSPartitionScanner object.
85          */
86         public JSPartitionScanner() {
87                 List rules = new ArrayList();
88
89                 rules.add(new MultiLineRule("/*", "*/", TOKEN_COMMENT));
90                 rules.add(new SingleLineRule("//", "", TOKEN_COMMENT));
91                 rules.add(new SingleLineRule("\"", "\"", TOKEN_STRING, '\\'));
92                 rules.add(new SingleLineRule("'", "'", TOKEN_STRING, '\\'));
93                 
94                 PredicateWordRule keywordRule = new PredicateWordRule(new JSWordDetector(), TOKEN_DEFAULT, keywordTokens, TOKEN_KEYWORD);
95                 keywordRule.addWords(constantTokens, TOKEN_KEYWORD);
96                 rules.add(keywordRule);
97                 
98                 setRuleList(rules);
99         }
100
101
102         private void setRuleList(List rules)
103         {
104                 IPredicateRule[] result = new IPredicateRule[rules.size()];
105                 rules.toArray(result);
106                 setPredicateRules(result);
107         }
108 }