Mercurial > repos > tabletprog
diff 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 |
line wrap: on
line diff
--- a/editor.js Sun Apr 14 18:16:03 2013 -0700 +++ b/editor.js Sun Apr 14 23:09:46 2013 -0700 @@ -1,16 +1,19 @@ -object.prototype.toHTML = function(node) { +object.prototype.toHTML = function(node, up) { + this.up = up; var el = newEl('div', { className: 'object' }); + 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', @@ -18,107 +21,146 @@ 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 base = newEl('div', { className: 'assignment' }); var varName = newEl('span', { textContent: this.symbol.name + ' <-' }); + this.domNode = base; base.appendChild(varName); node.appendChild(base); - this.expression.toHTML(base); + console.log(this.expression); + this.expression.toHTML(base, this); }; -op.prototype.toHTML = function(node) { +op.prototype.toHTML = function(node, up) { + this.up = up; var base = newEl('span', { className: 'op' }); - 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); + 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; + this.domNode = newEl('span', { className: 'integer', textContent: this.val - })); + }); + node.appendChild(this.domNode); }; -floatlit.prototype.toHTML = function(node) { - node.appendChild(newEl('span', { +floatlit.prototype.toHTML = function(node, up) { + this.up = up; + this.domNode = newEl('span', { className: 'float', textContent: this.val - })); + }); + node.appendChild(this.domNode); }; -strlit.prototype.toHTML = function(node) { - node.appendChild(newEl('span', { +strlit.prototype.toHTML = function(node, up) { + this.up = up; + this.domNode = newEl('span', { className: 'string', contentEditable: 'true', textContent: this.val - })); + }); + node.appendChild(this.domNode); +}; + +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); }; -funcall.prototype.toHTML = function(node) { +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) { - main_module.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) { main_module.symbolClick(this, astNode, event); } - })); + }) + node.appendChild(this.domNode); } function getEl(from, idx)