forked from code4fukui/DNCL3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
138 lines (122 loc) · 3.54 KB
/
index.html
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><link rel="icon" href="data:">
<title>Wirth Playground</title>
</head><body>
<h1>Wirth Playground</h1>
examples <select id=selexamples></select> <label><input type=checkbox id=chkvar checked>show vars after run</label>
<main>
<div class=diveditor id=divprog></div>
<div class=diveditor id=divrun></div>
</main>
<a href=https://github.com/code4fukui/Wirth/blob/main/README.md>Wirth Language Reference</a>
<a href=https://github.com/code4fukui/Wirth/>src on GitHub</a>
<style>
body {
font-family: sans-serif;
}
h1 {
margin: 0;
}
.diveditor {
width: calc(50% - .5em);
padding: .1em;
display: inline-block;
height: calc(100vh - 8em);
}
a {
color: gray !important;
}
@media only screen and (max-width: 600px) {
.diveditor {
width: calc(100vw - .8em);
height: calc(50dvh - 5em);
}
}
</style>
<script type="module">
import { Wirth } from "./Wirth.js";
import { monaco } from "https://code4fukui.github.io/monaco-editor/monaco.js";
import { CSV } from "https://js.sabae.cc/CSV.js";
export const makeEditor = (div, language) => {
const editor = monaco.editor.create(div, {
language,
autoIndent: true,
//autoIndent: "none",
//formatOnPaste: true,
//formatOnType: true,
fontSize: 16, // for mobile
lineHeight: 24,
suggestOnTriggerCharacters: false, // トリガーキャラクターでの補完を無効化
acceptSuggestionOnEnter: 'off', // Enterでの補完選択を無効化
parameterHints: false, // パラメータヒントを無効化
quickSuggestions: false, // 自動的に補完候補を表示しない
inlineSuggest: { enabled: false }, // インライン補完を無効化
tabSize: 2,
minimap: { enabled: false },
//overflow: "auto",
automaticLayout: true,
theme: "vs-dark",
});
window.addEventListener("resize", () => {
editor.layout();
});
return editor;
};
const prog = makeEditor(divprog, "");
const run = makeEditor(divrun, "");
const removeStartEnd = (json) => {
for (const name in json) {
const v = json[name];
if (typeof v == "object") {
removeStartEnd(v);
} else if (name == "start" || name == "end") {
delete json[name];
}
}
};
let bkval = null;
const onchange = () => {
const src = prog.getValue();
run.setValue("");
run.revealLine(1);
try {
const runtime = new Wirth(src, (s) => {
run.setValue(run.getValue() + s + "\n");
});
runtime.run();
if (chkvar.checked) {
run.setValue(run.getValue() + "\nvars " + JSON.stringify(runtime.getVars(), null, 2) + "\n");
}
} catch (e) {
console.log(e);
//ast.setValue(JSON.stringify(e, null, 2));
run.setValue(run.getValue() + e.toString() + "\n");
}
bkval = src;
};
//prog.onDidChangeModelContent = onchange; // なぜか初回のみ
setInterval(() => {
const txt = prog.getValue();
if (bkval == txt) return;
onchange();
}, 500);
const data = await CSV.fetchJSON("examples.csv");
for (const item of data) {
const opt = document.createElement("option");
opt.textContent = item.title;
opt.value = item.fn;
selexamples.appendChild(opt);
}
selexamples.oninput = async () => {
const fn = selexamples.value;
location.hash = fn;
const s = await (await fetch("examples/" + fn)).text();
prog.setValue(s);
onchange();
};
const fn = "print.wirth";
const fn0 = location.hash.substring(1) || fn;
selexamples.value = fn0;
selexamples.oninput();
chkvar.oninput = () => onchange();
</script>
</body></html>