forked from code4fukui/DNCL
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
161 lines (145 loc) · 4.35 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><link rel="icon" href="data:">
<title>DNCL3実行環境</title>
</head><body>
<h1>DNCL3実行環境</h1>
サンプル <select id=selexamples></select>
<label><input type=checkbox id=chkvar checked>変数表示</label>
<label><input type=checkbox id=chkmaxloop checked>繰り返し上限 <input id=inmaxloop value=1000></label>
<label><input type=checkbox id=chkwirth>Wirth(非ブロック括弧表記)</label>
<button id=btnstop>STOP</button>
<main>
<div class=diveditor id=divprog></div>
<div class=diveditor id=divrun></div>
</main>
<a href=https://github.com/code4fukui/DNCL3/blob/main/README.md>DNCL3言語仕様</a> / <a href=https://github.com/code4fukui/Wirth/blob/main/README_ja.md>Wirth言語仕様</a> <a href=https://github.com/code4fukui/DNCL3/>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;
}
#inmaxloop {
width: 4em;
}
label {
white-space: nowrap;
}
@media only screen and (max-width: 600px) {
.diveditor {
width: calc(100vw - .8em);
height: calc(50vh - 5em);
}
}
</style>
<script type="module">
import { DNCL3 } from "./DNCL3.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 running = false;
let abortctrl = null;
const onchange = async () => {
console.log("onchange", performance.now())
if (running) {
//abortctrl.abort();
return;
}
abortctrl = new AbortController();
running = true;
const src = prog.getValue();
run.setValue("");
run.revealLine(1);
try {
const blacketmode = !chkwirth.checked;
const dncl = new DNCL3(src, (s) => {
run.setValue(run.getValue() + s + "\n");
}, null, blacketmode);
const maxloop = chkmaxloop.checked ? inmaxloop.value : 0;
btnstop.onclick = () => {
abortctrl.abort();
};
await dncl.run(maxloop, abortctrl.signal);
if (chkvar.checked) {
run.setValue(run.getValue() + "\n" + dncl.getVars() + "\n");
}
} catch (e) {
console.log(e);
//ast.setValue(JSON.stringify(e, null, 2));
run.setValue(run.getValue() + e.toString() + "\n");
}
running = false;
};
//prog.onDidChangeModelContent = onchange; // なぜか初回のみ
let bkval = null;
setInterval(async () => {
const txt = prog.getValue();
if (bkval == txt) return;
await onchange();
bkval = txt;
}, 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);
};
const fn = "print.dncl";
const fn0 = location.hash.substring(1) || fn;
selexamples.value = fn0;
selexamples.oninput();
chkvar.oninput = chkmaxloop.oninput = inmaxloop.oninput = chkwirth.oninput = () => onchange();
</script>
</body></html>