Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Got rid of the 'cls' property on EClass. We will use a special combin…

…ator for that.
  • Loading branch information...
commit d47efe477c47300ead51c169c6f323a56433a87f 1 parent 531e41d
@luqui authored
Showing with 27 additions and 18 deletions.
  1. +7 −10 StructuralFramework.js
  2. +20 −8 StructuralGrammar.js
View
17 StructuralFramework.js
@@ -180,9 +180,8 @@ $$.EClass = object({
nav_right: function(zipper) { return zipper.right() }
});
-$$.Exp_box = function(cls, tokenizer) {
+$$.Exp_box = function(tokenizer) {
return new $$.EClass({
- cls: cls,
render: function() {
var epsilon = tokenizer('');
// if it accepts the empty string, then assume that was parsed
@@ -203,24 +202,22 @@ $$.Exp_box = function(cls, tokenizer) {
});
};
-$$.Infix_assoc_box = function(cls, term_cls, term_tokenizer, op_cls, op_tokenizer) {
+$$.Infix_assoc_box = function(term_tokenizer, op_tokenizer) {
return new $$.EClass({
- cls: cls,
make: function() {
- var view = $$.Infix_assoc_view(cls, term_cls, term_tokenizer, op_cls, op_tokenizer);
+ var view = $$.Infix_assoc_view(term_tokenizer, op_tokenizer);
return this.__proto__.make.call(this, view.make.apply(view, arguments));
}
});
};
-$$.Infix_assoc_view = function(cls, term_cls, term_tokenizer, op_cls, op_tokenizer) {
+$$.Infix_assoc_view = function(term_tokenizer, op_tokenizer) {
var slice_zipper = function(zipper, cxargs, args) {
return new Zipper([new $$.Context(zipper.contexts[0].head, cxargs)].concat(zipper.contexts.slice(1)),
new $$.Expr(zipper.expr.head, args));
};
return new $$.EClass({
- cls: cls,
parse_insert: function(expr) {
var self = this;
return function(inp) {
@@ -230,7 +227,7 @@ $$.Infix_assoc_view = function(cls, term_cls, term_tokenizer, op_cls, op_tokeniz
inp = tokresult[1];
var op_tokresult = op_tokenizer(inp);
if (op_tokresult) {
- var term = $$.Exp_box(term_cls, term_tokenizer).make();
+ var term = $$.Exp_box(term_tokenizer).make();
var r = tokresult[0];
return [ new $$.Expr(r.head, r.args.concat([ op_tokresult[0], term ])), op_tokresult[1] ];
}
@@ -245,7 +242,7 @@ $$.Infix_assoc_view = function(cls, term_cls, term_tokenizer, op_cls, op_tokeniz
},
make: function() {
if (arguments.length == 0) { // can't be empty
- return this.make($$.Exp_box(term_cls, term_tokenizer).make());
+ return this.make($$.Exp_box(term_tokenizer).make());
}
else {
// XXX __proto__ instead of prototype?
@@ -382,7 +379,7 @@ $$.Zipper = object({
});
var render_head = function(head, args) {
- var ret = elt('span', { 'class': head.cls });
+ var ret = elt('span');
foreach(head.render.apply(head, args), function(arg) {
ret.append(arg);
});
View
28 StructuralGrammar.js
@@ -12,7 +12,6 @@ var for_kv = function(object, body) {
};
// End CodeCatalog Snippet
-
// CodeCatalog Snippet http://www.codecatalog.net/378/2/
var regexp_tokenizer = function(tokens) {
return function(str) {
@@ -38,6 +37,21 @@ var regexp_tokenizer = function(tokens) {
};
// End CodeCatalog Snippet
+// CodeCatalog Snippet http://www.codecatalog.net/391/1/
+var choice_tokenizer = function(tokenizers) {
+ return function(str) {
+ for (var i = 0; i < tokenizers.length; ++i) {
+ var tokresult = tokenizers[i](str);
+ if (tokresult) {
+ return tokresult;
+ }
+ }
+ return null;
+ };
+};
+// End CodeCatalog Snippet
+
+
// CodeCatalog Snippet http://www.codecatalog.net/368/1/
var arguments_to_array = function(argobj) {
return Array.prototype.slice.call(argobj);
@@ -64,11 +78,9 @@ $$.sym = function(name) {
return function(grammar) { return grammar(name) }
};
-$$.str = function(cls) {
+$$.str = function() {
return function(grammar) {
- return new SF.EClass({
- cls: cls
- })
+ return new SF.EClass({})
}
};
@@ -82,11 +94,11 @@ $$.literal = function(str) {
};
};
-$$.token = function(rx, cls) {
+$$.token = function(rx) {
return function(grammar) {
var toks = {};
- toks[rx.source] = function(m) { return $$.str(cls)(grammar).make(m[0]) };
- return SF.Exp_box(cls, regexp_tokenizer(toks));
+ toks[rx.source] = function(m) { return $$.str()(grammar).make(m[0]) };
+ return SF.Exp_box(regexp_tokenizer(toks));
};
};
Please sign in to comment.
Something went wrong with that request. Please try again.