Mercurial > repos > tabletprog
changeset 23:068d63627b16
Populate in scope symbol buttons when clicking on a symbol in the source
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 26 Mar 2012 21:29:03 -0700 |
parents | 40a85f135be5 |
children | fe3533494ce9 |
files | compiler.js editor.css editor.js editor.tp index.html jsbackend.js mquery.js |
diffstat | 7 files changed, 46 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/compiler.js Mon Mar 26 00:06:13 2012 -0700 +++ b/compiler.js Mon Mar 26 21:29:03 2012 -0700 @@ -45,6 +45,13 @@ } return 'this'; } +osymbols.prototype.allSymbols = function() { + var start = this.parent ? this.parent.allSymbols() : {}; + for (var key in this.names) { + start[key] = this.names[key]; + } + return start; +} function lsymbols(parent) { @@ -93,6 +100,7 @@ this.needsSelfVar = true; } }; +lsymbols.prototype.allSymbols = osymbols.prototype.allSymbols; var mainModule;
--- a/editor.css Mon Mar 26 00:06:13 2012 -0700 +++ b/editor.css Mon Mar 26 21:29:03 2012 -0700 @@ -69,12 +69,19 @@ overflow: auto; } +ul#inscope +{ + height: 100%; + border-bottom-width: 1px !important; + overflow-y: auto; +} + #editor ul:first-child { border-bottom-width: 0px; } -#editor #operators, #editor .showops > #builtin +#editor #operators { display: none; }
--- a/editor.js Mon Mar 26 00:06:13 2012 -0700 +++ b/editor.js Mon Mar 26 21:29:03 2012 -0700 @@ -93,8 +93,12 @@ }; symbol.prototype.toHTML = function(node) { + var astNode = this; node.appendChild(newEl('span', { className: 'symbol', - textContent: this.name + textContent: this.name, + onclick: function() { + return mainModule.symbolClick(this, astNode); + } })); }
--- a/editor.tp Mon Mar 26 00:06:13 2012 -0700 +++ b/editor.tp Mon Mar 26 21:29:03 2012 -0700 @@ -6,6 +6,7 @@ addClass <- foreign: :node className {} removeClass <- foreign: :node className {} get <- foreign: :url onSuccess onFail onOther {} +newEl <- foreign: :tagname props {} //TP Parser parser <- foreign: #{ @@ -14,9 +15,12 @@ //js builtins console <- foreign: #{ - log <- foreign: #{} + log <- foreign: :val {} } window <- #{} +Object <- foreign: #{ + keys <- foreign: :object {} +} //kernel definitions true <- #{ @@ -38,10 +42,23 @@ console log: src ast <- parser parse: src console log: ast + ast populateSymbols: (foreign: null) ast toHTML: (q: "#src") } } +symbolClick <- :domnode astnode { + inscope <- q: "#inscope" + inscope innerHTML!: "" + console log: astnode + syms <- (astnode symbols) allSymbols + each: ((Object keys: syms) sort) :idx key { + inscope appendChild: (newEl: "li" #{ + textContent <- key + }) + } +} + //editor code main <- { //bind handlers for file browser links @@ -67,10 +84,6 @@ addClass: (q: ".controls") "showops" } - (q: "#builtin_button") onclick!: :event { - removeClass: (q: ".controls") "showops" - } - path <- (window location) pathname if: (path indexOf: "/edit/") = 0 { editFile: (path substr: 5)
--- a/index.html Mon Mar 26 00:06:13 2012 -0700 +++ b/index.html Mon Mar 26 21:29:03 2012 -0700 @@ -22,15 +22,9 @@ </div> <div id="editor"> <div class="controls"> - <ul id="builtin"> - <li id="ops_button">operators</li> - <li>get:</li> - <li>set:</li> - <li>length</li> - <li>if: then: else:</li> - </ul> + <ul id="inscope"></ul> + </div><div id="src"></div><div class="controls"> <ul id="operators"> - <li id="builtin_button">builtins</li> <li><</li> <li>></li> <li>+</li> @@ -40,10 +34,7 @@ <li>&&</li> <li>||</li> </ul> - <ul id="inscope"></ul> - </div><div id="src"></div><div class="controls"> - <ul></ul> - <ul></ul> + <ul><li id="ops_button">operators</li></ul> </div> </div> </body>
--- a/jsbackend.js Mon Mar 26 00:06:13 2012 -0700 +++ b/jsbackend.js Mon Mar 26 21:29:03 2012 -0700 @@ -76,9 +76,10 @@ console.log(name.substr(0, name.length-1)); return '(' + rJS + '.' + (new symbol(name.substr(0, name.length-1), this.symbols)).toJS() + ' = ' + args[0] + ', ' + rJS + ')' } else { - var callCode = rJS + '.' + (new symbol(name, this.symbols)).toJS() + '(' + args.join(', ') + ')'; + var callee = rJS + '.' + (new symbol(name, this.symbols)).toJS(); + var callCode = callee + '(' + args.join(', ') + ')'; if (args.length == 0) { - return '(' + rJS + ' instanceof Function ? ' + callCode + ' : ' + callCode.substr(0, callCode.length-2) + ')'; + return '(' + callee + ' instanceof Function ? ' + callCode + ' : ' + callee + ')'; } else { return callCode; }