diff editor.js @ 126:a2d2d8e09291

Merge
author Mike Pavone <pavone@retrodev.com>
date Mon, 05 Aug 2013 23:37:17 -0700
parents d5dc9507d612
children 2b25d0ce2946
line wrap: on
line diff
--- a/editor.js	Mon Aug 05 23:36:18 2013 -0700
+++ b/editor.js	Mon Aug 05 23:37:17 2013 -0700
@@ -1,122 +1,203 @@
 
 
-object.prototype.toHTML = function(node) {
+object.prototype.toHTML = function(node, up) {
+	this.up = up;
+	var astNode = this;
 	var el = newEl('div', {
-		className: 'object'
+		className: 'object',
+		onclick: function(event) {
+			main_module.objectClick(this, astNode, event);
+		}
 	});
+	this.domNode = el;
 	node.appendChild(el);
 	for (var i in this.messages) {
-		this.messages[i].toHTML(el);
+		this.messages[i].toHTML(el, this);
 	}
 };
 
-lambda.prototype.toHTML = function(node) {
+lambda.prototype.toHTML = function(node, up) {
+	this.up = up
 	var astNode = this;
 	var el = newEl('div', {
 		className: 'lambda',
 		onclick: function(event) {
-			mainModule.lambdaClick(this, astNode, event);
+			main_module.lambdaClick(this, astNode, event);
 		}
 	});
+	this.domNode = el;
 	var args = newEl('div', {
 		className: 'args'
 	});
 	for (var i in this.args) {
-		this.args[i].toHTML(args);
+		this.args[i].toHTML(args, this);
 	}
 	var body = newEl('div', {
 		className: 'lambdabody'
 	});
 	for (var i in this.expressions) {
-		this.expressions[i].toHTML(body);
+		this.expressions[i].toHTML(body, this);
 	}
 	el.appendChild(args);
 	el.appendChild(body);
 	node.appendChild(el);
 };
 
-assignment.prototype.toHTML = function(node) {
+assignment.prototype.toHTML = function(node, up) {
+	this.up = up;
+	var astNode = this;
 	var base = newEl('div', {
-		className: 'assignment'
+		className: 'assignment',
+		onclick: function(event) {
+			main_module.assignClick(this, astNode, event);
+		}
 	});
 	var varName = newEl('span', {
-		textContent: this.symbol.name + ' <-'
+		textContent: this.symbol.name,
+		className: 'varname'
 	});
+	this.domNode = base;
 	base.appendChild(varName);
 	node.appendChild(base);
-	this.expression.toHTML(base);
+	this.expression.toHTML(base, this);
 };
 
-op.prototype.toHTML = function(node) {
+op.prototype.toHTML = function(node, up) {
+	this.up = up;
+	var astNode = this;
 	var base = newEl('span', {
-		className: 'op'
+		className: 'op',
+		onclick: function(event) {
+			main_module.opClick(this, astNode, event);
+		}
 	});
-	this.left.toHTML(base);
+	this.domNode = base;
+	this.left.toHTML(base, this);
 	base.appendChild(newEl('span', {
 		textContent: this.op,
 		className: 'opname'
 	}));
-	this.right.toHTML(base);
+	if (this.op == '&&' || this.op == '||') {
+		this.right.expressions[0].toHTML(base, this);
+	} else {
+		this.right.toHTML(base, this);
+	}
 	node.appendChild(base);
 };
 
-intlit.prototype.toHTML = function(node) {
-	node.appendChild(newEl('span', {
+intlit.prototype.toHTML = function(node, up) {
+	this.up = up;
+	var astNode = this;
+	this.domNode = newEl('span', {
 		className: 'integer',
-		textContent: this.val
-	}));
+		textContent: this.val,
+		onclick: function(event) {
+			main_module.scalarClick(this, astNode, event);
+		}
+	});
+	node.appendChild(this.domNode);
 };
 
-floatlit.prototype.toHTML = function(node) {
-	node.appendChild(newEl('span', {
+floatlit.prototype.toHTML = function(node, up) {
+	this.up = up;
+	var astNode = this;
+	this.domNode = newEl('span', {
 		className: 'float',
-		textContent: this.val
-	}));
+		textContent: this.val,
+		onclick: function(event) {
+			main_module.scalarClick(this, astNode, event);
+		}
+	});
+	node.appendChild(this.domNode);
 };
 
-strlit.prototype.toHTML = function(node) {
-	node.appendChild(newEl('span', {
+strlit.prototype.toHTML = function(node, up) {
+	this.up = up;
+	var astNode = this;
+	this.domNode = newEl('span', {
 		className: 'string',
 		contentEditable: 'true',
-		textContent: this.val
-	}));
+		textContent: this.val,
+		onclick: function(event) {
+			main_module.scalarClick(this, astNode, event);
+		}
+	});
+	node.appendChild(this.domNode);
 };
 
-funcall.prototype.toHTML = function(node) {
+listlit.prototype.toHTML = function(node, up) {
+	this.up = up;
+	this.domNode = newEl('span', {
+		className: 'list',
+	});
+	for (var i = 0; i < this.val.length; i++) {
+		this.val[i].toHTML(this.domNode, this);
+	}
+	node.appendChild(this.domNode);
+};
+
+arraylit.prototype.toHTML = function(node, up) {
+	this.up = up;
+	this.domNode = newEl('span', {
+		className: 'array',
+	});
+	for (var i = 0; i < this.val.length; i++) {
+		this.val[i].toHTML(this.domNode, this);
+	}
+	node.appendChild(this.domNode);
+};
+
+funcall.prototype.toHTML = function(node, up) {
+	this.up = up;
 	var astNode = this;
 	var base = newEl('div', {
-		className: 'funcall'
+		className: 'funcall',
+		onclick: function(event) {
+			main_module.funClick(this, astNode, event);
+		}
 	});
+	this.domNode = base;
 	if (this.receiver) {
-		this.receiver.toHTML(base);
+		this.receiver.toHTML(base, this);
 	}
 	var parts = this.name.split(':');
 	for (var i in parts ) {
 		if(parts[i]) {
 			base.appendChild(newEl('span', {
 				textContent: parts[i] + (this.receiver && parts.length == 1 ? '' : ':'),
-				className: 'funpart',
-				onclick: function(event) {
-					mainModule.funClick(this, astNode, event);
-				}}));
+				className: 'funpart'
+				}));
 			if (this.args[i]) {
-				this.args[i].toHTML(base);
+				this.args[i].toHTML(base, this);
 			}
 		}
 	}
 	for (; i < this.args.length; i++) {
-		this.args[i].toHTML(base);
+		this.args[i].toHTML(base, this);
 	}
 	node.appendChild(base);
 };
 
-symbol.prototype.toHTML = function(node) {
+symbol.prototype.toHTML = function(node, up) {
+	this.up = up;
 	var astNode = this;
-	node.appendChild(newEl('span', {
+	this.domNode = newEl('span', {
 		className: 'symbol',
 		textContent: this.name,
 		onclick: function(event) {
-			mainModule.symbolClick(this, astNode, event);
+			main_module.symbolClick(this, astNode, event);
 		}
-	}));
+	})
+	node.appendChild(this.domNode);
 }
+
+function getEl(from, idx)
+{
+	return from[idx];
+}
+
+function setEl(to, idx, val)
+{
+	to[idx] = val;
+	return to;
+}