2
|
1 |
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
|
2 |
// Use of this source code is governed by a BSD-style license that can be
|
|
3 |
// found in the LICENSE file.
|
|
4 |
|
|
5 |
package org.chromium.debug.ui.editors;
|
|
6 |
|
|
7 |
import org.eclipse.jface.text.rules.EndOfLineRule;
|
|
8 |
import org.eclipse.jface.text.rules.ICharacterScanner;
|
|
9 |
import org.eclipse.jface.text.rules.IPredicateRule;
|
|
10 |
import org.eclipse.jface.text.rules.IToken;
|
|
11 |
import org.eclipse.jface.text.rules.IWordDetector;
|
|
12 |
import org.eclipse.jface.text.rules.MultiLineRule;
|
|
13 |
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
|
|
14 |
import org.eclipse.jface.text.rules.SingleLineRule;
|
|
15 |
import org.eclipse.jface.text.rules.Token;
|
|
16 |
import org.eclipse.jface.text.rules.WordRule;
|
|
17 |
|
|
18 |
/**
|
|
19 |
* JavaScript partition scanner.
|
|
20 |
*/
|
|
21 |
public class JsPartitionScanner extends RuleBasedPartitionScanner {
|
|
22 |
|
|
23 |
static final String PARTITIONING = "ChromiumJavaScriptPartitioning"; //$NON-NLS-1$
|
|
24 |
static final String MULTILINE_COMMENT= "__js_multiline_comment"; //$NON-NLS-1$
|
|
25 |
static final String JSDOC = "__jsdoc"; //$NON-NLS-1$
|
|
26 |
static final String[] PARTITION_TYPES = {
|
|
27 |
MULTILINE_COMMENT,
|
|
28 |
JSDOC
|
|
29 |
};
|
|
30 |
|
|
31 |
/**
|
|
32 |
* Empty comments should be handled so as not to be confused with JSDoc.
|
|
33 |
*/
|
|
34 |
private static class EmptyCommentDetector implements IWordDetector {
|
|
35 |
|
|
36 |
public boolean isWordStart(char c) {
|
|
37 |
return (c == '/');
|
|
38 |
}
|
|
39 |
|
|
40 |
public boolean isWordPart(char c) {
|
|
41 |
return (c == '*' || c == '/');
|
|
42 |
}
|
|
43 |
}
|
|
44 |
|
|
45 |
private static class EmptyCommentPredicateRule extends WordRule implements IPredicateRule {
|
|
46 |
private final IToken successToken;
|
|
47 |
|
|
48 |
public EmptyCommentPredicateRule(IToken successToken) {
|
|
49 |
super(new EmptyCommentDetector());
|
|
50 |
this.successToken = successToken;
|
|
51 |
addWord("/**/", successToken); //$NON-NLS-1$
|
|
52 |
}
|
|
53 |
|
|
54 |
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
|
|
55 |
return super.evaluate(scanner);
|
|
56 |
}
|
|
57 |
|
|
58 |
public IToken getSuccessToken() {
|
|
59 |
return successToken;
|
|
60 |
}
|
|
61 |
}
|
|
62 |
|
|
63 |
public JsPartitionScanner() {
|
|
64 |
IToken jsDocToken= new Token(JSDOC);
|
|
65 |
IToken multilineCommentToken= new Token(MULTILINE_COMMENT);
|
|
66 |
|
|
67 |
setPredicateRules(new IPredicateRule[] {
|
|
68 |
new EndOfLineRule("//", Token.UNDEFINED), //$NON-NLS-1$
|
|
69 |
new SingleLineRule("\"", "\"", Token.UNDEFINED, '\\'), //$NON-NLS-2$ //$NON-NLS-1$
|
|
70 |
new SingleLineRule("'", "'", Token.UNDEFINED, '\\'), //$NON-NLS-2$ //$NON-NLS-1$
|
|
71 |
new EmptyCommentPredicateRule(multilineCommentToken),
|
|
72 |
new MultiLineRule("/**", "*/", jsDocToken, (char) 0, true), //$NON-NLS-1$ //$NON-NLS-2$
|
|
73 |
new MultiLineRule("/*", "*/", multilineCommentToken, (char) 0, true) //$NON-NLS-1$ //$NON-NLS-2$
|
|
74 |
});
|
|
75 |
}
|
|
76 |
}
|