Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

started on auto-rebuilding

  • Loading branch information...
commit b083ff4ccb763caff44b18b032ac57b98a31de46 1 parent cfe87b9
@zot authored
View
1  TODO.html
@@ -19,6 +19,7 @@
<li>notebook style interface
<ul>
<li>collapse auto exprs</li>
+<li>command completion</li>
<li>"save output as testcase" -- snapshot input and output as strings and record them as a testcase comment</li>
<li>highlighting fixes
<ul>
View
1  TODO.md
@@ -2,6 +2,7 @@
# TODO
* notebook style interface
* collapse auto exprs
+ * command completion
* "save output as testcase" -- snapshot input and output as strings and record them as a testcase comment
* highlighting fixes
* defs don't work
View
4 leisure.cs
@@ -115,10 +115,12 @@ class CNil extends Cons
global.leisureGetFuncs = -> ll
+global.noredefs = true
+
define = (name, func) ->
nm = nameSub(name)
func.leisureName = name
- if ctx[nm]? then throw new Error("[DEF] Attempt to redefine definition: #{name}")
+ if global.noredefs and ctx[nm]? then throw new Error("[DEF] Attempt to redefine definition: #{name}")
f = -> func
ctx[nm] = ctx.leisureFuncs[nm] = f
(evalFunc 'leisureAddFunc')(name)
View
4 leisure.js
@@ -242,11 +242,13 @@ misrepresented as being the original software.
return ll;
};
+ global.noredefs = true;
+
define = function define(name, func) {
var f, nm;
nm = nameSub(name);
func.leisureName = name;
- if (ctx[nm] != null) {
+ if (global.noredefs && (ctx[nm] != null)) {
throw new Error("[DEF] Attempt to redefine definition: " + name);
}
f = function f() {
View
73 notebook.cs
@@ -53,6 +53,7 @@ makeOutputBox bx
if !s.rangeCount then return
r = s.getRangeAt(0)
parent = getBox r.startContainer
+ focusBox parent
if !parent? or parent.getAttribute('LeisureOutput')? then return
tr = document.createRange()
tr.setStart parent, 0
@@ -60,28 +61,29 @@ makeOutputBox bx
pos = getRangeText(tr).length
txt = parent.textContent
ast = (Leisure.compileNext txt, Leisure.Nil, true, null, true)[0]
- offset = ast.leisureDefPrefix ? 0
- brackets = Leisure.bracket ast, pos + offset
- if oldBrackets[0] != parent or !oldBrackets[1].equals(brackets)
- oldBrackets = [parent, brackets]
- for node in document.querySelectorAll "[LeisureBrackets]"
- unwrap node
- parent.normalize()
- if ast?
- b = brackets
- while b != Leisure.Nil
- span = document.createElement 'span'
- span.setAttribute 'LeisureBrackets', ''
- span.setAttribute 'class', if b == brackets then 'LeisureFunc' else 'LeisureArg'
- r = makeRange parent, b.head.head - offset, b.head.tail.head - offset
- contents = r.cloneContents()
- r.deleteContents()
- r.insertNode span
- span.appendChild contents
- b = b.tail
- s.removeAllRanges()
- parent.normalize()
- s.addRange(makeRange parent, pos, pos)
+ if ast?
+ offset = ast.leisureDefPrefix ? 0
+ brackets = Leisure.bracket ast, pos + offset
+ if oldBrackets[0] != parent or !oldBrackets[1].equals(brackets)
+ oldBrackets = [parent, brackets]
+ for node in document.querySelectorAll "[LeisureBrackets]"
+ unwrap node
+ parent.normalize()
+ if ast?
+ b = brackets
+ while b != Leisure.Nil
+ span = document.createElement 'span'
+ span.setAttribute 'LeisureBrackets', ''
+ span.setAttribute 'class', if b == brackets then 'LeisureFunc' else 'LeisureArg'
+ r = makeRange parent, b.head.head - offset, b.head.tail.head - offset
+ contents = r.cloneContents()
+ r.deleteContents()
+ r.insertNode span
+ span.appendChild contents
+ b = b.tail
+ s.removeAllRanges()
+ parent.normalize()
+ s.addRange(makeRange parent, pos, pos)
getRangeText = (r)-> r.cloneContents().textContent
@@ -127,7 +129,7 @@ toDefBox p
initNotebook = (el)->
el.replacing = true
removeOldDefs el
- pgm = markupDefs findDefs el
+ pgm = markupDefs el, findDefs el
if !(el?.lastChild?.nodeType == 3 and el.lastChild.data[el.lastChild.data.length - 1] == '\n')
el.appendChild textNode('\n')
el.appendChild textNode('\n')
@@ -137,7 +139,7 @@ el.appendChild textNode('\n')
insertControls(el)
pgm
-makeLabel = (text, c)->
+makeLabel = (text, c)->
node = document.createElement 'SPAN'
node.innerHTML = text
node.setAttribute 'class', c
@@ -265,7 +267,7 @@ unwrap node
if txt?.nodeType == 3 and (m = txt.data.match /(^|[^\n])(\n+)$/)
txt.data = txt.data.substring(0, txt.data.length - m[2].length)
-markupDefs = (defs)->
+markupDefs = (el, defs)->
pgm = ''
auto = ''
for i in defs
@@ -278,6 +280,8 @@ bod.appendChild textNode('\n')
bx.appendChild (codeSpan name, 'codeName')
bx.appendChild (textNode(def))
bx.appendChild bod
+ bx.addEventListener 'blur', (-> evalDoc el), true, true
+ bx.leisureOwner = el
pgm += "#{name} #{def} #{body}\n"
else if main.leisureTest
s = codeSpan body, 'codeTest'
@@ -286,6 +290,7 @@ s.appendChild textNode('\n')
bx = box main, 'codeMainTest', true
bx.setAttribute 'class', 'codeMainTest green'
bx.appendChild s
+ bx.leisureOwner = el
else
if main.leisureAuto then auto += "#{body}\n"
s = codeSpan body, 'codeExpr'
@@ -293,6 +298,7 @@ s.appendChild textNode('\n')
s.setAttribute('generatedNL', '')
bx = box main, 'codeMainExpr', true
bx.appendChild s
+ bx.leisureOwner = el
makeOutputBox(bx)
for test in tests
console.log "TEST: #{JSON.stringify(test.leisureTest)}"
@@ -302,6 +308,7 @@ bx.appendChild s
evalOutput = (exBox)->
exBox = getBox exBox
+ focusBox exBox
cleanOutput exBox
d = document.createElement('div')
d.setAttribute 'style', 'float: right'
@@ -357,6 +364,7 @@ bx.appendChild s
node.setAttribute 'class', 'output'
node.setAttribute 'contentEditable', 'false'
node.source = source
+ node.leisureOwner = source.leisureOwner
source.output = node
node.innerHTML = "<div><div style='float: left'><button onclick='Notebook.evalOutput(this)'>-&gt;</button></div><button style='visibility: hidden'></button></div>"
source.parentNode.insertBefore node, source.nextSibling
@@ -494,15 +502,26 @@ nodeEnd child
queueAfterLoad = (func)-> postLoadQueue.push(func)
+###
+# handle focus manually, because focus and blur events don't seem to work in this case
+###
+
+oldFocus = null
+
+focusBox = (box)->
+ if oldFocus?.classList.contains 'codeMain' then evalDoc(box.leisureOwner)
+ oldFocus = box
+
evalDoc = (el)->
[pgm, auto] = initNotebook(el)
try
if auto
auto = "do\n #{auto.trim().replace /\n/, '\n '}\n finishLoading 'fred'"
+ global.noredefs = false
Notebook.queueAfterLoad ->
- Leisure.processDefs(Leisure.eval(ReplCore.generateCode('_doc', pgm, false)), global)
+ Leisure.processDefs(Leisure.eval(ReplCore.generateCode('_doc', pgm, false, false, false)), global)
Leisure.eval(ReplCore.generateCode('_auto', auto, false))
- else Leisure.processDefs(Leisure.eval(ReplCore.generateCode('_doc', pgm, false)), global)
+ else Leisure.processDefs(Leisure.eval(ReplCore.generateCode('_doc', pgm, false, false, false)), global)
catch err
alert(err.stack)
View
85 notebook.js
@@ -4,7 +4,7 @@
*/
(function() {
- var Leisure, Prim, ReplCore, addsLine, bindNotebook, box, changeTheme, changeView, checkMutateFromModification, checkMutateToDef, cleanOutput, codeBox, codeSpan, configureSaveLink, continueRangePosition, createFragment, createNode, delay, envFor, evalDoc, evalOutput, findDefs, getBox, getRangePosition, getRangeText, getRanges, grp, highlightPosition, initNotebook, insertControls, loadProgram, makeLabel, makeOption, makeOutputBox, makeRange, makeTestBox, makeTestCase, markupDefs, nodeEnd, oldBrackets, postLoadQueue, prepExpr, queueAfterLoad, removeOldDefs, req, root, runTests, selInDef, testPat, textNode, toDefBox, toExprBox, unwrap,
+ var Leisure, Prim, ReplCore, addsLine, bindNotebook, box, changeTheme, changeView, checkMutateFromModification, checkMutateToDef, cleanOutput, codeBox, codeSpan, configureSaveLink, continueRangePosition, createFragment, createNode, delay, envFor, evalDoc, evalOutput, findDefs, focusBox, getBox, getRangePosition, getRangeText, getRanges, grp, highlightPosition, initNotebook, insertControls, loadProgram, makeLabel, makeOption, makeOutputBox, makeRange, makeTestBox, makeTestCase, markupDefs, nodeEnd, oldBrackets, oldFocus, postLoadQueue, prepExpr, queueAfterLoad, removeOldDefs, req, root, runTests, selInDef, testPat, textNode, toDefBox, toExprBox, unwrap,
__indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
if ((typeof window !== "undefined" && window !== null) && (!(typeof global !== "undefined" && global !== null) || global === window)) {
@@ -85,6 +85,7 @@
if (!s.rangeCount) return;
r = s.getRangeAt(0);
parent = getBox(r.startContainer);
+ focusBox(parent);
if (!(parent != null) || (parent.getAttribute('LeisureOutput') != null)) {
return;
}
@@ -94,33 +95,35 @@
pos = getRangeText(tr).length;
txt = parent.textContent;
ast = (Leisure.compileNext(txt, Leisure.Nil, true, null, true))[0];
- offset = (_ref = ast.leisureDefPrefix) != null ? _ref : 0;
- brackets = Leisure.bracket(ast, pos + offset);
- if (oldBrackets[0] !== parent || !oldBrackets[1].equals(brackets)) {
- oldBrackets = [parent, brackets];
- _ref2 = document.querySelectorAll("[LeisureBrackets]");
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- node = _ref2[_i];
- unwrap(node);
- }
- parent.normalize();
- if (ast != null) {
- b = brackets;
- while (b !== Leisure.Nil) {
- span = document.createElement('span');
- span.setAttribute('LeisureBrackets', '');
- span.setAttribute('class', b === brackets ? 'LeisureFunc' : 'LeisureArg');
- r = makeRange(parent, b.head.head - offset, b.head.tail.head - offset);
- contents = r.cloneContents();
- r.deleteContents();
- r.insertNode(span);
- span.appendChild(contents);
- b = b.tail;
+ if (ast != null) {
+ offset = (_ref = ast.leisureDefPrefix) != null ? _ref : 0;
+ brackets = Leisure.bracket(ast, pos + offset);
+ if (oldBrackets[0] !== parent || !oldBrackets[1].equals(brackets)) {
+ oldBrackets = [parent, brackets];
+ _ref2 = document.querySelectorAll("[LeisureBrackets]");
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
+ node = _ref2[_i];
+ unwrap(node);
+ }
+ parent.normalize();
+ if (ast != null) {
+ b = brackets;
+ while (b !== Leisure.Nil) {
+ span = document.createElement('span');
+ span.setAttribute('LeisureBrackets', '');
+ span.setAttribute('class', b === brackets ? 'LeisureFunc' : 'LeisureArg');
+ r = makeRange(parent, b.head.head - offset, b.head.tail.head - offset);
+ contents = r.cloneContents();
+ r.deleteContents();
+ r.insertNode(span);
+ span.appendChild(contents);
+ b = b.tail;
+ }
}
+ s.removeAllRanges();
+ parent.normalize();
+ return s.addRange(makeRange(parent, pos, pos));
}
- s.removeAllRanges();
- parent.normalize();
- return s.addRange(makeRange(parent, pos, pos));
}
};
@@ -188,7 +191,7 @@
var pgm, _ref;
el.replacing = true;
removeOldDefs(el);
- pgm = markupDefs(findDefs(el));
+ pgm = markupDefs(el, findDefs(el));
if (!((el != null ? (_ref = el.lastChild) != null ? _ref.nodeType : void 0 : void 0) === 3 && el.lastChild.data[el.lastChild.data.length - 1] === '\n')) {
el.appendChild(textNode('\n'));
el.appendChild(textNode('\n'));
@@ -373,7 +376,7 @@
}
};
- markupDefs = function markupDefs(defs) {
+ markupDefs = function markupDefs(el, defs) {
var auto, bod, body, bx, def, i, main, name, pgm, s, test, tests, _i, _j, _len, _len2;
pgm = '';
auto = '';
@@ -388,6 +391,10 @@
bx.appendChild(codeSpan(name, 'codeName'));
bx.appendChild(textNode(def));
bx.appendChild(bod);
+ bx.addEventListener('blur', (function() {
+ return evalDoc(el);
+ }), true, true);
+ bx.leisureOwner = el;
pgm += "" + name + " " + def + " " + body + "\n";
} else if (main.leisureTest) {
s = codeSpan(body, 'codeTest');
@@ -396,6 +403,7 @@
bx = box(main, 'codeMainTest', true);
bx.setAttribute('class', 'codeMainTest green');
bx.appendChild(s);
+ bx.leisureOwner = el;
} else {
if (main.leisureAuto) auto += "" + body + "\n";
s = codeSpan(body, 'codeExpr');
@@ -403,6 +411,7 @@
s.setAttribute('generatedNL', '');
bx = box(main, 'codeMainExpr', true);
bx.appendChild(s);
+ bx.leisureOwner = el;
makeOutputBox(bx);
}
for (_j = 0, _len2 = tests.length; _j < _len2; _j++) {
@@ -420,6 +429,7 @@
evalOutput = function evalOutput(exBox) {
var d;
exBox = getBox(exBox);
+ focusBox(exBox);
cleanOutput(exBox);
d = document.createElement('div');
d.setAttribute('style', 'float: right');
@@ -505,6 +515,7 @@
node.setAttribute('class', 'output');
node.setAttribute('contentEditable', 'false');
node.source = source;
+ node.leisureOwner = source.leisureOwner;
source.output = node;
node.innerHTML = "<div><div style='float: left'><button onclick='Notebook.evalOutput(this)'>-&gt;</button></div><button style='visibility: hidden'></button></div>";
source.parentNode.insertBefore(node, source.nextSibling);
@@ -714,18 +725,32 @@
return postLoadQueue.push(func);
};
+ /*
+ # handle focus manually, because focus and blur events don't seem to work in this case
+ */
+
+ oldFocus = null;
+
+ focusBox = function focusBox(box) {
+ if (oldFocus != null ? oldFocus.classList.contains('codeMain') : void 0) {
+ evalDoc(box.leisureOwner);
+ }
+ return oldFocus = box;
+ };
+
evalDoc = function evalDoc(el) {
var auto, pgm, _ref;
_ref = initNotebook(el), pgm = _ref[0], auto = _ref[1];
try {
if (auto) {
auto = "do\n " + (auto.trim().replace(/\n/, '\n ')) + "\n finishLoading 'fred'";
+ global.noredefs = false;
Notebook.queueAfterLoad(function() {
- return Leisure.processDefs(Leisure.eval(ReplCore.generateCode('_doc', pgm, false)), global);
+ return Leisure.processDefs(Leisure.eval(ReplCore.generateCode('_doc', pgm, false, false, false)), global);
});
return Leisure.eval(ReplCore.generateCode('_auto', auto, false));
} else {
- return Leisure.processDefs(Leisure.eval(ReplCore.generateCode('_doc', pgm, false)), global);
+ return Leisure.processDefs(Leisure.eval(ReplCore.generateCode('_doc', pgm, false, false, false)), global);
}
} catch (err) {
return alert(err.stack);
View
4 replCore.cs
@@ -123,7 +123,7 @@ processResult result
escape = (str)-> str.replace(/\n/g, '\\n')
-generateCode = (file, contents, loud, handle, nomacros)->
+generateCode = (file, contents, loud, handle, nomacros, check)->
if loud then console.log("Compiling #{file}:\n")
objName = if file? and file.match /\.lsr$/ then file.substring(0, file.length - 4) else file ? '_anonymous'
out = """
@@ -168,7 +168,7 @@ processResult result
while rest and rest.trim()
if loud > 1 and prev != names and names != Leisure.Nil then console.log "Compiling function: #{names.head}"
oldRest = rest
- [ast, err, rest] = Leisure.compileNext rest, globals, null, false, nomacros
+ [ast, err, rest] = Leisure.compileNext rest, globals, null, check, nomacros
if ast?.leisureName?
prev = ast.leisureName
names = names.tail
View
4 replCore.js
@@ -187,7 +187,7 @@
return str.replace(/\n/g, '\\n');
};
- generateCode = function generateCode(file, contents, loud, handle, nomacros) {
+ generateCode = function generateCode(file, contents, loud, handle, nomacros, check) {
var a, ast, c, code, defs, err, errs, globals, i, m, names, nm, objName, oldRest, out, prev, r, rest, src, v, varOut, _len, _ref, _ref2, _ref3, _ref4;
if (loud) console.log("Compiling " + file + ":\n");
objName = (file != null) && file.match(/\.lsr$/) ? file.substring(0, file.length - 4) : file != null ? file : '_anonymous';
@@ -212,7 +212,7 @@
console.log("Compiling function: " + names.head);
}
oldRest = rest;
- _ref3 = Leisure.compileNext(rest, globals, null, false, nomacros), ast = _ref3[0], err = _ref3[1], rest = _ref3[2];
+ _ref3 = Leisure.compileNext(rest, globals, null, check, nomacros), ast = _ref3[0], err = _ref3[1], rest = _ref3[2];
if ((ast != null ? ast.leisureName : void 0) != null) {
prev = ast.leisureName;
names = names.tail;
View
8 update
@@ -2,6 +2,8 @@
for i in *; do
cp ../lambdaCalculus/$i .
done
-git add .
-git commit -m 'update from master'
-git push origin gh-pages
+if [ "$1" != "-t" ]; then
+ git add .
+ git commit -m 'update from master'
+ git push origin gh-pages
+fi
Please sign in to comment.
Something went wrong with that request. Please try again.