-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconsole.html
108 lines (96 loc) · 2.95 KB
/
console.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Parse Console</title>
<style>
.content > * {
width: 50%;
float: left;
position: relative;
}
.content > * > * {
padding: 0 2em;
display: block;
}
.console textarea {
width: 100%;
box-sizing: border-box;
}
.input textarea {
width: 100%;
}
.output pre {
white-space: pre-wrap;
}
.ParseError, .LexError {
color: red;
}
</style>
</head>
<body lang="en">
<div class="content">
<div class='input'>
<h2>Input</h2>
<div class='Parser'>
<h4>Parser</h4>
<textarea rows='10'></textarea>
</div>
<div class='Text'>
<h4>Text</h4>
<textarea rows='20'></textarea>
</div>
<div>
<button>Parse</button>
</div>
</div>
<div class='output'>
<h2>Output</h2>
<div>
<pre class='ParseError'></pre>
<pre class='ParseOut'></pre>
</div>
</div>
</div>
<script type="application/javascript" src="resources/require.js"></script>
<script src="resources/jquery-1.8.3.min.js"></script>
<script type="application/javascript">
requirejs.config({
paths: {
'bennu': 'dist',
'nu-stream': 'dependencies/nu/dist',
'seshet': 'dependencies/seshet/dist/seshet'
}
});
$(function(){
require(['nu-stream/stream', 'bennu/parse', 'bennu/text', 'bennu/lang'],
function(stream, parse, parse_text, parse_lang) {
var flatten = function(s, f) {
if (stream.isStream(s)) {
stream.forEach(function(x) {
flatten(x, f);
}, s);
} else {
f(s);
}
};
$('button').click(function() {
$('.ParseOut').children().remove();
$('.ParseOut').text('');
$('.ParseError').text('');
try {
var parser = eval($('.Parser textarea').val());
var input = $('.Text textarea').val();
flatten(parse.run(parser, input, 0), function(x) {
$('.ParseOut').append(x + '');
});
} catch (e) {
$('.ParseError').text(e);
return;
}
});
});
});
</script>
</body>
</html>