changeset 14:85fb6ba15bc6

Start turning AST into HTML in editor
author Mike Pavone <pavone@retrodev.com>
date Thu, 22 Mar 2012 22:52:36 -0700
parents e69f5ab0a453
children a5ef5af3df0f
files editor.js editor.tp index.html mquery.js
diffstat 4 files changed, 77 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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) {
+};
--- 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
 		}
 	}
--- 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 @@
 	<script src="parser.js"></script>
 	<script src="compiler.js"></script>
 	<script src="jsbackend.js"></script>
+	<script src="editor.js"></script>
 	<script src="scripttags.js"></script>
 	<script src="editor.tp" type="text/tabletprog"></script>
 	<link rel="stylesheet" href="editor.css">
--- 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;
+}
+