-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
127 lines (122 loc) · 3.5 KB
/
index.html
File metadata and controls
127 lines (122 loc) · 3.5 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
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>RapydScript Demo</title>
<script src=codemirror/lib/codemirror.js></script>
<script src=codemirror/mode/python/python.js></script>
<script src=codemirror/mode/javascript/javascript.js></script>
<link rel=stylesheet href=codemirror/lib/codemirror.css>
<style type=text/css>
.CodeMirror {
border: 1px solid black;
height: 100%;
width: 49.5%;
float: left;
}
.cm-s-output {
border-left: 1px;
}
.title {
font-size: 1.75em;
font-family: 'Roboto Condensed', arial, sans-serif;
font-weight: bold;
height: 3em;
vertical-align: top;
}
.title img {
height: 1em;
padding-right: 0.25em;
}
.title a {
text-decoration: none;
}
.page {
position: absolute;
top: 3em;
left: 0;
right: 0;
bottom: 1em;
}
.fl {
float: left;
}
</style>
<script type="text/javascript" src="lib/baselib.js"></script>
<script type="text/javascript" src="lib/utils.js"></script>
<script type="text/javascript" src="lib/ast.js"></script>
<script type="text/javascript" src="lib/output.js"></script>
<script type="text/javascript" src="lib/parse.js"></script>
<script type="text/javascript" src="importer.js"></script>
</head>
<body>
<div class="title">
<div class="fl">
<a href="http://rapydscript.pyjeon.com">
<img src="http://www.pyjeon.com/static/images/rapydscript.png">
</a>
RapydScript Demo
</div>
</div>
<div class="page">
<textarea id=code name=code>
def factorial(n):
if n == 0:
return 1
return n * factorial(n-1)
</textarea>
<textarea class=output id=preview></textarea>
</div>
<script>
var delay;
// Initialize CodeMirror editor with a nice html5 canvas demo.
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
mode: 'text/x-python',
indentUnit: 4,
lineNumbers: true,
autofocus: true,
});
var preview = CodeMirror.fromTextArea(document.getElementById('preview'), {
mode: 'text/javascript',
lineNumbers: true,
theme: "default output",
readOnly: true
});
editor.on("change", function() {
clearTimeout(delay);
delay = setTimeout(function(){updatePreview(false);}, 500);
});
//RapydScript options
var rs_options = {
"filename":"demo",
"toplevel":null,
"basedir": null,
"libdir": null
};
var output_opts = {
"beautify":true,
"private_scope":false
};
function updatePreview(from_error) {
var rapydscript_string = editor.getValue();
output = OutputStream(output_opts)
rapydscript_string += '\n'; //just to be safe
try {
BASELIB = {}
INDEX_COUNTER = 0
TOPLEVEL = parse(rapydscript_string, rs_options);
TOPLEVEL.print(output);
preview.setValue(String(output) + '\n');
} catch(err) {
if (from_error) {
preview.setValue("ERROR: " + err.message + ". Line " + err.line + ", column " + err.col + ".");
} else {
clearTimeout(delay);
delay = setTimeout(function(){updatePreview(true);}, 2000);
}
}
}
updatePreview();
</script>
</body>
</html>