Mercurial > repos > tabletprog
view editor.tp @ 25:4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 02 Apr 2012 22:28:48 -0700 |
parents | fe3533494ce9 |
children | 93bbc4c8be95 |
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 {} newEl <- foreign: :tagname props {} //TP Parser parser <- foreign: #{ parse <- foreign: :str {} } isLambda <- foreign: :astnode {} //js builtins console <- foreign: #{ log <- foreign: :val {} } window <- foreign: #{} Object <- foreign: #{ keys <- foreign: :object {} } //kernel definitions true <- #{ if:else <- :self trueblock :elseblock { trueblock: } } false <- #{ if:else <- :self trueblock :elseblock { elseblock: } } filter <- :arr pred { output <- arr slice: 0 0 each: arr :idx el { if: (pred: el) { output push: el } else: {} } output } //editor code editFile <- :path { get: path :request { addClass: (q: "body") "editorMode" src <- request responseText console log: src ast <- parser parse: src console log: ast ast populateSymbols: (foreign: null) ast toHTML: (q: "#src") } } selectNode <- :node { each: (qall: ".selected") :idx el { removeClass: el "selected" } addClass: node "selected" } selectQuery <- :selector { selectQuery: selector in: (foreign: undefined) } selectQuery:in <- :selector :context { each: (qall: ".selected") :idx el { removeClass: el "selected" } each: (qall: selector context) :idx el { addClass: el "selected" } } selectParent <- :node { each: (qall: ".selectParent") :idx el { removeClass: el "selected" } addClass: (node parentNode) "selectParent" } popInscope:onClick <- :syms :handler { inscope <- q: "#inscope" inscope innerHTML!: "" each: syms :idx key { inscope appendChild: (newEl: "li" #{ textContent <- key onclick <- { handler: key } }) } } symbolClick <- :domnode astnode { console log: astnode selectNode: domnode popInscope: ((astnode symbols) allSymbols) onClick: :key { domnode textContent!: key astnode name!: key } } funClick <- :domnode astnode { selectParent: domnode selectQuery: ".selectParent > .funpart" in: (domnode parentNode) symtable <- astnode symbols syms <- filter: (symtable allSymbols) :sym { isLambda: ((symtable find: sym) def) } popInscope: syms } main <- { //bind handlers for file browser links each: (qall: "a") :idx el { el onclick!: :event { link <- foreign: this path <- link href path <- path substr: (path indexOf: "/edit/") + 5 console log: path editFile: path foreign: false } } //bind handlers for editor buttons each: (qall: ".controls li") :idx el { el onclick!: :event { srcel <- (q: "#src") srcel textContent!: (srcel textContent) + (el textContent) } } (q: "#ops_button") onclick!: :event { each: (qall: ".controls") :idx el { addClass: el "showops" } } path <- (window location) pathname if: (path indexOf: "/edit/") = 0 { editFile: (path substr: 5) } else: {} } }