Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Parse now operates on a context-free expression.

  • Loading branch information...
commit df247357c8ffc7ee7423c0cb326675bef4a827f6 1 parent 9fb94a3
@luqui authored
Showing with 12 additions and 31 deletions.
  1. +2 −2 demo/structural.html
  2. +10 −29 structural.js
View
4 demo/structural.html
@@ -87,9 +87,9 @@
$(document.body).keypress(function(e) {
if (typeof(zipper.expr) !== 'string') {
var ch = String.fromCharCode(e.charCode);
- var tokresult = zipper.expr.head.parse(zipper)(ch);
+ var tokresult = zipper.expr.head.parse(zipper.expr)(ch);
if (tokresult) {
- update(tokresult[0]);
+ update(new Zipper(zipper.contexts, tokresult[0]));
}
}
});
View
39 structural.js
@@ -97,21 +97,6 @@ var regexp_tokenizer = function(tokens) {
};
// End CodeCatalog Snippet
-// CodeCatalog Snippet http://www.codecatalog.net/381/1/
-var multi_tokenizer = function(tokenizer) {
- return function(str) {
- var tokresult = tokenizer(str);
- var ret = [];
- while (tokresult) {
- ret.push(tokresult[0]);
- str = tokresult[1];
- tokresult = tokenizer(str);
- }
- return [ret, str];
- };
-};
-// End CodeCatalog Snippet
-
// CodeCatalog Snippet http://www.codecatalog.net/383/1/
var map_tokenizer = function(f, tokenizer) {
return function(str) {
@@ -162,8 +147,7 @@ var EClass = object({
render: function() {
return arguments_to_array(arguments);
},
- parse: function(zipper) {
- var expr = zipper.expr;
+ parse: function(expr) {
return function(inp) {
var new_args = expr.args.slice(0);
for (var i = 0; i < expr.args.length; i++) {
@@ -173,9 +157,9 @@ var EClass = object({
continue;
}
- var tokresult = arg.head.parse(zipper.down(i))(inp);
+ var tokresult = arg.head.parse(arg)(inp);
if (tokresult) {
- new_args[i] = tokresult[0].expr; // what if the context was changed!
+ new_args[i] = tokresult[0];
inp = tokresult[1];
}
else {
@@ -183,7 +167,7 @@ var EClass = object({
else return null; // legit failure
}
}
- return [new Zipper(zipper.contexts, new Expr(expr.head, new_args)), inp];
+ return [new Expr(expr.head, new_args), inp];
}
}
});
@@ -205,13 +189,16 @@ var Exp_box = function(cls, tokenizer) {
return [ elt('span', { 'class': 'box' }, text_node(' '))]
}
},
- parse: function(zipper) {
- return map_tokenizer(function(expr) {
- return new Zipper(zipper.contexts, expr) }, tokenizer)
+ parse: function(expr) {
+ return tokenizer;
}
});
};
+var Infix_assoc_box = function(cls, term_tokenizer, op_tokenizer) {
+
+};
+
var Context = object({
init: function(head, args) { // exactly one of args will be null, this is where the "hole" is
@@ -263,12 +250,6 @@ var Zipper = object({
},
});
-var zipper_leaves = function(z) {
- if (z.arity == 0) { return [z] }
- return flatten(
- range(0,arity).map(function(i) { return zipper_leaves(z.down(i)) }));
-};
-
var render_head = function(head, args) {
var ret = elt('span', { 'class': head.cls });
foreach(head.render.apply(head, args), function(arg) {
Please sign in to comment.
Something went wrong with that request. Please try again.