-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathapp.js
More file actions
89 lines (80 loc) · 2.75 KB
/
Copy pathapp.js
File metadata and controls
89 lines (80 loc) · 2.75 KB
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
84
85
86
87
88
89
/* CodeMirror & Lezer */
import { basicSetup } from 'codemirror';
import { Compartment, EditorState } from '@codemirror/state';
import { EditorView, keymap } from '@codemirror/view';
import { indentWithTab } from '@codemirror/commands';
import { LRLanguage, LanguageSupport, continuedIndent, foldNodeProp, indentNodeProp } from '@codemirror/language';
import { styleTags, tags as t } from '@lezer/highlight';
import parser from './lezer.grammar';
export const cp = new LanguageSupport(LRLanguage.define({
parser: parser.configure({
props: [
indentNodeProp.add({
RecordType: continuedIndent(),
Record: continuedIndent(),
}),
foldNodeProp.add({
RecordType(tree) { return { from: tree.from + 1, to: tree.to - 1 } },
Record(tree) { return { from: tree.from + 1, to: tree.to - 1 } },
Document(tree) { return { from: tree.from + 1, to: tree.to - 1 } },
}),
styleTags({
'type interface extends let letrec trait implements inherits': t.definitionKeyword,
'if then else new fix open in with toString fold unfold ref switch as case forall Int Double Bool String Top Bot Trait Ref': t.keyword,
'override': t.modifier,
'true false undefined': t.atom,
Unit: t.unit,
TermName: t.variableName,
TermNameDecl: t.definition(t.variableName),
Label: t.propertyName,
LabelDecl: t.definition(t.propertyName),
LineComment: t.lineComment,
BlockComment: t.blockComment,
Number: t.number,
String: t.string,
Document: t.docString,
TypeOp: t.typeOperator,
ArithOp: t.arithmeticOperator,
LogicOp: t.logicOperator,
CompareOp: t.compareOperator,
MergeOp: t.operator,
TraitArrow: t.definition(t.punctuation),
'( )': t.paren,
'{ }': t.brace,
'[ ]': t.squareBracket,
'< >': t.angleBracket,
'.': t.derefOperator,
';': t.separator,
}),
],
}),
languageData: {
closeBrackets: { brackets: ['{', '(', '[', '"', '`'] },
commentTokens: { line: '--', block: { open: '{-', close: '-}' } },
},
}));
export const language = new Compartment;
export function editorState(doc, binding) {
const modEnter = {
key: 'Mod-Enter',
run: () => { binding(); return true; },
};
return EditorState.create({
doc,
extensions: [
EditorView.lineWrapping,
EditorState.tabSize.of(2),
keymap.of([indentWithTab, modEnter]),
language.of([]),
basicSetup,
],
});
}
export function editorView(state, parent) {
return new EditorView({ state, parent });
}
/* PureScript interpreter */
import { evaluateCP } from './output/Language.CP/index.js';
export function interpret(input) {
return evaluateCP(input)();
}