diff options
author | 2020-05-08 18:28:19 +0200 | |
---|---|---|
committer | 2020-05-08 18:28:19 +0200 | |
commit | 419e76265ecbdf65e960e0624be006d31ed1e191 (patch) | |
tree | dad200fe9fd0beae7adde969206b77691a51b85a /Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticHighlightCalculator.xtend | |
parent | Fix check expressions in generated VIATRA (diff) | |
download | VIATRA-Generator-419e76265ecbdf65e960e0624be006d31ed1e191.tar.gz VIATRA-Generator-419e76265ecbdf65e960e0624be006d31ed1e191.tar.zst VIATRA-Generator-419e76265ecbdf65e960e0624be006d31ed1e191.zip |
Update solver language grammar
First version, still needs TokenSource and Linker to work.
Diffstat (limited to 'Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticHighlightCalculator.xtend')
-rw-r--r-- | Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticHighlightCalculator.xtend | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticHighlightCalculator.xtend b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticHighlightCalculator.xtend deleted file mode 100644 index cb10ebf4..00000000 --- a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticHighlightCalculator.xtend +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.language.ui.highlight | ||
2 | |||
3 | import java.util.Random | ||
4 | import java.util.WeakHashMap | ||
5 | import org.eclipse.viatra.solver.language.solverLanguage.ModelSymbol | ||
6 | import org.eclipse.xtext.ide.editor.syntaxcoloring.DefaultSemanticHighlightingCalculator | ||
7 | import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor | ||
8 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils | ||
9 | import org.eclipse.xtext.resource.XtextResource | ||
10 | import org.eclipse.xtext.util.CancelIndicator | ||
11 | |||
12 | class SolverSemanticHighlightCalculator extends DefaultSemanticHighlightingCalculator { | ||
13 | public static val SmybolCode = "SymbolCode" | ||
14 | |||
15 | val symbolName2ID = new WeakHashMap<String,String> | ||
16 | |||
17 | override provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) { | ||
18 | if (resource === null || resource.getParseResult() === null) { | ||
19 | return | ||
20 | } else { | ||
21 | val modelSymbols = resource.allContents.filter(ModelSymbol) | ||
22 | while(modelSymbols.hasNext) { | ||
23 | val symbolElement = modelSymbols.next | ||
24 | val node = NodeModelUtils::getNode(symbolElement) | ||
25 | acceptor.addPosition( | ||
26 | node.getOffset(), | ||
27 | node.getLength(), | ||
28 | getSymbolCode(symbolElement.name) | ||
29 | ) | ||
30 | } | ||
31 | } | ||
32 | } | ||
33 | |||
34 | def getSymbolCode(String name) { | ||
35 | if(symbolName2ID.containsKey(name)) { | ||
36 | return symbolName2ID.get(name) | ||
37 | } else { | ||
38 | val id = calculateSymbolCode(name) | ||
39 | symbolName2ID.put(name,id) | ||
40 | return id | ||
41 | } | ||
42 | } | ||
43 | |||
44 | def String calculateSymbolCode(String name) { | ||
45 | val Random random = new Random(name.hashCode) | ||
46 | val hue = huePick(random.nextFloat) | ||
47 | val saturation = 0.2+random.nextFloat*0.3 | ||
48 | val brightness = random.nextFloat*0.2+0.7f | ||
49 | return '''«SmybolCode» «hue» «saturation» «brightness»''' | ||
50 | } | ||
51 | private def huePick(float random) { | ||
52 | val pink = 300 | ||
53 | val tolerance = 10 | ||
54 | val degree = random*(360-2*tolerance) | ||
55 | if(degree<pink-tolerance) return degree | ||
56 | else return degree+2*tolerance | ||
57 | } | ||
58 | } \ No newline at end of file | ||