Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add and combinator #37

Open
mattfenwick opened this issue Oct 2, 2016 · 2 comments
Open

add and combinator #37

mattfenwick opened this issue Oct 2, 2016 · 2 comments

Comments

@mattfenwick
Copy link
Owner

mattfenwick commented Oct 2, 2016

Run a bunch of parsers, checking that they all succeed, without advancing the position.
Something like:

// [Parser e s (m t) a] -> Parser e s (m t) [a]
// or [forall a. Parser e s (m t) a] -> Parser e s (m t) ()
function and(parsers) {
  parsers.forEach(checkParser.bind(null, 'and'));
  function f(xs, s) {
    var values = [];
    for (var i = 0; i < parsers.length; i++) {
      var r = parsers[i].parse(xs, s);
      if ( r.status !== 'success' ) {
        return r;
      } else {
        values.push(r.result.value);
      }
    }
    return good(values, xs, s);
  }
  return new Parser(f);
}
@mattfenwick mattfenwick changed the title add and combinator` add and combinator Oct 15, 2016
@mattfenwick
Copy link
Owner Author

mattfenwick commented Oct 15, 2016

Is this different from:

// [Parser e s (m t) a] -> Parser e s (m t) [a]
function and(parsers) {
    parsers.forEach(checkParser.bind(null, 'and'));
    return seq(parsers.map(lookahead));
}

?

@mattfenwick
Copy link
Owner Author

Is there a better name than and? Perhaps all?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant