# HG changeset patch # User Mike Pavone # Date 1332822543 25200 # Node ID 068d63627b1604d0878b1fe4bac528e933e76ba1 # Parent 40a85f135be550d528bafb189080b9ed9e5e7bd9 Populate in scope symbol buttons when clicking on a symbol in the source diff -r 40a85f135be5 -r 068d63627b16 compiler.js --- 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; diff -r 40a85f135be5 -r 068d63627b16 editor.css --- 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; } diff -r 40a85f135be5 -r 068d63627b16 editor.js --- 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); + } })); } diff -r 40a85f135be5 -r 068d63627b16 editor.tp --- 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) diff -r 40a85f135be5 -r 068d63627b16 index.html --- 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 @@
-
    -
  • operators
  • -
  • get:
  • -
  • set:
  • -
  • length
  • -
  • if: then: else:
  • -
+
    +
      -
    • builtins
    • <
    • >
    • +
    • @@ -40,10 +34,7 @@
    • &&
    • ||
    -
      -
      -
        -
          +
          • operators
          diff -r 40a85f135be5 -r 068d63627b16 jsbackend.js --- 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; } diff -r 40a85f135be5 -r 068d63627b16 mquery.js --- a/mquery.js Mon Mar 26 00:06:13 2012 -0700 +++ b/mquery.js Mon Mar 26 21:29:03 2012 -0700 @@ -2,7 +2,7 @@ { if (container instanceof Array) { for (var i = 0; i < container.length; i++) { - fun(i, conatiner[i]); + fun(i, container[i]); } } else { for (var i in container) {