Mercurial > repos > tabletprog
view src/editor.tp @ 105:35006a6e1c47
Fixed more editor coderot and improved syntax/selection coloring a bit.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 11 Apr 2013 09:16:35 -0700 |
parents | 648659961e0e |
children | 152b6cfb98b6 |
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 //import: kernel //editor code editFile <- :path { get: path :request { addClass: (q: "body") "editorMode" src <- request responseText ast <- parser parse: src 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 event { selectNode: domnode popInscope: ((astnode symbols) allSymbols: (foreign: undefined)) onClick: :key { domnode textContent!: key astnode name!: key } event stopPropagation } funClick <- :domnode astnode event { selectParent: domnode selectQuery: ".selectParent > .funpart" in: (domnode parentNode) symtable <- astnode symbols syms <- filter: (symtable allSymbols) :sym { isLambda: ((symtable find: sym) def) } popInscope: syms onClick: {} event stopPropagation } lambdaClick <- :domnode astnode event { symbolClick: domnode astnode event } main <- { get: "/src/" :data { fakeEl <- newEl: "div" #{ innerHTML <- data response } each: (qall: "a" fakeEl) :idx el { if: ((el textContent) = "../") {} else: { nel <- newEl: "a" #{ href <- "/edit/src/" + (el textContent) textContent <- el textContent } nel onclick!: :event { link <- foreign: this path <- link href path <- path substr: (path indexOf: "/edit/") + 5 editFile: path foreign: false } li <- newEl: "li" li appendChild: nel (q: "#browser ul") appendChild: li } } } //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: {} } }