1 package org.simantics.sysdyn.ui.equation.expressions;
\r
3 import java.util.HashSet;
\r
4 import java.util.Set;
\r
6 import org.eclipse.jface.text.DefaultTextHover;
\r
7 import org.eclipse.jface.text.IDocument;
\r
8 import org.eclipse.jface.text.ITextHover;
\r
9 import org.eclipse.jface.text.TextAttribute;
\r
10 import org.eclipse.jface.text.presentation.IPresentationReconciler;
\r
11 import org.eclipse.jface.text.presentation.PresentationReconciler;
\r
12 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
\r
13 import org.eclipse.jface.text.rules.IRule;
\r
14 import org.eclipse.jface.text.rules.ITokenScanner;
\r
15 import org.eclipse.jface.text.rules.IWordDetector;
\r
16 import org.eclipse.jface.text.rules.RuleBasedScanner;
\r
17 import org.eclipse.jface.text.rules.Token;
\r
18 import org.eclipse.jface.text.rules.WordRule;
\r
19 import org.eclipse.jface.text.source.DefaultAnnotationHover;
\r
20 import org.eclipse.jface.text.source.IAnnotationHover;
\r
21 import org.eclipse.jface.text.source.ISourceViewer;
\r
22 import org.eclipse.jface.text.source.SourceViewerConfiguration;
\r
23 import org.eclipse.swt.SWT;
\r
24 import org.eclipse.swt.graphics.RGB;
\r
26 public class ExpressionFieldConfiguration extends SourceViewerConfiguration {
\r
29 ColorManager colorManager;
\r
31 public ExpressionFieldConfiguration(ColorManager colorManager) {
\r
33 this.colorManager = colorManager;
\r
36 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
\r
37 return new String[] {
\r
38 IDocument.DEFAULT_CONTENT_TYPE
\r
44 public IAutoEditStrategy[] getAutoEditStrategies(
\r
45 ISourceViewer sourceViewer, String contentType) {
\r
46 return new IAutoEditStrategy[] {
\r
47 new ReplaceTabsBySpaces(),
\r
48 new IndentLineEditStrategy(),
\r
49 new MatchingBracketsEditStrategy()
\r
54 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
\r
55 PresentationReconciler reconciler = new PresentationReconciler();
\r
57 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner());
\r
59 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
\r
60 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
\r
68 ITokenScanner getSclTokenScanner() {
\r
69 RuleBasedScanner scanner = new RuleBasedScanner();
\r
71 final Token reserved = new Token(
\r
73 colorManager.getColor(new RGB(127, 0, 85)),
\r
79 WordRule reservedWord = new WordRule(new IWordDetector() {
\r
81 public boolean isWordStart(char c) {
\r
82 return Character.isLetter(c);
\r
86 public boolean isWordPart(char c) {
\r
87 return Character.isLetter(c);
\r
91 for(String s : keywords) {
\r
92 reservedWord.addWord(s, reserved);
\r
95 IRule[] rules = new IRule[] {
\r
98 scanner.setRules(rules);
\r
104 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
\r
105 return new DefaultTextHover(sourceViewer);
\r
109 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
\r
110 return new DefaultAnnotationHover();
\r
113 static final Set<String> keywords = new HashSet<String>();
\r
116 keywords.add("within");
\r
117 keywords.add("final");
\r
118 keywords.add("public");
\r
119 keywords.add("protected");
\r
120 keywords.add("connect");
\r
121 keywords.add("when");
\r
122 keywords.add("then");
\r
123 keywords.add("elsewhen");
\r
124 keywords.add("if");
\r
125 keywords.add("end");
\r
126 keywords.add("elseif");
\r
127 keywords.add("else");
\r
128 keywords.add("for");
\r
129 keywords.add("while");
\r
130 keywords.add("loop");
\r
131 keywords.add("der");
\r
132 keywords.add("enumeration");
\r
133 keywords.add("extends");
\r
134 keywords.add("class");
\r
135 keywords.add("partial");
\r
136 keywords.add("encapsulated");
\r
137 keywords.add("model");
\r
138 keywords.add("record");
\r
139 keywords.add("block");
\r
140 keywords.add("expandable");
\r
141 keywords.add("connector");
\r
142 keywords.add("type");
\r
143 keywords.add("package");
\r
144 keywords.add("function");
\r
145 keywords.add("import");
\r
146 keywords.add("external");
\r
147 keywords.add("constrainedby");
\r
148 keywords.add("redeclare");
\r
149 keywords.add("replaceable");
\r
150 keywords.add("flow");
\r
151 keywords.add("discrete");
\r
152 keywords.add("parameter");
\r
153 keywords.add("constant");
\r
154 keywords.add("input");
\r
155 keywords.add("output");
\r
156 keywords.add("annotation");
\r
157 keywords.add("false");
\r
158 keywords.add("true");
\r
159 keywords.add("each");
\r
160 keywords.add("initial");
\r
161 keywords.add("algorithm");
\r
162 keywords.add("equation");
\r
163 keywords.add("or");
\r
164 keywords.add("and");
\r
165 keywords.add("not");
\r
166 keywords.add("break");
\r
167 keywords.add("return");
\r
169 keywords.add("abs");
\r
170 keywords.add("min");
\r
171 keywords.add("max");
\r