comparison editor.js @ 126:a2d2d8e09291

Merge
author Mike Pavone <pavone@retrodev.com>
date Mon, 05 Aug 2013 23:37:17 -0700
parents d5dc9507d612
children 2b25d0ce2946
comparison
equal deleted inserted replaced
125:6f8d868e8da0 126:a2d2d8e09291
1 1
2 2
3 object.prototype.toHTML = function(node) { 3 object.prototype.toHTML = function(node, up) {
4 this.up = up;
5 var astNode = this;
4 var el = newEl('div', { 6 var el = newEl('div', {
5 className: 'object' 7 className: 'object',
6 }); 8 onclick: function(event) {
9 main_module.objectClick(this, astNode, event);
10 }
11 });
12 this.domNode = el;
7 node.appendChild(el); 13 node.appendChild(el);
8 for (var i in this.messages) { 14 for (var i in this.messages) {
9 this.messages[i].toHTML(el); 15 this.messages[i].toHTML(el, this);
10 } 16 }
11 }; 17 };
12 18
13 lambda.prototype.toHTML = function(node) { 19 lambda.prototype.toHTML = function(node, up) {
20 this.up = up
14 var astNode = this; 21 var astNode = this;
15 var el = newEl('div', { 22 var el = newEl('div', {
16 className: 'lambda', 23 className: 'lambda',
17 onclick: function(event) { 24 onclick: function(event) {
18 mainModule.lambdaClick(this, astNode, event); 25 main_module.lambdaClick(this, astNode, event);
19 } 26 }
20 }); 27 });
28 this.domNode = el;
21 var args = newEl('div', { 29 var args = newEl('div', {
22 className: 'args' 30 className: 'args'
23 }); 31 });
24 for (var i in this.args) { 32 for (var i in this.args) {
25 this.args[i].toHTML(args); 33 this.args[i].toHTML(args, this);
26 } 34 }
27 var body = newEl('div', { 35 var body = newEl('div', {
28 className: 'lambdabody' 36 className: 'lambdabody'
29 }); 37 });
30 for (var i in this.expressions) { 38 for (var i in this.expressions) {
31 this.expressions[i].toHTML(body); 39 this.expressions[i].toHTML(body, this);
32 } 40 }
33 el.appendChild(args); 41 el.appendChild(args);
34 el.appendChild(body); 42 el.appendChild(body);
35 node.appendChild(el); 43 node.appendChild(el);
36 }; 44 };
37 45
38 assignment.prototype.toHTML = function(node) { 46 assignment.prototype.toHTML = function(node, up) {
47 this.up = up;
48 var astNode = this;
39 var base = newEl('div', { 49 var base = newEl('div', {
40 className: 'assignment' 50 className: 'assignment',
51 onclick: function(event) {
52 main_module.assignClick(this, astNode, event);
53 }
41 }); 54 });
42 var varName = newEl('span', { 55 var varName = newEl('span', {
43 textContent: this.symbol.name + ' <-' 56 textContent: this.symbol.name,
44 }); 57 className: 'varname'
58 });
59 this.domNode = base;
45 base.appendChild(varName); 60 base.appendChild(varName);
46 node.appendChild(base); 61 node.appendChild(base);
47 this.expression.toHTML(base); 62 this.expression.toHTML(base, this);
48 }; 63 };
49 64
50 op.prototype.toHTML = function(node) { 65 op.prototype.toHTML = function(node, up) {
66 this.up = up;
67 var astNode = this;
51 var base = newEl('span', { 68 var base = newEl('span', {
52 className: 'op' 69 className: 'op',
53 }); 70 onclick: function(event) {
54 this.left.toHTML(base); 71 main_module.opClick(this, astNode, event);
72 }
73 });
74 this.domNode = base;
75 this.left.toHTML(base, this);
55 base.appendChild(newEl('span', { 76 base.appendChild(newEl('span', {
56 textContent: this.op, 77 textContent: this.op,
57 className: 'opname' 78 className: 'opname'
58 })); 79 }));
59 this.right.toHTML(base); 80 if (this.op == '&&' || this.op == '||') {
81 this.right.expressions[0].toHTML(base, this);
82 } else {
83 this.right.toHTML(base, this);
84 }
60 node.appendChild(base); 85 node.appendChild(base);
61 }; 86 };
62 87
63 intlit.prototype.toHTML = function(node) { 88 intlit.prototype.toHTML = function(node, up) {
64 node.appendChild(newEl('span', { 89 this.up = up;
90 var astNode = this;
91 this.domNode = newEl('span', {
65 className: 'integer', 92 className: 'integer',
66 textContent: this.val 93 textContent: this.val,
67 })); 94 onclick: function(event) {
68 }; 95 main_module.scalarClick(this, astNode, event);
69 96 }
70 floatlit.prototype.toHTML = function(node) { 97 });
71 node.appendChild(newEl('span', { 98 node.appendChild(this.domNode);
99 };
100
101 floatlit.prototype.toHTML = function(node, up) {
102 this.up = up;
103 var astNode = this;
104 this.domNode = newEl('span', {
72 className: 'float', 105 className: 'float',
73 textContent: this.val 106 textContent: this.val,
74 })); 107 onclick: function(event) {
75 }; 108 main_module.scalarClick(this, astNode, event);
76 109 }
77 strlit.prototype.toHTML = function(node) { 110 });
78 node.appendChild(newEl('span', { 111 node.appendChild(this.domNode);
112 };
113
114 strlit.prototype.toHTML = function(node, up) {
115 this.up = up;
116 var astNode = this;
117 this.domNode = newEl('span', {
79 className: 'string', 118 className: 'string',
80 contentEditable: 'true', 119 contentEditable: 'true',
81 textContent: this.val 120 textContent: this.val,
82 })); 121 onclick: function(event) {
83 }; 122 main_module.scalarClick(this, astNode, event);
84 123 }
85 funcall.prototype.toHTML = function(node) { 124 });
125 node.appendChild(this.domNode);
126 };
127
128 listlit.prototype.toHTML = function(node, up) {
129 this.up = up;
130 this.domNode = newEl('span', {
131 className: 'list',
132 });
133 for (var i = 0; i < this.val.length; i++) {
134 this.val[i].toHTML(this.domNode, this);
135 }
136 node.appendChild(this.domNode);
137 };
138
139 arraylit.prototype.toHTML = function(node, up) {
140 this.up = up;
141 this.domNode = newEl('span', {
142 className: 'array',
143 });
144 for (var i = 0; i < this.val.length; i++) {
145 this.val[i].toHTML(this.domNode, this);
146 }
147 node.appendChild(this.domNode);
148 };
149
150 funcall.prototype.toHTML = function(node, up) {
151 this.up = up;
86 var astNode = this; 152 var astNode = this;
87 var base = newEl('div', { 153 var base = newEl('div', {
88 className: 'funcall' 154 className: 'funcall',
89 }); 155 onclick: function(event) {
156 main_module.funClick(this, astNode, event);
157 }
158 });
159 this.domNode = base;
90 if (this.receiver) { 160 if (this.receiver) {
91 this.receiver.toHTML(base); 161 this.receiver.toHTML(base, this);
92 } 162 }
93 var parts = this.name.split(':'); 163 var parts = this.name.split(':');
94 for (var i in parts ) { 164 for (var i in parts ) {
95 if(parts[i]) { 165 if(parts[i]) {
96 base.appendChild(newEl('span', { 166 base.appendChild(newEl('span', {
97 textContent: parts[i] + (this.receiver && parts.length == 1 ? '' : ':'), 167 textContent: parts[i] + (this.receiver && parts.length == 1 ? '' : ':'),
98 className: 'funpart', 168 className: 'funpart'
99 onclick: function(event) { 169 }));
100 mainModule.funClick(this, astNode, event);
101 }}));
102 if (this.args[i]) { 170 if (this.args[i]) {
103 this.args[i].toHTML(base); 171 this.args[i].toHTML(base, this);
104 } 172 }
105 } 173 }
106 } 174 }
107 for (; i < this.args.length; i++) { 175 for (; i < this.args.length; i++) {
108 this.args[i].toHTML(base); 176 this.args[i].toHTML(base, this);
109 } 177 }
110 node.appendChild(base); 178 node.appendChild(base);
111 }; 179 };
112 180
113 symbol.prototype.toHTML = function(node) { 181 symbol.prototype.toHTML = function(node, up) {
114 var astNode = this; 182 this.up = up;
115 node.appendChild(newEl('span', { 183 var astNode = this;
184 this.domNode = newEl('span', {
116 className: 'symbol', 185 className: 'symbol',
117 textContent: this.name, 186 textContent: this.name,
118 onclick: function(event) { 187 onclick: function(event) {
119 mainModule.symbolClick(this, astNode, event); 188 main_module.symbolClick(this, astNode, event);
120 } 189 }
121 })); 190 })
191 node.appendChild(this.domNode);
122 } 192 }
193
194 function getEl(from, idx)
195 {
196 return from[idx];
197 }
198
199 function setEl(to, idx, val)
200 {
201 to[idx] = val;
202 return to;
203 }