# HG changeset patch # User Mike Pavone # Date 1332481956 25200 # Node ID 85fb6ba15bc6940fcf9d1474da822ab232e1fb16 # Parent e69f5ab0a4531201dd7769c5132635420bb8ae6e Start turning AST into HTML in editor diff -r e69f5ab0a453 -r 85fb6ba15bc6 editor.js --- a/editor.js Wed Mar 21 23:17:49 2012 -0700 +++ b/editor.js Thu Mar 22 22:52:36 2012 -0700 @@ -1,15 +1,56 @@ -onReady(function() { - each(qall('li'), function (idx,el) { - el.onclick = function (event) { - q('#src').innerHTML += el.innerHTML; - }; +object.prototype.toHTML = function(node) { + var el = newEl('div', { + className: 'object', + innerHTML: '#' + }); + node.appendChild(el); + for (var i in this.messages) { + this.messages[i].toHTML(el); + } +}; + +lambda.prototype.toHTML = function(node) { + var el = newEl('div', { + className: 'lambda', + textContent: this.args.join(' ') + }); + node.appendChild(el); +}; + +assignment.prototype.toHTML = function(node) { + var base = newEl('div', { + className: 'assignment' + }); + var varName = newEl('span', { + textContent: this.symbol.name + ' <-' }); - q('#ops_button').onclick = function (event) { - addClass(this.parentNode.parentNode, 'showops'); - }; - q('#builtin_button').onclick = function (event) { - removeClass(this.parentNode.parentNode, 'showops'); - }; -}); + base.appendChild(varName); + node.appendChild(base); + this.expression.toHTML(base); +}; + +intlit.prototype.toHTML = function(node) { + node.appendChild('span', { + className: 'integer', + textContent: node.val + }); +}; + +floatlit.prototype.toHTML = function(node) { + node.appendChild('span', { + className: 'float', + textContent: node.val + }); +}; + +strlit.prototype.toHTML = function(node) { + node.appendChild('span', { + className: 'string', + textContent: node.val + }); +}; + +funcall.prototype.toHTML = function(node) { +}; diff -r e69f5ab0a453 -r 85fb6ba15bc6 editor.tp --- a/editor.tp Wed Mar 21 23:17:49 2012 -0700 +++ b/editor.tp Thu Mar 22 22:52:36 2012 -0700 @@ -7,10 +7,15 @@ removeClass <- foreign: :node className {} get <- foreign: :url onSuccess onFail onOther {} -//tabletprog JS helpers +//JS interop helpers setP <- foreign: :object property val {} getP <- foreign: :object property {} +//TP Parser +parser <- foreign: #{ + parse <- foreign: :str {} +} + //js builtins console <- foreign: #{ log <- foreign: #{} @@ -24,10 +29,13 @@ link <- foreign: this get: (link getP: "href") :request { addClass: (q: "body") "editorMode" - console log: (request getP: "responseText") - (q: "#src") setP: "textContent" (request getP: "responseText") + src <- request getP: "responseText" + console log: src + ast <- parser parse: src + console log: ast + ast toHTML: (q: "#src") + //(q: "#src") setP: "textContent" (request getP: "responseText") } - console log: "returning false" foreign: false } } diff -r e69f5ab0a453 -r 85fb6ba15bc6 index.html --- a/index.html Wed Mar 21 23:17:49 2012 -0700 +++ b/index.html Thu Mar 22 22:52:36 2012 -0700 @@ -8,6 +8,7 @@ + diff -r e69f5ab0a453 -r 85fb6ba15bc6 mquery.js --- a/mquery.js Wed Mar 21 23:17:49 2012 -0700 +++ b/mquery.js Thu Mar 22 22:52:36 2012 -0700 @@ -108,3 +108,14 @@ ajax('POST', url, data, onSuccess, onFail, onOthers); } +function newEl(tagname, props) +{ + var el = document.createElement(tagname); + if (typeof props == 'object') { + each(props, function (key, val) { + el[key] = val; + }); + } + return el; +} +