# HG changeset patch # User Mike Pavone # Date 1332551213 25200 # Node ID a5ef5af3df0fb826c18dbbe82f5c7cc1300d3844 # Parent 85fb6ba15bc6940fcf9d1474da822ab232e1fb16 Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit diff -r 85fb6ba15bc6 -r a5ef5af3df0f editor.css --- 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; +} diff -r 85fb6ba15bc6 -r a5ef5af3df0f editor.js --- 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 + })); +}