-
Notifications
You must be signed in to change notification settings - Fork 4
/
demo.html
196 lines (175 loc) · 6.63 KB
/
demo.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../assets/ico/favicon.ico">
<title>Lua 2 JS</title>
<!-- Bootstrap core CSS -->
<link href="http://bootswatch.com/darkly/bootstrap.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js"></script>
<script src="demo/ui-ace.js"></script>
<script src="build/skulpty.js"></script>
<script src="https://estools.github.io/escodegen/escodegen.browser.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/mode-python.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/mode-javascript.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<style>
.ace_editor { height: 500px; background-color: black; }
textarea { width:100%; height: 100px; font-size: 14pt }
.x { padding: 10px; color: white !important; }
.footer { margin-top: 20px; }
.modal-body hr { margin-top: 0; margin-bottom: 0; }
.ace_err { background: rgba(255, 0, 0, 0.3); position: absolute; min-width: 8px; }
</style>
</head>
<body ng-app="MyApp" ng-controller="main">
<div class="container">
<div class="header">
<ul class="nav nav-pills pull-right">
<li><a href="#" data-toggle="modal" data-target="#options">Options</a></li>
<li class="active"><a href="#" ng-click="xeval()">Evaluate</a></li>
</ul>
<h3 class="text-muted">Skulpty</h3>
</div>
<div class="row" style="padding-top: 10px">
<div class="col-sm-6">
<div ng-model="code" ui-ace="{
useWrapMode : true,
showGutter: true,
theme:'twilight',
mode: 'python',
onLoad: aceLoaded,
onChange: aceChanged
}"></div>
</div>
<div class="col-sm-6">
<div ng-model="code2" ng-show="error == ''" ui-ace="{
useWrapMode : true,
showGutter: true,
theme:'twilight',
mode: 'javascript',
onLoad: aceLoaded2,
onChange: aceChanged2
}"></div>
<div ng-show="error != ''" class="x ace_editor ace_dark ace-twilight">{{error}}
</div>
</div>
</div>
<div class="footer">
<p>© basicer 2014</p>
</div>
</div> <!-- /container -->
<div class="modal fade" id="options">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Parser Options</h4>
</div>
<div class="modal-body">
<h5>JavaScript Compat</h5>
<hr />
<div class="row">
<div class="col-sm-6">
<div class="checkbox"><label><input type="checkbox" ng-model="opts.forceVar"> Force 'var' instead of 'let'</label></div>
<div class="checkbox"><label><input type="checkbox" ng-model="opts.luaOperators"> Use library functions for operators</label></div>
<div class="checkbox"><label><input type="checkbox" ng-model="opts.encloseWithFunctions"> Enclose scopes in functions</label></div>
</div>
<div class="col-sm-6">
<div class="checkbox"><label><input type="checkbox" ng-model="opts.decorateLuaObjects"> Decorate Lua objects</label></div>
<div class="checkbox"><label><input type="checkbox" ng-model="opts.luaCalls"> Proxy function calls </label></div>
</div>
</div>
<h5>Error Handeling</h5>
<hr />
<div class="row">
<div class="col-sm-6">
<div class="checkbox"><label><input type="checkbox" ng-model="opts.loose"> Loose Mode</label></div>
</div>
<div class="col-sm-6">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script type="text/javascript">
__pythonRuntime = filbert.pythonRuntime;
var Range;
var myAppModule = angular.module('MyApp', ['ui.ace']);
function update($scope) {
var rng;
try {
if ( $scope.marker ) $scope.ace.session.removeMarker($scope.marker);
$scope.error = "";
localStorage['skulpty.js'] = $scope.code;
var c = filbert.parse($scope.code, $scope.opts);
$scope.code2 = "(function() {\n'use strict';\n" + escodegen.generate(c) + "\n})();";
} catch ( e ) {
console.log("E", e, e.context, e.extra, e.stack);
var ctx = e.context;
console.log("C", ctx);
//var rng = new Range(e.line - 1, e.column, e.line - 1, e.column+1);
if ( ctx.length > 1 ) {
rng = new Range(ctx[0][0] - 1, ctx[0][1], ctx[1][0] - 1, ctx[1][1]);
} else {
rng = new Range(e.line - 1, e.column, e.line - 1, e.column+1);
}
if ( e.extra && e.extra.node ) {
var loc = e.extra.node.loc;
//var rng = new Range(loc.start.line-1, loc.start.column, loc.end.line-1, loc.end.column);
}
$scope.marker = $scope.ace.session.addMarker(
rng,
"ace_err",
"text"
);
$scope.error = e.message + "\n" + "at " + e.line + ":" + e.column;
$scope.code2 = "";
}
}
function main($scope) {
$scope.code = localStorage['skulpty.js'];
$scope.code2 = "{\n}";
$scope.opts = {locations: true, ranges: true};
$scope.fix = function(c) { return c.reverse(); }
$scope.aceLoaded = function(e) {
window.l = e;
$scope.ace = e;
Range = ace.require('ace/range').Range;
e.focus();
};
$scope.aceChanged = function() {
update($scope);
};
$scope.xeval = function() {
update($scope);
try {
stdout = "Output:\n"
eval($scope.code2);
} catch ( e ) {
stdout = "Error:\n" + e;
}
$scope.error = stdout;
};
$scope.$watch('opts', function() {
update($scope);
}, true);
}
</script>
</body>
</html>