Mercurial > repos > tabletprog
comparison editor.js @ 15:a5ef5af3df0f
Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 23 Mar 2012 18:06:53 -0700 |
parents | 85fb6ba15bc6 |
children | 068d63627b16 |
comparison
equal
deleted
inserted
replaced
14:85fb6ba15bc6 | 15:a5ef5af3df0f |
---|---|
1 | 1 |
2 | 2 |
3 object.prototype.toHTML = function(node) { | 3 object.prototype.toHTML = function(node) { |
4 var el = newEl('div', { | 4 var el = newEl('div', { |
5 className: 'object', | 5 className: 'object' |
6 innerHTML: '#' | |
7 }); | 6 }); |
8 node.appendChild(el); | 7 node.appendChild(el); |
9 for (var i in this.messages) { | 8 for (var i in this.messages) { |
10 this.messages[i].toHTML(el); | 9 this.messages[i].toHTML(el); |
11 } | 10 } |
12 }; | 11 }; |
13 | 12 |
14 lambda.prototype.toHTML = function(node) { | 13 lambda.prototype.toHTML = function(node) { |
15 var el = newEl('div', { | 14 var el = newEl('div', { |
16 className: 'lambda', | 15 className: 'lambda' |
17 textContent: this.args.join(' ') | |
18 }); | 16 }); |
17 for (var i in this.args) { | |
18 this.args[i].toHTML(el); | |
19 } | |
20 var body = newEl('div', { | |
21 className: 'lambdabody' | |
22 }); | |
23 for (var i in this.expressions) { | |
24 this.expressions[i].toHTML(body); | |
25 } | |
26 el.appendChild(body); | |
19 node.appendChild(el); | 27 node.appendChild(el); |
20 }; | 28 }; |
21 | 29 |
22 assignment.prototype.toHTML = function(node) { | 30 assignment.prototype.toHTML = function(node) { |
23 var base = newEl('div', { | 31 var base = newEl('div', { |
29 base.appendChild(varName); | 37 base.appendChild(varName); |
30 node.appendChild(base); | 38 node.appendChild(base); |
31 this.expression.toHTML(base); | 39 this.expression.toHTML(base); |
32 }; | 40 }; |
33 | 41 |
42 op.prototype.toHTML = function(node) { | |
43 var base = newEl('span', { | |
44 className: 'op' | |
45 }); | |
46 this.left.toHTML(base); | |
47 base.appendChild(newEl('span', { | |
48 textContent: this.op, | |
49 className: 'opname' | |
50 })); | |
51 this.right.toHTML(base); | |
52 node.appendChild(base); | |
53 }; | |
54 | |
34 intlit.prototype.toHTML = function(node) { | 55 intlit.prototype.toHTML = function(node) { |
35 node.appendChild('span', { | 56 node.appendChild(newEl('span', { |
36 className: 'integer', | 57 className: 'integer', |
37 textContent: node.val | 58 textContent: this.val |
38 }); | 59 })); |
39 }; | 60 }; |
40 | 61 |
41 floatlit.prototype.toHTML = function(node) { | 62 floatlit.prototype.toHTML = function(node) { |
42 node.appendChild('span', { | 63 node.appendChild(newEl('span', { |
43 className: 'float', | 64 className: 'float', |
44 textContent: node.val | 65 textContent: this.val |
45 }); | 66 })); |
46 }; | 67 }; |
47 | 68 |
48 strlit.prototype.toHTML = function(node) { | 69 strlit.prototype.toHTML = function(node) { |
49 node.appendChild('span', { | 70 node.appendChild(newEl('span', { |
50 className: 'string', | 71 className: 'string', |
51 textContent: node.val | 72 textContent: this.val |
52 }); | 73 })); |
53 }; | 74 }; |
54 | 75 |
55 funcall.prototype.toHTML = function(node) { | 76 funcall.prototype.toHTML = function(node) { |
77 var base = newEl('div', { | |
78 className: 'funcall' | |
79 }); | |
80 var parts = this.name.split(':'); | |
81 for (var i in parts ) { | |
82 if(parts[i]) { | |
83 base.appendChild(newEl('span', {textContent: parts[i] + ':', className: 'funpart'})); | |
84 if (this.args[i]) { | |
85 this.args[i].toHTML(base); | |
86 } | |
87 } | |
88 } | |
89 for (; i < this.args.length; i++) { | |
90 this.args[i].toHTML(base); | |
91 } | |
92 node.appendChild(base); | |
56 }; | 93 }; |
94 | |
95 symbol.prototype.toHTML = function(node) { | |
96 node.appendChild(newEl('span', { | |
97 className: 'symbol', | |
98 textContent: this.name | |
99 })); | |
100 } |