Skip to content

Instantly share code, notes, and snippets.

@MarchLiu
Last active August 29, 2015 14:24
Show Gist options
  • Save MarchLiu/787e85cc5515894d2fd5 to your computer and use it in GitHub Desktop.
Save MarchLiu/787e85cc5515894d2fd5 to your computer and use it in GitHub Desktop.
sep and sep1
var sep = function(s, p) {
var fun = function(state){
return choice(sep1(s, p), [])
};
parsec(fun);
return fun;
};
sep.prototype = parsec;
var sep1 = function(s, p) {
var fun = function(state){
p.bind(function(state, x){
var re = new Array()
re[0]=x
re.contact(many(s.then(p)))
})
var result = op(state);
var arr = new Array();
arr.push(result);
arr.contact(sep(op,sp)(state));
};
parsec(fun);
return fun;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment