This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gps.html
219 lines (181 loc) · 5.15 KB
/
gps.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Eyebrow gps</title>
</head>
<body>
<style>
:root {
--margin: 10px;
}
html {
height: 100%;
}
body {
display: flex;
flex-direction: column;
width: 100%; height: 100%; margin: var(--margin);
overflow: hidden;
}
.content {
position: relative;
flex-grow: 1;
}
.scroll-wrapper {
box-sizing: border-box;
position: absolute;
height: calc(100% - 2*var(--margin)); width: calc(100% - 2*var(--margin)); border: 1px solid black;
overflow: auto; display: flex; flex-direction: column-reverse;
padding: 5px;
}
.scroll-start-at-top { flex: 1 1 0%; }
#file {
box-sizing: border-box;
border: 0px;
resize: none;
width: 100%; height: 100%;
}
#input {
margin-top: var(--margin);
box-sizing: border-box;
display: flex;
width: 100%;
}
#query { flex-grow: 1; margin: 0px 10px;}
.stderr { color: blue; }
.stderr, .stdout, .query { white-space: pre; font-family: monospace;}
.query, .prompt { font-weight: bold; }
.query { margin-top: 5px; }
</style>
<div class="content">
<div class="scroll-wrapper">
<span class="scroll-start-at-top"></span>
<div class="console">
<div id="output"></div>
<form class="input" id="input">
<span class="prompt">?- </span><input type="text" name="query" id="query" value="main(['--wcache', 'http://eyereasoner.github.io/eye/reasoning/gps', '.', '--nope', 'http://eyereasoner.github.io/eye/reasoning/gps/gps-example1.n3', 'http://eyereasoner.github.io/eye/reasoning/gps/gps-plugin.n3', '--query', 'http://eyereasoner.github.io/eye/reasoning/gps/gps-query1.n3']).">
</form>
</div>
</div>
</div>
<script src="./swipl-web.js"></script>
<script>
const output = document.getElementById('output');
const input = document.getElementById('input');
const more = document.getElementById('more');
const editor = document.getElementById('editor');
let yield = null;
let buffers = {
stdout: [],
stderr: []
}
function write(to, c) {
if (c)
buffers[to].push(c);
if (c == 10 || c == null)
flush(to);
}
function flush(to) {
const line = String.fromCharCode.apply(null, buffers[to]);
print_output(line, to);
buffers[to] = [];
}
function bindStdStreams(module) {
module.FS.init(undefined, (c) => write("stdout", c), (c) => write("stderr", c));
}
function print_output(line, cls) {
const node = document.createElement('span');
node.className = cls;
node.textContent = line;
output.insertBefore(node, more);
};
function pl(s) {
Module.prolog.call(s);
}
function query(query) {
print_output(`?- ${query}.\n`, 'query');
if (yield && yield.yield == "goal")
next(yield.resume(query));
else
alert("REPL is not waiting for a goal");
}
input.addEventListener('submit', (e) => {
e.preventDefault();
if (yield && yield.yield == "goal") {
let query = e.target.elements.query.value;
e.target.elements.query.value = '';
e.target.style.display = "none";
if (!/\.\s*/.test(query))
query += ".\n";
print_output(`?- ${query}\n`, 'query');
next(yield.resume(query));
} else {
alert("Not waiting for a query");
}
}, false);
function reply_more(action) {
more.style.display = "none";
if (yield && yield.yield == "more") {
switch (action) {
case "redo":
print_output(";", "stdout");
break;
case "continue":
print_output(".", "stdout");
break;
}
next(yield.resume(action));
}
}
function next(rc) {
yield = null;
if (typeof(rc) === "object") {
yield = rc;
flush("stderr");
flush("stdout");
switch (rc.yield) {
case "goal":
input.style.display = "flex";
break;
case "more":
more.style.display = "inline-block";
break;
}
} else if (rc == undefined) {
console.log("Unhandled exception; restarting");
toplevel();
}
}
function toplevel() {
let rc = Module.prolog.call("'$query_loop'", {
async: true,
module: "$toplevel"
});
next(rc);
}
var Module = {
noInitialRun: true,
arguments: [],
locateFile: function(file) {
return './' + file;
},
preRun: [() => bindStdStreams(Module)]
};
async function fetchWrite(link, file) {
const response = await fetch(link);
await Module.FS.writeFile(file, await response.text());
}
SWIPL(Module).then(async (module) => {
await fetchWrite('https://eyereasoner.github.io/eye/eye.pl', 'eye.pl');
await fetchWrite('https://eyereasoner.github.io/eye/reasoning/gps/gps-example1.n3', 'gps-example1.n3');
await fetchWrite('https://eyereasoner.github.io/eye/reasoning/gps/gps-plugin.n3', 'gps-plugin.n3');
await fetchWrite('https://eyereasoner.github.io/eye/reasoning/gps/gps-query1.n3', 'gps-query1.n3');
pl("set_prolog_flag(tty_control, true)");
pl("set_prolog_flag(debug_on_error, false)");
toplevel();
query("consult('./eye.pl')");
});
</script>
</body>
</html>