2 * $RCSfile: JSPartitionScanner.java,v $
5 * CH-1700 Fribourg, Switzerland
8 *========================================================================
9 * Modifications history
10 *========================================================================
11 * $Log: not supported by cvs2svn $
12 * Revision 1.2 2004/09/15 06:52:15 agfitzp
13 * added finally keyword... finally
15 * Revision 1.1 2004/02/26 02:25:42 agfitzp
16 * renamed packages to match xml & css
18 * Revision 1.1 2004/02/05 03:10:08 agfitzp
21 * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp
22 * Experimental work for Classes view
24 * Revision 1.3 2003/05/30 20:53:09 agfitzp
25 * 0.0.2 : Outlining is now done as the user types. Some other bug fixes.
27 * Revision 1.2 2003/05/28 20:47:58 agfitzp
28 * Outline the document, not the file.
30 * Revision 1.1 2003/05/28 15:17:12 agfitzp
31 * net.sf.wdte.js.core 0.0.1 code base
33 *========================================================================
36 package net.sourceforge.phpeclipse.js.core.parser;
38 import java.util.ArrayList;
39 import java.util.List;
40 //import org.eclipse.jface.text.IDocument;
41 import org.eclipse.jface.text.rules.*;
46 * @author $Author: axelcl $, $Date: 2004-11-02 19:51:53 $
48 * @version $Revision: 1.2 $
50 public class JSPartitionScanner extends RuleBasedPartitionScanner {
51 public final static String JS_DEFAULT = "__js_default";
52 public final static String JS_COMMENT = "__js_comment";
53 public final static String JS_KEYWORD = "__js_keyword";
54 public final static String JS_STRING = "__js_string";
56 public final static IToken TOKEN_STRING = new Token(JS_STRING);
57 public final static IToken TOKEN_COMMENT = new Token(JS_COMMENT);
58 public final static IToken TOKEN_DEFAULT = new Token(JS_DEFAULT);
59 public final static IToken TOKEN_KEYWORD = new Token(JS_KEYWORD);
62 * Array of keyword token strings.
64 private static String[] keywordTokens= {
66 "case", "catch", "continue",
69 "finally", "for", "function",
75 "this", "throw", "try",
81 * Array of constant token strings.
83 private static String[] constantTokens= { "false", "null", "true" };
87 * Creates a new JSPartitionScanner object.
89 public JSPartitionScanner() {
90 List rules = new ArrayList();
92 rules.add(new MultiLineRule("/*", "*/", TOKEN_COMMENT));
93 rules.add(new SingleLineRule("//", "", TOKEN_COMMENT));
94 rules.add(new SingleLineRule("\"", "\"", TOKEN_STRING, '\\'));
95 rules.add(new SingleLineRule("'", "'", TOKEN_STRING, '\\'));
97 PredicateWordRule keywordRule = new PredicateWordRule(new JSWordDetector(), TOKEN_DEFAULT, keywordTokens, TOKEN_KEYWORD);
98 keywordRule.addWords(constantTokens, TOKEN_KEYWORD);
99 rules.add(keywordRule);
105 private void setRuleList(List rules)
107 IPredicateRule[] result = new IPredicateRule[rules.size()];
108 rules.toArray(result);
109 setPredicateRules(result);