# HG changeset patch # User Mike Pavone # Date 1366006186 25200 # Node ID c0bfff39abe38aa098759dd9bacbba70278750a7 # Parent c0cf9444cf889c611229d3471f097695fcdc9bf4 Basic in and out navigation support added to funcall expressions. Added toHTML methods to listlit and arraylit. diff -r c0cf9444cf88 -r c0bfff39abe3 editor.css --- a/editor.css Sun Apr 14 18:16:03 2013 -0700 +++ b/editor.css Sun Apr 14 23:09:46 2013 -0700 @@ -215,6 +215,21 @@ content: '"'; } +.listlit:before +{ + content: '['; +} + +.listlit:after, .arraylit:after +{ + content: ']'; +} + +.arraylit:before +{ + content: '#['; +} + .funpart { color: #108030; diff -r c0cf9444cf88 -r c0bfff39abe3 editor.js --- 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) diff -r c0cf9444cf88 -r c0bfff39abe3 mquery.js --- a/mquery.js Sun Apr 14 18:16:03 2013 -0700 +++ b/mquery.js Sun Apr 14 23:09:46 2013 -0700 @@ -115,7 +115,6 @@ function newEl(tagname, props) { - console.log('tagname:', tagname, 'props:', props); var el = document.createElement(tagname); if (typeof props == 'object') { each(props, function (key, val) { diff -r c0cf9444cf88 -r c0bfff39abe3 src/editor.tp --- a/src/editor.tp Sun Apr 14 18:16:03 2013 -0700 +++ b/src/editor.tp Sun Apr 14 23:09:46 2013 -0700 @@ -40,6 +40,10 @@ } //editor code +selection <- #{ + valid? <- false +} + editFile <- :path { get: path :request { addClass: (q: "body") "editorMode" @@ -74,7 +78,7 @@ each: (qall: ".selectParent") :idx el { removeClass: el "selectParent" } - addClass: (node parentNode) "selectParent" + addClass: node "selectParent" } popInscope:onClick <- :syms :handler { @@ -99,17 +103,39 @@ funClick <- :domnode astnode event { selectParent: domnode - selectQuery: ".selectParent > .funpart" in: (domnode parentNode) + selectQuery: ".selectParent > .funpart" in: domnode symtable <- astnode symbols syms <- filter: (symtable allSymbols: (foreign: undefined)) :sym { isLambda: ((symtable find: sym) def) } + self selection!: #{ + valid? <- true + in <- { + fakeEvent <- #{ + stopPropagation <- :Blah { + } + } + if: (astnode receiver) != (foreign: null) { + ((astnode receiver) domNode) onclick: fakeEvent + } else: { + if: ((astnode args) length) > 0 { + (((astnode args) getEl: 0) domNode) onclick: fakeEvent + } + } + } + out <- { + fakeEvent <- #{ + stopPropagation <- :Blah { + } + } + ((astnode up) domNode) onclick: fakeEvent + } + } popInscope: syms onClick: :key { astnode name!: key parts <- key split: ":" - parent <- domnode parentNode nodes <- [] - each: (parent children) :idx val{ + each: (domnode children) :idx val{ nodes push: val } partIdx <- 0 @@ -126,12 +152,12 @@ node textContent!: (getEl: parts partIdx) . postfix partIdx <- partIdx + 1 } else: { - parent removeChild: node + domnode removeChild: node } lastWasNamePart <- true } else: { if: (not: lastWasNamePart) && partIdx < (parts length) && nodeIdx > 0 { - parent insertBefore: (newEl: "span" #{ + domnode insertBefore: (newEl: "span" #{ className <- "funpart selected" textContent <- (getEl: parts partIdx) . ":" }) node @@ -141,7 +167,7 @@ } } else: { console log: "part: " . (getEl: parts partIdx) - parent appendChild: (newEl: "span" #{ + domnode appendChild: (newEl: "span" #{ className <- "funpart selected" textContent <- (getEl: parts partIdx) . ":" }) @@ -204,10 +230,24 @@ visible <- "showlit" } + (q: "#in") onclick!: :event { + console log: "inwards" + if: (selection valid?) { + selection in + } + } + + (q: "#out") onclick!: :event { + console log: "outwards" + if: (selection valid?) { + selection out + } + } + path <- (window location) pathname if: (path indexOf: "/edit/") = 0 { editFile: (path substr: 5) - } else: {} + } } }