1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*******************************************************************************
* Copyright (c) 2008 Phil Muldoon <pkmuldoon@picobot.org>.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Phil Muldoon <pkmuldoon@picobot.org> - initial API and implementation.
*******************************************************************************/
package org.eclipse.linuxtools.systemtap.ui.ide.editors.stp;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
import org.eclipse.jface.text.rules.EndOfLineRule;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.IWhitespaceDetector;
import org.eclipse.jface.text.rules.IWordDetector;
import org.eclipse.jface.text.rules.MultiLineRule;
import org.eclipse.jface.text.rules.SingleLineRule;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.linuxtools.systemtap.ui.editor.ColorManager;
import org.eclipse.swt.SWT;
public class STPElementScanner extends BufferedRuleBasedScanner {
private String[] keywordList= {"probe", "for", "else", "foreach", "exit", "printf", "in", "return",
"break", "global", "next", "while", "if", "delete", "#include", "function", "do",
"print", "error","log", "printd", "printdln", "println", "sprint", "sprintf", "system", "warn"};
// TODO: Not sure if we want these keywords or not. Defer for now.
// "backtrace", "caller", "caller_addr", "cpu", "egid", "euid", "execname", "gid", "is_return",
// "pexecname", "pid", "ppid", "tid", "uid", "print_backtrace", "print_regs", "print_stack",
// "stack_size", "stack_unused", "stack_used", "stp_pid", "target"};
/**
*
* Build Element scanner for Syntax Highlighting for Systemtap Editor
*
* @param manager ColorManager to source highlighting.
*
*/
public STPElementScanner(ColorManager manager) {
IToken defaultToken = new Token(new TextAttribute(manager
.getColor(STPColorConstants.DEFAULT)));
IToken keywordToken = new Token(new TextAttribute(manager
.getColor(STPColorConstants.KEYWORD),null,SWT.BOLD));
IToken commentToken = new Token(new TextAttribute(manager
.getColor(STPColorConstants.COMMENT)));
IToken stringToken = new Token(new TextAttribute(manager
.getColor(STPColorConstants.STP_STRING)));
// Build keyword scanner
WordRule keywordsRule = new WordRule(new IWordDetector() {
public boolean isWordStart(char c) {
// probe kernel.function("schedule") is a valid name in
// Systemtap, but we do not want to highlight the function
// here as a keyword. Same with foo.return and so on.
if (c == '.') {
return true;
}
return Character.isJavaIdentifierStart(c);
}
public boolean isWordPart(char c) {
// Set isWordStart for . rule.
if (c == '.') {
return true;
}
return Character.isJavaIdentifierPart(c);
}
}, defaultToken, true);
for (int i=0; i<keywordList.length; i++)
keywordsRule.addWord(keywordList[i], keywordToken);
setRules(new IRule[] {
new MultiLineRule("/*", "*/", commentToken),
new EndOfLineRule("/*", commentToken),
new EndOfLineRule("#", commentToken),
new EndOfLineRule("//", commentToken),
new EndOfLineRule("#if", defaultToken),
new EndOfLineRule("#else", defaultToken),
new EndOfLineRule("#endif", defaultToken),
new EndOfLineRule("#define", defaultToken),
new SingleLineRule("\"", "\"", stringToken, '\\'),
new SingleLineRule("'", "'", stringToken, '\\'),
keywordsRule,
new WhitespaceRule(new IWhitespaceDetector() {
public boolean isWhitespace(char c) {
return Character.isWhitespace(c);
}
}),
});
}
}
|