2 * Created on May 16, 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
10 * Revision 1.1 2004/02/05 03:10:08 agfitzp
13 * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp
14 * Experimental work for Classes view
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.
19 *========================================================================
21 package net.sourceforge.phpeclipse.js.core.parser;
23 import java.util.ArrayList;
24 import java.util.List;
25 import org.eclipse.jface.text.rules.*;
28 * Scanner for detecting syntactic elements: comments, strings, classes, functions
33 public class JSSyntaxScanner extends BufferedRuleBasedScanner {
34 public final static String JS_DEFAULT = "__js_default";
35 public final static String JS_COMMENT = "__js_comment";
36 public final static String JS_FUNCTION = "__js_function";
37 public final static String JS_STRING = "__js_string";
38 public final static String JS_MEMBER = "__js_member";
39 public final static String JS_PERIOD = "__js_period";
41 public final static IToken TOKEN_STRING = new Token(JS_STRING);
42 public final static IToken TOKEN_COMMENT = new Token(JS_COMMENT);
43 public final static IToken TOKEN_DEFAULT = new Token(JS_DEFAULT);
44 public final static IToken TOKEN_FUNCTION = new Token(JS_FUNCTION);
45 public final static IToken TOKEN_MEMBER = new Token(JS_MEMBER);
46 public final static IToken TOKEN_PERIOD = new Token(JS_PERIOD);
49 * String for detecting member declarations.
51 private static String memberToken= ".prototype";
54 * Creates a new JSSyntaxScanner object.
56 public JSSyntaxScanner() {
57 List rules = new ArrayList();
59 rules.add(new MultiLineRule("/*", "*/", TOKEN_COMMENT));
60 rules.add(new SingleLineRule("//", "", TOKEN_COMMENT));
61 rules.add(new SingleLineRule("\"", "\"", TOKEN_STRING, '\\'));
62 rules.add(new SingleLineRule("'", "'", TOKEN_STRING, '\\'));
64 rules.add(new WhitespaceRule(new JSWhitespaceDetector()));
66 rules.add(new MultiLineRule("function(", ")", TOKEN_FUNCTION));
67 rules.add(new MultiLineRule("function ", ")", TOKEN_FUNCTION));
69 rules.add(new WordRule(new JSWordDetector(), TOKEN_DEFAULT));
70 rules.add(new PredicateWordRule(new JSReferenceDetector(), memberToken, TOKEN_MEMBER));
80 private void setRuleList(List rules)
82 IRule[] result = new IRule[rules.size()];
83 rules.toArray(result);