changeset 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 59e83296e331
files editor.css editor.js
diffstat 2 files changed, 117 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/editor.css	Thu Mar 22 22:52:36 2012 -0700
+++ b/editor.css	Fri Mar 23 18:06:53 2012 -0700
@@ -97,4 +97,64 @@
 	cursor: pointer;
 }
 
+/* AST Nodes */
+#src span
+{
+	border-width: 1px;
+	border-style: solid;
+	border-color: lightgrey;
+	display: inline-block;
+}
 
+
+.object:before
+{
+	content: '#';
+}
+
+.lambda
+{
+	padding-left: 2em;
+}
+
+.lambda > *
+{
+	vertical-align: top;
+}
+
+.lambdabody
+{
+	display: inline-block;
+	margin-left: 2em;
+}
+
+.lambdabody:before
+{
+	content: '{';
+}
+
+.lambda:after
+{
+	display: block;
+	content: '}';
+}
+
+.funcall > .funcall, .assignment > .funcall
+{
+	display: inline-block;
+}
+
+.funcall > .funcall:before
+{
+	content: '(';
+}
+
+.funcall > .funcall:after
+{
+	content: ')';
+}
+
+.string
+{
+	color: #FF1030;
+}
--- a/editor.js	Thu Mar 22 22:52:36 2012 -0700
+++ b/editor.js	Fri Mar 23 18:06:53 2012 -0700
@@ -2,8 +2,7 @@
 
 object.prototype.toHTML = function(node) {
 	var el = newEl('div', {
-		className: 'object',
-		innerHTML: '#'
+		className: 'object'
 	});
 	node.appendChild(el);
 	for (var i in this.messages) {
@@ -13,9 +12,18 @@
 
 lambda.prototype.toHTML = function(node) {
 	var el = newEl('div', {
-		className: 'lambda',
-		textContent: this.args.join(' ')
+		className: 'lambda'
 	});
+	for (var i in this.args) {
+		this.args[i].toHTML(el);
+	}
+	var body = newEl('div', {
+		className: 'lambdabody'
+	});
+	for (var i in this.expressions) {
+		this.expressions[i].toHTML(body);
+	}
+	el.appendChild(body);
 	node.appendChild(el);
 };
 
@@ -31,26 +39,62 @@
 	this.expression.toHTML(base);
 };
 
+op.prototype.toHTML = function(node) {
+	var base = newEl('span', {
+		className: 'op'
+	});
+	this.left.toHTML(base);
+	base.appendChild(newEl('span', {
+		textContent: this.op,
+		className: 'opname'
+	}));
+	this.right.toHTML(base);
+	node.appendChild(base);
+};
+
 intlit.prototype.toHTML = function(node) {
-	node.appendChild('span', {
+	node.appendChild(newEl('span', {
 		className: 'integer',
-		textContent: node.val
-	});
+		textContent: this.val
+	}));
 };
 
 floatlit.prototype.toHTML = function(node) {
-	node.appendChild('span', {
+	node.appendChild(newEl('span', {
 		className: 'float',
-		textContent: node.val
-	});
+		textContent: this.val
+	}));
 };
 
 strlit.prototype.toHTML = function(node) {
-	node.appendChild('span', {
+	node.appendChild(newEl('span', {
 		className: 'string',
-		textContent: node.val
-	});
+		textContent: this.val
+	}));
 };
 
 funcall.prototype.toHTML = function(node) {
+	var base = newEl('div', {
+		className: 'funcall'
+	});
+	var parts = this.name.split(':');
+	for (var i in parts ) {
+		if(parts[i]) {
+			base.appendChild(newEl('span', {textContent: parts[i] + ':', className: 'funpart'}));
+			if (this.args[i]) {
+				this.args[i].toHTML(base);
+			}
+		}
+	}
+	for (; i < this.args.length; i++) {
+		this.args[i].toHTML(base);
+	}
+	node.appendChild(base);
 };
+
+symbol.prototype.toHTML = function(node) {
+	node.appendChild(newEl('span', {
+		className: 'symbol',
+		textContent: this.name
+	}));
+}