-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcashew-worker.html
114 lines (104 loc) · 3.02 KB
/
cashew-worker.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
<!DOCTYPE html>
<html>
<head>
<title>Cashew Web Parser</title>
<meta charset="utf-8">
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
}
textarea { font-size: 18px; }
#codeArea, #jsText, #astText, #outputText {
width: 45%;
height: 45%;
padding: 10px 15px;
font-size: 16px;
margin: 10px;
border: 1px solid silver;
display: inline-block;
overflow: hidden;
}
.btn-parser {
padding: 10px 25px;
background-color: #E6DB74;
font-size: 16px;
border: none;
position: absolute;
left: 38%;
top: 42%;
z-index: 9;
}
</style>
<script src="cashew.js"></script>
<script src="escodegen.browser.js"></script>
<script>
(function() {
var oldLog = console.log;
console.log = function(message){
outputText.innerHTML += (message + '\n');
oldLog.apply(console, arguments);
};
})();
var Parser = cashew.Parse;
function submitCode(){
var code = editor.getValue();
outputText.innerHTML = '';
try {
var ast = Parser(code);
// Display the AST text
astHigh.setValue(JSON.stringify(ast, null, 2));
astHigh.gotoLine(1);
// Generate and display the JS code
var js = escodegen.generate(ast);
js = "(function(___JavaRuntime){" + js + "})(cashew.___JavaRuntime);";
jseditor.setValue(js);
jseditor.gotoLine(1);
// Execute the transpiled code
eval(js);
} catch(err){
console.log(err);
}
}
</script>
</head>
<body>
<button class="btn-parser" onclick='submitCode()'>Parse it!</button>
<div id="codeArea">public class MyClass {
/** main method */
public static void main(String[] args)
{
System.out.println("Type your code here");
}
}
</div>
<pre id="jsText"></pre>
<pre id="astText"></pre>
<pre id="outputText"></pre>
<script type="text/javascript" src="vendor/ace.js"></script>
<script type="text/javascript">
var editor = ace.edit("codeArea");
editor.setTheme("ace/theme/github");
editor.getSession().setTabSize(2);
editor.getSession().setMode("ace/mode/java");
editor.$blockScrolling = Infinity;
var jseditor = ace.edit("jsText");
jseditor.setTheme("ace/theme/textmate");
jseditor.getSession().setTabSize(2);
jseditor.getSession().setMode("ace/mode/javascript");
jseditor.setHighlightActiveLine(false);
jseditor.setOption('showGutter', false);
jseditor.setReadOnly(true);
jseditor.$blockScrolling = Infinity;
var astHigh = ace.edit("astText");
astHigh.setTheme("ace/theme/github");
astHigh.getSession().setTabSize(2);
astHigh.getSession().setMode("ace/mode/json");
astHigh.setHighlightActiveLine(false);
astHigh.setOption('showGutter', false);
astHigh.setReadOnly(true);
astHigh.$blockScrolling = Infinity;
</script>
</body>
</html>