diff options
author | 2021-06-27 17:59:54 +0200 | |
---|---|---|
committer | 2021-06-27 18:09:46 +0200 | |
commit | 5785f36b17d2b290d88c05fee54e39060a07b6d4 (patch) | |
tree | 31f4f319b493d6f29e13ef63fe46eb18935178b5 /language-mwe2/src/main/java/org/eclipse/viatra/solver/language/mwe2 | |
parent | Fix running outside of Eclipse (diff) | |
download | refinery-5785f36b17d2b290d88c05fee54e39060a07b6d4.tar.gz refinery-5785f36b17d2b290d88c05fee54e39060a07b6d4.tar.zst refinery-5785f36b17d2b290d88c05fee54e39060a07b6d4.zip |
Customize client-side CodeMirror mode
Diffstat (limited to 'language-mwe2/src/main/java/org/eclipse/viatra/solver/language/mwe2')
-rw-r--r-- | language-mwe2/src/main/java/org/eclipse/viatra/solver/language/mwe2/ProblemWebIntegrationFragment.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/language-mwe2/src/main/java/org/eclipse/viatra/solver/language/mwe2/ProblemWebIntegrationFragment.java b/language-mwe2/src/main/java/org/eclipse/viatra/solver/language/mwe2/ProblemWebIntegrationFragment.java new file mode 100644 index 00000000..7cc736bc --- /dev/null +++ b/language-mwe2/src/main/java/org/eclipse/viatra/solver/language/mwe2/ProblemWebIntegrationFragment.java | |||
@@ -0,0 +1,59 @@ | |||
1 | package org.eclipse.viatra.solver.language.mwe2; | ||
2 | |||
3 | import java.util.Set; | ||
4 | |||
5 | import org.eclipse.xtext.xtext.generator.web.WebIntegrationFragment; | ||
6 | |||
7 | import com.google.common.collect.Multimap; | ||
8 | |||
9 | public class ProblemWebIntegrationFragment extends WebIntegrationFragment { | ||
10 | public ProblemWebIntegrationFragment() { | ||
11 | setFramework(Framework.CODEMIRROR.name()); | ||
12 | // We use our custom token style for single-quoted names | ||
13 | addSuppressPattern("string_singleQuote"); | ||
14 | // Use the CodeMirror default .cm-number instead of .cm-constant.cm-numeric | ||
15 | addSuppressPattern("number_decimal"); | ||
16 | // We use our own custom single-line comments | ||
17 | addSuppressPattern("comment_singleLine"); | ||
18 | // Override bracket indentation behavior | ||
19 | addSuppressPattern("bracket_open"); | ||
20 | addSuppressPattern("parenthesis_open"); | ||
21 | addSuppressPattern("brace_open"); | ||
22 | addSuppressPattern("bracket_close"); | ||
23 | addSuppressPattern("parenthesis_close"); | ||
24 | addSuppressPattern("brace_close"); | ||
25 | } | ||
26 | |||
27 | @Override | ||
28 | public void setFramework(String frameworkName) { | ||
29 | if (!frameworkName.toUpperCase().equals(Framework.CODEMIRROR.name())) { | ||
30 | throw new IllegalStateException("Framework cannot be changed from CodeMirror"); | ||
31 | } | ||
32 | super.setFramework(frameworkName); | ||
33 | } | ||
34 | |||
35 | @Override | ||
36 | protected Multimap<String, String> createCodeMirrorPatterns(String langId, Set<String> keywords) { | ||
37 | Multimap<String, String> patterns = super.createCodeMirrorPatterns(langId, keywords); | ||
38 | // We use our custom token style for single-quoted names | ||
39 | patterns.put("start", "{token: \"quoted-name\", regex: \"['](?:(?:\\\\\\\\.)|(?:[^'\\\\\\\\]))*?[']\"}"); | ||
40 | // Use the CodeMirror default .cm-number instead of .cm-constant.cm-numeric | ||
41 | patterns.put("start", | ||
42 | "{token: \"number\", regex: \"[+-]?\\\\d+(?:(?:\\\\.\\\\d*)?(?:[eE][+-]?\\\\d+)?)?\\\\b\"}"); | ||
43 | patterns.put("start", "{token: \"number\", regex: \"[*]\"}"); | ||
44 | // We use our own custom single-line comments | ||
45 | patterns.put("start", "{token: \"comment\", regex: \"%.*$\"}"); | ||
46 | patterns.put("start", "{token: \"comment\", regex: \"\\\\/\\\\/.*$\"}"); | ||
47 | patterns.put("meta", "lineComment: \"%\""); | ||
48 | // Override indentation behavior | ||
49 | patterns.put("start", "{token: \"lparen\", indent: true, regex: \"[[({]\"}"); | ||
50 | patterns.put("start", "{token: \"rparen\", dedent: true, dedentIfLineStart: true, regex: \"[\\\\])}]\"}"); | ||
51 | patterns.putAll("predicateBody", patterns.get("start")); | ||
52 | patterns.put("start", "{indent: true, push: \"predicateBody\", regex: \":-\"}"); | ||
53 | patterns.put("predicateBody", "{dedent: true, dedentIfLineStart: false, pop: true, regex: \"\\\\.\\\\s*$\"}"); | ||
54 | // We must repeat the keyword rule here, because Xtext only adds it to "main" later. | ||
55 | patterns.put("predicateBody", "{token: \"keyword\", regex: \"\\\\b(?:\" + keywords + \")\\\\b\"}"); | ||
56 | patterns.put("meta", "electricChars: \"])]\""); | ||
57 | return patterns; | ||
58 | } | ||
59 | } | ||