Mercurial > repos > tabletprog
view editor.tp @ 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 | 4dd99fde5f63 |
children | 6c8ae6b47ab5 |
line wrap: on
line source
#{ //mquery functions q <- foreign: :query {} qall <- foreign: :query {} each <- foreign: :iterable fun {} addClass <- foreign: :node className {} removeClass <- foreign: :node className {} get <- foreign: :url onSuccess onFail onOther {} //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: #{} } window <- #{} //kernel definitions true <- #{ if:else <- :self trueblock :elseblock { trueblock: } } false <- #{ if:else <- :self trueblock :elseblock { elseblock: } } editFile <- :path { get: path :request { addClass: (q: "body") "editorMode" src <- request getP: "responseText" console log: src ast <- parser parse: src console log: ast ast toHTML: (q: "#src") } } //editor code main <- { //bind handlers for file browser links each: (qall: "a") :idx el { el setP: "onclick" :event { link <- foreign: this editFile: (link getP: "href") foreign: false } } //bind handlers for editor buttons each: (qall: ".controls li") :idx el { el setP: "onclick" :event { srcel <- (q: "#src") srcel setP: "textContent" (srcel getP: "textContent") + (el getP: "textContent") } } (q: "#ops_button") setP: "onclick" :event { addClass: (q: ".controls") "showops" } (q: "#builtin_button") setP: "onclick" :event { removeClass: (q: ".controls") "showops" } path <- (window getP: "location") getP: "pathname" if: (path indexOf: "/edit/") = 0 { editFile: (path substr: 5) } else: {} } }