-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlexp.html
62 lines (56 loc) · 1.47 KB
/
lexp.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
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.4.js"></script>
<script data-main="lexp.js" src="assets/js/require.js"></script>
<style>
.error { color: red; }
</style>
</head>
<body>
<textarea name="exp" id="exp" rows="8" cols="60"></textarea><br/>
<div id="result">compiled result will be shown here</div>
<div id="val">result of evaluated expression will be shown here</div>
<script language="javascript">
$(document).ready( function() {
$('#exp').on( "change", function() {
var exp = $(this).val();
require( ['lexp'], function( lexp ) {
var n;
try {
$('#val').text("??").removeClass('error');
$('#result').text("??").removeClass('error');
n = lexp.compile( exp );
$('#result').html('Successful compile!');
}
catch (e) {
$('#result').html(typeof e + " error: " + e.toString()).addClass('error');
}
var context = {
color: "red",
size: "XL",
price: "40.00",
origin: {
country: "CN",
city: "Shanghai",
distance: 10000
}
};
if (n) {
n.buzz = function(a,b,c) { if (arguments.length != 3) throw new Error(); return 'a='+a+', b='+b+', c='+c; };
n.strftime = util.strftime;
try
{
var v = lexp.run( n, context );
$('#val').text( v + " (" + typeof v + ")" );
}
catch (e)
{
$('#val').text('Runtime error: ' + e.toString()).addClass('error');
}
}
});
});
});
</script>
</body>
</html>