-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
84 lines (73 loc) · 2.45 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
<html>
<head>
<title>CodeHint.js demo</title>
</head>
<body>
<p>
This is a very simple demo of <a href="https://github.com/jgalenson/codehint.js">CodeHint.js</a>.
</p>
Input:<br/>
<textarea id='input' cols=120 rows=30>
var two = 2;
var s = 'live';
var plusOne = function(x) { return x + 1 };
var person = { firstName: "John",
lastName: "Doe",
age: 42,
live: function(x) {
if (typeof(x) == 'number') {
this.age += x;
return this.age;
} else
throw "Must give a number.";
},
answer: function () { return 42; }
};
var a = [1, 2, 3];
var spec = function (rv) { return typeof rv == 'number'; };
var startTime = (new Date()).getTime();
var results = CodeHint.synthesize({two: two, s: s, person: person, a: a}, spec);
var endTime = (new Date()).getTime();
document.getElementById('time').innerHTML = 'Found ' + results.length + ' results in ' + ((endTime - startTime) / 1000) + 's.\n';
results;
</textarea><br/><br/>
<input value='Solve' type='button' onclick='solve()'><br/><br/>
Output:<br/>
<span id='time'></span><br/>
<table class='tablesorter'>
<thead>
<tr>
<th>Expression</th>
<th>Value</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script src="codehint.js"></script>
<script src="underscore-min.js"></script>
<link rel="stylesheet" href="tablesorter/theme.blue.css" type="text/css" />
<script type="text/javascript" src="tablesorter/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="tablesorter/jquery.tablesorter.min.js"></script>
<script>
$("table").tablesorter();
function solve() {
var input = document.getElementById('input').value;
$("table tbody").empty();
result = eval(input);
$("table tbody").append(tableOfResult(result));
$("table").trigger("update");
}
function prettyPrintResult(result) {
return result.reduce(function (acc, expr) {
return acc + (acc.length == 0 ? '' : '\n') + '\'' + expr.str + '\' has value ' + expr.value;
}, '');
}
function tableOfResult(result) {
return result.reduce(function (acc, expr) {
return acc + '<tr><td>' + expr.str + '</td><td>' + expr.value + '</td></tr>';
}, '');
}
</script>
</body>
</html>