Permalink
Browse files

A little refactoring.

  • Loading branch information...
1 parent 85563c7 commit 4797fce218ece57a8e9d5ee4b5757739502f89d9 @luqui committed Jun 21, 2011
Showing with 8 additions and 9 deletions.
  1. +6 −3 StructuralFramework.js
  2. +2 −6 StructuralGrammar.js
View
9 StructuralFramework.js
@@ -282,17 +282,20 @@ $$.Cursor = object({
var tokresult = expr.args[this.pos].head.parse_prefix(text);
if (tokresult) {
var newcursor = tokresult[0];
- var thiscx = new $$.Context(expr.head,
- [].concat(expr.args.slice(0, this.pos), [null], expr.args.slice(this.pos+1)));
+ var thiscx = context_in(expr, this.pos);
var contexts = [].concat(newcursor.zipper.contexts, [thiscx], this.zipper.contexts);
return [new $$.Cursor(
new $$.Zipper(contexts, newcursor.zipper.expr),
newcursor.pos),
tokresult[1] ];
}
- else {
+ else {
return null;
}
+ },
+ cons_context: function(cx) {
+ var cxs = [cx].concat(this.zipper.contexts);
+ return new $$.Cursor(new $$.Zipper(cxs, this.zipper.expr), this.pos);
}
});
View
8 StructuralGrammar.js
@@ -185,15 +185,11 @@ var cursor = function(expr, pos) {
return new SF.Cursor(new SF.Zipper([], expr), pos);
};
-var cons_context = function(cx, cursor) {
- var cxs = [cx].concat(cursor.zipper.contexts);
- return new SF.Cursor(new SF.Zipper(cxs, cursor.zipper.expr), cursor.pos);
-};
-
$$.empty = function(grammar) {
var c = new SF.SynClass({
open: function() { return this.make([]) },
parse_prefix: function(str) {
+ // XXX cursor violates nonempty invariant
return [ cursor(c.make([]), 0), str ]
}
});
@@ -257,7 +253,7 @@ $$.seq = function() {
if (tokresult[1].length < str.length) { // consumed input
rs[i] = null;
var newcx = new SF.Context(c, rs);
- return [ cons_context(newcx, tokresult[0]), tokresult[1] ]
+ return [ tokresult[0].cons_context(newcx), tokresult[1] ]
}
}
else {

0 comments on commit 4797fce

Please sign in to comment.