Mercurial > repos > tabletprog
annotate editor.js @ 92:6abbf2454657
merge
author | William Morgan <bill@mrgn.org> |
---|---|
date | Mon, 23 Jul 2012 01:07:52 -0700 |
parents | 18cec540238a |
children | 648659961e0e |
rev | line source |
---|---|
0 | 1 |
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) { |
28 | 14 var astNode = this; |
14
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
15 var el = newEl('div', { |
28 | 16 className: 'lambda', |
29
18cec540238a
Prevent event bubbling so lambda click handler doesn't get called when clicking on an element inside it
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
17 onclick: function(event) { |
18cec540238a
Prevent event bubbling so lambda click handler doesn't get called when clicking on an element inside it
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
18 mainModule.lambdaClick(this, astNode, event); |
28 | 19 } |
14
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
20 }); |
26
fe593c1df568
Display receiver arg in editor. Improve formatting in editor.
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
21 var args = newEl('div', { |
fe593c1df568
Display receiver arg in editor. Improve formatting in editor.
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
22 className: 'args' |
fe593c1df568
Display receiver arg in editor. Improve formatting in editor.
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
23 }); |
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
|
24 for (var i in this.args) { |
26
fe593c1df568
Display receiver arg in editor. Improve formatting in editor.
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
25 this.args[i].toHTML(args); |
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
|
26 } |
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
|
27 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
|
28 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
|
29 }); |
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
|
30 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
|
31 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
|
32 } |
26
fe593c1df568
Display receiver arg in editor. Improve formatting in editor.
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
33 el.appendChild(args); |
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
|
34 el.appendChild(body); |
14
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
35 node.appendChild(el); |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
36 }; |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
37 |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
38 assignment.prototype.toHTML = function(node) { |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
39 var base = newEl('div', { |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
40 className: 'assignment' |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
41 }); |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
42 var varName = newEl('span', { |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
43 textContent: this.symbol.name + ' <-' |
0 | 44 }); |
14
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
45 base.appendChild(varName); |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
46 node.appendChild(base); |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
47 this.expression.toHTML(base); |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
48 }; |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
49 |
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
|
50 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
|
51 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
|
52 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
|
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 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
|
55 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
|
56 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
|
57 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
|
58 })); |
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 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
|
60 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
|
61 }; |
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
|
62 |
14
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
63 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
|
64 node.appendChild(newEl('span', { |
14
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
65 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
|
66 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
|
67 })); |
14
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 |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
70 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
|
71 node.appendChild(newEl('span', { |
14
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
72 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
|
73 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
|
74 })); |
14
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 |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
77 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
|
78 node.appendChild(newEl('span', { |
14
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
79 className: 'string', |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
80 contentEditable: 'true', |
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
|
81 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
|
82 })); |
14
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
83 }; |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
84 |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
85 funcall.prototype.toHTML = function(node) { |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
86 var astNode = this; |
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
|
87 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
|
88 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
|
89 }); |
26
fe593c1df568
Display receiver arg in editor. Improve formatting in editor.
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
90 if (this.receiver) { |
fe593c1df568
Display receiver arg in editor. Improve formatting in editor.
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
91 this.receiver.toHTML(base); |
fe593c1df568
Display receiver arg in editor. Improve formatting in editor.
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
92 } |
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
|
93 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
|
94 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
|
95 if(parts[i]) { |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
96 base.appendChild(newEl('span', { |
26
fe593c1df568
Display receiver arg in editor. Improve formatting in editor.
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
97 textContent: parts[i] + (this.receiver && parts.length == 1 ? '' : ':'), |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
98 className: 'funpart', |
29
18cec540238a
Prevent event bubbling so lambda click handler doesn't get called when clicking on an element inside it
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
99 onclick: function(event) { |
18cec540238a
Prevent event bubbling so lambda click handler doesn't get called when clicking on an element inside it
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
100 mainModule.funClick(this, astNode, event); |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
101 }})); |
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
|
102 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
|
103 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
|
104 } |
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
|
105 } |
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
|
106 } |
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
|
107 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
|
108 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
|
109 } |
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
|
110 node.appendChild(base); |
14
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
111 }; |
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
|
112 |
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
|
113 symbol.prototype.toHTML = function(node) { |
23
068d63627b16
Populate in scope symbol buttons when clicking on a symbol in the source
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
114 var astNode = this; |
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
|
115 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
|
116 className: 'symbol', |
23
068d63627b16
Populate in scope symbol buttons when clicking on a symbol in the source
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
117 textContent: this.name, |
29
18cec540238a
Prevent event bubbling so lambda click handler doesn't get called when clicking on an element inside it
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
118 onclick: function(event) { |
18cec540238a
Prevent event bubbling so lambda click handler doesn't get called when clicking on an element inside it
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
119 mainModule.symbolClick(this, astNode, event); |
23
068d63627b16
Populate in scope symbol buttons when clicking on a symbol in the source
Mike Pavone <pavone@retrodev.com>
parents:
15
diff
changeset
|
120 } |
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
|
121 })); |
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
|
122 } |