1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
import { styleTags, tags as t } from '@codemirror/highlight';
import {
foldInside,
foldNodeProp,
indentNodeProp,
LanguageSupport,
LRLanguage,
} from '@codemirror/language';
import { LRParser } from '@lezer/lr';
import { parser } from '../../../../build/generated/sources/lezer/problem';
import {
foldBlockComment,
foldConjunction,
foldDeclaration,
} from './folding';
import {
indentBlockComment,
indentDeclaration,
indentPredicate,
} from './indentation';
const parserWithMetadata = (parser as LRParser).configure({
props: [
styleTags({
LineComment: t.lineComment,
BlockComment: t.blockComment,
'problem class enum pred unique scope': t.definitionKeyword,
'abstract extends refers contains opposite error default': t.modifier,
'true false unknown error': t.keyword,
NotOp: t.keyword,
UnknownOp: t.keyword,
OrOp: t.keyword,
StarArgument: t.keyword,
'IntMult StarMult Real': t.number,
StarMult: t.number,
String: t.string,
'RelationName/QualifiedName': t.typeName,
'UniqueNodeName/QualifiedName': t.atom,
'VariableName/QualifiedName': t.variableName,
'{ }': t.brace,
'( )': t.paren,
'[ ]': t.squareBracket,
'. .. , :': t.separator,
'<->': t.definitionOperator,
}),
indentNodeProp.add({
ProblemDeclaration: indentDeclaration,
UniqueDeclaration: indentDeclaration,
ScopeDeclaration: indentDeclaration,
PredicateBody: indentPredicate,
BlockComment: indentBlockComment,
}),
foldNodeProp.add({
ClassBody: foldInside,
EnumBody: foldInside,
ParameterList: foldInside,
PredicateBody: foldInside,
Conjunction: foldConjunction,
UniqueDeclaration: foldDeclaration,
ScopeDeclaration: foldDeclaration,
BlockComment: foldBlockComment,
}),
],
});
const problemLanguage = LRLanguage.define({
parser: parserWithMetadata,
languageData: {
commentTokens: {
block: {
open: '/*',
close: '*/',
},
line: '%',
},
indentOnInput: /^\s*(?:\{|\}|\(|\)|;|\.)$/,
},
});
export function problemLanguageSupport(): LanguageSupport {
return new LanguageSupport(problemLanguage);
}
|