diff options
author | 2021-10-30 13:48:52 +0200 | |
---|---|---|
committer | 2021-10-31 19:26:13 +0100 | |
commit | cdb493b0a47bcf64e8e670b94fa399fcd731f531 (patch) | |
tree | b6b03aec77ef87a2dda7585be7884a30c65d93f5 /language-web/src/main/js/language/problemLanguageSupport.ts | |
parent | feat(web): add xtext content assist (diff) | |
download | refinery-cdb493b0a47bcf64e8e670b94fa399fcd731f531.tar.gz refinery-cdb493b0a47bcf64e8e670b94fa399fcd731f531.tar.zst refinery-cdb493b0a47bcf64e8e670b94fa399fcd731f531.zip |
chore(web): refactor xtext client
Diffstat (limited to 'language-web/src/main/js/language/problemLanguageSupport.ts')
-rw-r--r-- | language-web/src/main/js/language/problemLanguageSupport.ts | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/language-web/src/main/js/language/problemLanguageSupport.ts b/language-web/src/main/js/language/problemLanguageSupport.ts new file mode 100644 index 00000000..c9e61b31 --- /dev/null +++ b/language-web/src/main/js/language/problemLanguageSupport.ts | |||
@@ -0,0 +1,83 @@ | |||
1 | import { styleTags, tags as t } from '@codemirror/highlight'; | ||
2 | import { | ||
3 | foldInside, | ||
4 | foldNodeProp, | ||
5 | indentNodeProp, | ||
6 | LanguageSupport, | ||
7 | LRLanguage, | ||
8 | } from '@codemirror/language'; | ||
9 | import { LRParser } from '@lezer/lr'; | ||
10 | |||
11 | import { parser } from '../../../../build/generated/sources/lezer/problem'; | ||
12 | import { | ||
13 | foldBlockComment, | ||
14 | foldConjunction, | ||
15 | foldDeclaration, | ||
16 | } from './folding'; | ||
17 | import { | ||
18 | indentBlockComment, | ||
19 | indentDeclaration, | ||
20 | indentPredicate, | ||
21 | } from './indentation'; | ||
22 | |||
23 | const parserWithMetadata = (parser as LRParser).configure({ | ||
24 | props: [ | ||
25 | styleTags({ | ||
26 | LineComment: t.lineComment, | ||
27 | BlockComment: t.blockComment, | ||
28 | 'problem class enum pred unique scope': t.definitionKeyword, | ||
29 | 'abstract extends refers contains opposite error default': t.modifier, | ||
30 | 'true false unknown error': t.keyword, | ||
31 | NotOp: t.keyword, | ||
32 | UnknownOp: t.keyword, | ||
33 | OrOp: t.keyword, | ||
34 | StarArgument: t.keyword, | ||
35 | 'IntMult StarMult Real': t.number, | ||
36 | StarMult: t.number, | ||
37 | String: t.string, | ||
38 | 'RelationName/QualifiedName': t.typeName, | ||
39 | 'UniqueNodeName/QualifiedName': t.atom, | ||
40 | 'VariableName/QualifiedName': t.variableName, | ||
41 | '{ }': t.brace, | ||
42 | '( )': t.paren, | ||
43 | '[ ]': t.squareBracket, | ||
44 | '. .. , :': t.separator, | ||
45 | '<->': t.definitionOperator, | ||
46 | }), | ||
47 | indentNodeProp.add({ | ||
48 | ProblemDeclaration: indentDeclaration, | ||
49 | UniqueDeclaration: indentDeclaration, | ||
50 | ScopeDeclaration: indentDeclaration, | ||
51 | PredicateBody: indentPredicate, | ||
52 | BlockComment: indentBlockComment, | ||
53 | }), | ||
54 | foldNodeProp.add({ | ||
55 | ClassBody: foldInside, | ||
56 | EnumBody: foldInside, | ||
57 | ParameterList: foldInside, | ||
58 | PredicateBody: foldInside, | ||
59 | Conjunction: foldConjunction, | ||
60 | UniqueDeclaration: foldDeclaration, | ||
61 | ScopeDeclaration: foldDeclaration, | ||
62 | BlockComment: foldBlockComment, | ||
63 | }), | ||
64 | ], | ||
65 | }); | ||
66 | |||
67 | const problemLanguage = LRLanguage.define({ | ||
68 | parser: parserWithMetadata, | ||
69 | languageData: { | ||
70 | commentTokens: { | ||
71 | block: { | ||
72 | open: '/*', | ||
73 | close: '*/', | ||
74 | }, | ||
75 | line: '%', | ||
76 | }, | ||
77 | indentOnInput: /^\s*(?:\{|\}|\(|\)|;|\.)$/, | ||
78 | }, | ||
79 | }); | ||
80 | |||
81 | export function problemLanguageSupport(): LanguageSupport { | ||
82 | return new LanguageSupport(problemLanguage); | ||
83 | } | ||