annotate editor.js @ 19:132c7756860e

Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
author Mike Pavone <pavone@retrodev.com>
date Sun, 25 Mar 2012 16:11:19 -0700
parents a5ef5af3df0f
children 068d63627b16
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2
14
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
3 object.prototype.toHTML = function(node) {
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
4 var el = newEl('div', {
15
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
5 className: 'object'
14
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
6 });
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
7 node.appendChild(el);
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
8 for (var i in this.messages) {
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
9 this.messages[i].toHTML(el);
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
10 }
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
11 };
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
12
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
13 lambda.prototype.toHTML = function(node) {
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
14 var el = newEl('div', {
15
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
15 className: 'lambda'
14
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
16 });
15
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
17 for (var i in this.args) {
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
18 this.args[i].toHTML(el);
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
19 }
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
20 var body = newEl('div', {
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
21 className: 'lambdabody'
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
22 });
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
23 for (var i in this.expressions) {
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
24 this.expressions[i].toHTML(body);
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
25 }
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
26 el.appendChild(body);
14
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
27 node.appendChild(el);
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
28 };
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
29
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
30 assignment.prototype.toHTML = function(node) {
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
31 var base = newEl('div', {
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
32 className: 'assignment'
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
33 });
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
34 var varName = newEl('span', {
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
35 textContent: this.symbol.name + ' <-'
0
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
36 });
14
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
37 base.appendChild(varName);
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
38 node.appendChild(base);
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
39 this.expression.toHTML(base);
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
40 };
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
41
15
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
42 op.prototype.toHTML = function(node) {
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
43 var base = newEl('span', {
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
44 className: 'op'
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
45 });
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
46 this.left.toHTML(base);
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
47 base.appendChild(newEl('span', {
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
48 textContent: this.op,
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
49 className: 'opname'
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
50 }));
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
51 this.right.toHTML(base);
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
52 node.appendChild(base);
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
53 };
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
54
14
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
55 intlit.prototype.toHTML = function(node) {
15
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
56 node.appendChild(newEl('span', {
14
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
57 className: 'integer',
15
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
58 textContent: this.val
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
59 }));
14
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
60 };
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
61
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
62 floatlit.prototype.toHTML = function(node) {
15
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
63 node.appendChild(newEl('span', {
14
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
64 className: 'float',
15
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
65 textContent: this.val
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
66 }));
14
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
67 };
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
68
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
69 strlit.prototype.toHTML = function(node) {
15
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
70 node.appendChild(newEl('span', {
14
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
71 className: 'string',
15
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
72 textContent: this.val
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
73 }));
14
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
74 };
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
75
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
76 funcall.prototype.toHTML = function(node) {
15
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
77 var base = newEl('div', {
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
78 className: 'funcall'
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
79 });
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
80 var parts = this.name.split(':');
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
81 for (var i in parts ) {
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
82 if(parts[i]) {
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
83 base.appendChild(newEl('span', {textContent: parts[i] + ':', className: 'funpart'}));
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
84 if (this.args[i]) {
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
85 this.args[i].toHTML(base);
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
86 }
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
87 }
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
88 }
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
89 for (; i < this.args.length; i++) {
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
90 this.args[i].toHTML(base);
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
91 }
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
92 node.appendChild(base);
14
85fb6ba15bc6 Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
93 };
15
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
94
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
95 symbol.prototype.toHTML = function(node) {
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
96 node.appendChild(newEl('span', {
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
97 className: 'symbol',
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
98 textContent: this.name
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
99 }));
a5ef5af3df0f Add toHTML methods to the rest of the AST nodes. Cleanup the formatting a bit
Mike Pavone <pavone@retrodev.com>
parents: 14
diff changeset
100 }