diff options
Diffstat (limited to 'language-web/src/main/js/editor/problemLanguageSupport.ts')
-rw-r--r-- | language-web/src/main/js/editor/problemLanguageSupport.ts | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/language-web/src/main/js/editor/problemLanguageSupport.ts b/language-web/src/main/js/editor/problemLanguageSupport.ts new file mode 100644 index 00000000..2bf7c7a4 --- /dev/null +++ b/language-web/src/main/js/editor/problemLanguageSupport.ts | |||
@@ -0,0 +1,82 @@ | |||
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 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 | 'RelationName/QualifiedName': t.typeName, | ||
38 | 'UniqueNodeName/QualifiedName': t.atom, | ||
39 | 'VariableName/QualifiedName': t.variableName, | ||
40 | '{ }': t.brace, | ||
41 | '( )': t.paren, | ||
42 | '[ ]': t.squareBracket, | ||
43 | '. .. , :': t.separator, | ||
44 | '<->': t.definitionOperator, | ||
45 | }), | ||
46 | indentNodeProp.add({ | ||
47 | ProblemDeclaration: indentDeclaration, | ||
48 | UniqueDeclaration: indentDeclaration, | ||
49 | ScopeDeclaration: indentDeclaration, | ||
50 | PredicateBody: indentPredicate, | ||
51 | BlockComment: indentBlockComment, | ||
52 | }), | ||
53 | foldNodeProp.add({ | ||
54 | ClassBody: foldInside, | ||
55 | EnumBody: foldInside, | ||
56 | ParameterList: foldInside, | ||
57 | PredicateBody: foldInside, | ||
58 | Conjunction: foldConjunction, | ||
59 | UniqueDeclaration: foldDeclaration, | ||
60 | ScopeDeclaration: foldDeclaration, | ||
61 | BlockComment: foldBlockComment, | ||
62 | }), | ||
63 | ], | ||
64 | }); | ||
65 | |||
66 | const problemLanguage = LRLanguage.define({ | ||
67 | parser: parserWithMetadata, | ||
68 | languageData: { | ||
69 | commentTokens: { | ||
70 | block: { | ||
71 | open: '/*', | ||
72 | close: '*/', | ||
73 | }, | ||
74 | line: '%', | ||
75 | }, | ||
76 | indentOnInput: /^\s*(?:\{|\}|\(|\)|;|\.)$/, | ||
77 | }, | ||
78 | }); | ||
79 | |||
80 | export function problemLanguageSupport(): LanguageSupport { | ||
81 | return new LanguageSupport(problemLanguage); | ||
82 | } | ||