-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (46 loc) · 1.43 KB
/
Copy pathindex.js
File metadata and controls
52 lines (46 loc) · 1.43 KB
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
var input, output, decoded;
window.addEventListener("load", function() {
input = document.getElementById("input");
output = document.getElementById("output");
input.addEventListener("input", function() {
decoded = Mma.DecompressDecode(input.value);
output.textContent = PrettyPrint(decoded.parts[0]);
})
});
// Convenient list of type names and content locations:
// Mma.IntegerMP .n
// Mma.IntegerAP .nstring
// Mma.RealMP .n
// Mma.RealAP .nstring
// Mma.Symbol .name
// Mma.String .str
// Mma.Expression .head .parts
function PrettyPrint (obj, indent) {
if (indent === undefined)
indent = 0;
var text = "";
function print (str) {
for (var i=0; i<indent; i++)
text += " ";
text += str;
text += "\n";
}
if (obj instanceof Mma.IntegerMP || obj instanceof Mma.RealMP) {
print(String(obj.n));
} else if (obj instanceof Mma.IntegerAP || obj instanceof Mma.RealAP) {
print(obj.nstring);
} else if (obj instanceof Mma.Symbol) {
print(obj.name);
} else if (obj instanceof Mma.String) {
print('"' + obj.str + '"');
} else if (obj instanceof Mma.Expression) {
print(obj.head.name + " [");
for (var i=0; i < obj.parts.length; i++) {
text += PrettyPrint(obj.parts[i], indent + 3);
}
print("]")
} else {
print("<???>");
}
return text;
}