Mercurial > repos > tabletprog
comparison editor.js @ 113:c0bfff39abe3
Basic in and out navigation support added to funcall expressions. Added toHTML methods to listlit and arraylit.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 14 Apr 2013 23:09:46 -0700 |
parents | d715fb3c39ab |
children | f2b435509301 |
comparison
equal
deleted
inserted
replaced
112:c0cf9444cf88 | 113:c0bfff39abe3 |
---|---|
1 | 1 |
2 | 2 |
3 object.prototype.toHTML = function(node) { | 3 object.prototype.toHTML = function(node, up) { |
4 this.up = up; | |
4 var el = newEl('div', { | 5 var el = newEl('div', { |
5 className: 'object' | 6 className: 'object' |
6 }); | 7 }); |
8 this.domNode = el; | |
7 node.appendChild(el); | 9 node.appendChild(el); |
8 for (var i in this.messages) { | 10 for (var i in this.messages) { |
9 this.messages[i].toHTML(el); | 11 this.messages[i].toHTML(el, this); |
10 } | 12 } |
11 }; | 13 }; |
12 | 14 |
13 lambda.prototype.toHTML = function(node) { | 15 lambda.prototype.toHTML = function(node, up) { |
16 this.up = up | |
14 var astNode = this; | 17 var astNode = this; |
15 var el = newEl('div', { | 18 var el = newEl('div', { |
16 className: 'lambda', | 19 className: 'lambda', |
17 onclick: function(event) { | 20 onclick: function(event) { |
18 main_module.lambdaClick(this, astNode, event); | 21 main_module.lambdaClick(this, astNode, event); |
19 } | 22 } |
20 }); | 23 }); |
24 this.domNode = el; | |
21 var args = newEl('div', { | 25 var args = newEl('div', { |
22 className: 'args' | 26 className: 'args' |
23 }); | 27 }); |
24 for (var i in this.args) { | 28 for (var i in this.args) { |
25 this.args[i].toHTML(args); | 29 this.args[i].toHTML(args, this); |
26 } | 30 } |
27 var body = newEl('div', { | 31 var body = newEl('div', { |
28 className: 'lambdabody' | 32 className: 'lambdabody' |
29 }); | 33 }); |
30 for (var i in this.expressions) { | 34 for (var i in this.expressions) { |
31 this.expressions[i].toHTML(body); | 35 this.expressions[i].toHTML(body, this); |
32 } | 36 } |
33 el.appendChild(args); | 37 el.appendChild(args); |
34 el.appendChild(body); | 38 el.appendChild(body); |
35 node.appendChild(el); | 39 node.appendChild(el); |
36 }; | 40 }; |
37 | 41 |
38 assignment.prototype.toHTML = function(node) { | 42 assignment.prototype.toHTML = function(node, up) { |
43 this.up = up; | |
39 var base = newEl('div', { | 44 var base = newEl('div', { |
40 className: 'assignment' | 45 className: 'assignment' |
41 }); | 46 }); |
42 var varName = newEl('span', { | 47 var varName = newEl('span', { |
43 textContent: this.symbol.name + ' <-' | 48 textContent: this.symbol.name + ' <-' |
44 }); | 49 }); |
50 this.domNode = base; | |
45 base.appendChild(varName); | 51 base.appendChild(varName); |
46 node.appendChild(base); | 52 node.appendChild(base); |
47 this.expression.toHTML(base); | 53 console.log(this.expression); |
54 this.expression.toHTML(base, this); | |
48 }; | 55 }; |
49 | 56 |
50 op.prototype.toHTML = function(node) { | 57 op.prototype.toHTML = function(node, up) { |
58 this.up = up; | |
51 var base = newEl('span', { | 59 var base = newEl('span', { |
52 className: 'op' | 60 className: 'op' |
53 }); | 61 }); |
54 this.left.toHTML(base); | 62 this.domNode = base; |
63 this.left.toHTML(base, this); | |
55 base.appendChild(newEl('span', { | 64 base.appendChild(newEl('span', { |
56 textContent: this.op, | 65 textContent: this.op, |
57 className: 'opname' | 66 className: 'opname' |
58 })); | 67 })); |
59 this.right.toHTML(base); | 68 this.right.toHTML(base, this); |
60 node.appendChild(base); | 69 node.appendChild(base); |
61 }; | 70 }; |
62 | 71 |
63 intlit.prototype.toHTML = function(node) { | 72 intlit.prototype.toHTML = function(node, up) { |
64 node.appendChild(newEl('span', { | 73 this.up = up; |
74 this.domNode = newEl('span', { | |
65 className: 'integer', | 75 className: 'integer', |
66 textContent: this.val | 76 textContent: this.val |
67 })); | 77 }); |
78 node.appendChild(this.domNode); | |
68 }; | 79 }; |
69 | 80 |
70 floatlit.prototype.toHTML = function(node) { | 81 floatlit.prototype.toHTML = function(node, up) { |
71 node.appendChild(newEl('span', { | 82 this.up = up; |
83 this.domNode = newEl('span', { | |
72 className: 'float', | 84 className: 'float', |
73 textContent: this.val | 85 textContent: this.val |
74 })); | 86 }); |
87 node.appendChild(this.domNode); | |
75 }; | 88 }; |
76 | 89 |
77 strlit.prototype.toHTML = function(node) { | 90 strlit.prototype.toHTML = function(node, up) { |
78 node.appendChild(newEl('span', { | 91 this.up = up; |
92 this.domNode = newEl('span', { | |
79 className: 'string', | 93 className: 'string', |
80 contentEditable: 'true', | 94 contentEditable: 'true', |
81 textContent: this.val | 95 textContent: this.val |
82 })); | 96 }); |
97 node.appendChild(this.domNode); | |
83 }; | 98 }; |
84 | 99 |
85 funcall.prototype.toHTML = function(node) { | 100 listlit.prototype.toHTML = function(node, up) { |
101 this.up = up; | |
102 this.domNode = newEl('span', { | |
103 className: 'list', | |
104 }); | |
105 for (var i = 0; i < this.val.length; i++) { | |
106 this.val[i].toHTML(this.domNode, this); | |
107 } | |
108 node.appendChild(this.domNode); | |
109 }; | |
110 | |
111 arraylit.prototype.toHTML = function(node, up) { | |
112 this.up = up; | |
113 this.domNode = newEl('span', { | |
114 className: 'array', | |
115 }); | |
116 for (var i = 0; i < this.val.length; i++) { | |
117 this.val[i].toHTML(this.domNode, this); | |
118 } | |
119 node.appendChild(this.domNode); | |
120 }; | |
121 | |
122 funcall.prototype.toHTML = function(node, up) { | |
123 this.up = up; | |
86 var astNode = this; | 124 var astNode = this; |
87 var base = newEl('div', { | 125 var base = newEl('div', { |
88 className: 'funcall' | 126 className: 'funcall', |
127 onclick: function(event) { | |
128 main_module.funClick(this, astNode, event); | |
129 } | |
89 }); | 130 }); |
131 this.domNode = base; | |
90 if (this.receiver) { | 132 if (this.receiver) { |
91 this.receiver.toHTML(base); | 133 this.receiver.toHTML(base, this); |
92 } | 134 } |
93 var parts = this.name.split(':'); | 135 var parts = this.name.split(':'); |
94 for (var i in parts ) { | 136 for (var i in parts ) { |
95 if(parts[i]) { | 137 if(parts[i]) { |
96 base.appendChild(newEl('span', { | 138 base.appendChild(newEl('span', { |
97 textContent: parts[i] + (this.receiver && parts.length == 1 ? '' : ':'), | 139 textContent: parts[i] + (this.receiver && parts.length == 1 ? '' : ':'), |
98 className: 'funpart', | 140 className: 'funpart' |
99 onclick: function(event) { | 141 })); |
100 main_module.funClick(this, astNode, event); | |
101 }})); | |
102 if (this.args[i]) { | 142 if (this.args[i]) { |
103 this.args[i].toHTML(base); | 143 this.args[i].toHTML(base, this); |
104 } | 144 } |
105 } | 145 } |
106 } | 146 } |
107 for (; i < this.args.length; i++) { | 147 for (; i < this.args.length; i++) { |
108 this.args[i].toHTML(base); | 148 this.args[i].toHTML(base, this); |
109 } | 149 } |
110 node.appendChild(base); | 150 node.appendChild(base); |
111 }; | 151 }; |
112 | 152 |
113 symbol.prototype.toHTML = function(node) { | 153 symbol.prototype.toHTML = function(node, up) { |
154 this.up = up; | |
114 var astNode = this; | 155 var astNode = this; |
115 node.appendChild(newEl('span', { | 156 this.domNode = newEl('span', { |
116 className: 'symbol', | 157 className: 'symbol', |
117 textContent: this.name, | 158 textContent: this.name, |
118 onclick: function(event) { | 159 onclick: function(event) { |
119 main_module.symbolClick(this, astNode, event); | 160 main_module.symbolClick(this, astNode, event); |
120 } | 161 } |
121 })); | 162 }) |
163 node.appendChild(this.domNode); | |
122 } | 164 } |
123 | 165 |
124 function getEl(from, idx) | 166 function getEl(from, idx) |
125 { | 167 { |
126 return from[idx]; | 168 return from[idx]; |