2014-04-14 03:35:26 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
|
<title>ColaScript Playground</title>
|
|
|
|
|
<script src="./utils.js"></script>
|
|
|
|
|
<script src="./ast.js"></script>
|
|
|
|
|
<script src="./parse.js"></script>
|
|
|
|
|
<script src="./transform.js"></script>
|
|
|
|
|
<script src="./scope.js"></script>
|
|
|
|
|
<script src="./output.js"></script>
|
|
|
|
|
<script src="./compress.js"></script>
|
|
|
|
|
<script src="./sourcemap.js"></script>
|
|
|
|
|
<script src="./mozilla-ast.js"></script>
|
|
|
|
|
<script src="./translate.js"></script>
|
|
|
|
|
<script src="./std.js"></script>
|
2014-04-15 10:52:01 +00:00
|
|
|
<style>
|
|
|
|
|
|
|
|
|
|
body {
|
|
|
|
|
padding: 0;
|
|
|
|
|
margin: 0;
|
|
|
|
|
line-height: 100%;
|
|
|
|
|
position: fixed;
|
|
|
|
|
top: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
textarea {
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
width: 33.333%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
float: left;
|
|
|
|
|
font-family: "Andale Mono";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#controls {
|
|
|
|
|
position: fixed;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</style>
|
2014-04-14 03:35:26 +00:00
|
|
|
</head>
|
|
|
|
|
<body>
|
2014-04-15 10:52:01 +00:00
|
|
|
<textarea id="source" onkeyup="compile()"></textarea>
|
|
|
|
|
<textarea id="translation"></textarea>
|
|
|
|
|
<textarea id="result"></textarea>
|
2014-04-16 18:39:27 +00:00
|
|
|
<div id="controls"><button id="exec" onclick="exec()">Execute</button><input type="checkbox" id="is_js" onclick="compile()"><label for="is_js">js parser</label></div>
|
2014-04-14 03:35:26 +00:00
|
|
|
</body>
|
|
|
|
|
<script>
|
2014-04-15 10:52:01 +00:00
|
|
|
var sourceArea = document.getElementById("source"),
|
|
|
|
|
translationArea = document.getElementById("translation"),
|
|
|
|
|
resultArea = document.getElementById("result"),
|
2014-04-16 18:39:27 +00:00
|
|
|
isjs = document.getElementById("is_js"),
|
2014-04-15 10:52:01 +00:00
|
|
|
source;
|
2014-04-14 03:35:26 +00:00
|
|
|
sourceArea.value = source = localStorage.source;
|
2014-04-16 18:39:27 +00:00
|
|
|
isjs.checked = localStorage.isjs == "t";
|
2014-04-14 03:35:26 +00:00
|
|
|
|
2014-04-15 10:52:01 +00:00
|
|
|
function compile(){
|
2014-04-14 03:35:26 +00:00
|
|
|
source = sourceArea.value;
|
|
|
|
|
localStorage.source = source;
|
2014-04-16 18:39:27 +00:00
|
|
|
localStorage.isjs = isjs.checked ? "t" : "f";
|
2014-04-15 10:52:01 +00:00
|
|
|
|
2014-04-17 16:21:45 +00:00
|
|
|
stream = new Cola.OutputStream({ beautify : true, is_js : isjs.checked });
|
2014-04-18 06:10:20 +00:00
|
|
|
compressor = new Cola.Compressor({ is_js : isjs.checked });
|
2014-04-15 10:52:01 +00:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 1. compile
|
2014-04-18 06:10:20 +00:00
|
|
|
ast = Cola.parse(source, { is_js : isjs.checked });
|
2014-04-17 16:21:45 +00:00
|
|
|
if(!isjs.checked) ast = ast.toJavaScript();
|
2014-04-15 10:52:01 +00:00
|
|
|
ast.print(stream);
|
|
|
|
|
translationArea.value = stream.toString();
|
|
|
|
|
|
|
|
|
|
// 2. compress
|
|
|
|
|
ast.figure_out_scope();
|
|
|
|
|
ast = ast.transform(compressor);
|
|
|
|
|
|
|
|
|
|
// 3. mangle
|
|
|
|
|
ast.figure_out_scope();
|
|
|
|
|
ast.compute_char_frequency();
|
2014-04-17 10:10:18 +00:00
|
|
|
ast.mangle_names({ is_js : isjs.checked, sort : true, toplevel : true });
|
2014-04-15 10:52:01 +00:00
|
|
|
|
2014-04-18 06:10:20 +00:00
|
|
|
stream = new Cola.OutputStream({ is_js : isjs.checked });
|
2014-04-15 10:52:01 +00:00
|
|
|
ast.print(stream);
|
|
|
|
|
resultArea.value = stream.toString();
|
|
|
|
|
} catch(e){
|
|
|
|
|
translationArea.value = '';
|
|
|
|
|
resultArea.value = '';
|
2014-04-16 16:43:40 +00:00
|
|
|
|
|
|
|
|
throw e;
|
2014-04-15 10:52:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function exec(){
|
|
|
|
|
eval(resultArea.value)
|
|
|
|
|
}
|
2014-04-14 03:35:26 +00:00
|
|
|
|
|
|
|
|
function Translate(){
|
2014-04-17 16:21:45 +00:00
|
|
|
stream = new Cola.OutputStream({ beautify : true });
|
2014-04-16 18:39:27 +00:00
|
|
|
translate(Cola.parse(source, null, isjs.checked)).print(stream);
|
2014-04-14 03:35:26 +00:00
|
|
|
return stream.toString();
|
|
|
|
|
}
|
2014-04-15 10:52:01 +00:00
|
|
|
|
|
|
|
|
compile();
|
2014-04-14 03:35:26 +00:00
|
|
|
</script>
|
|
|
|
|
</html>
|