def word(s): """Parse a sequence of characters as a single string. Args: s: Allowed characters in the word. Returns: The parsing function. """ @combinators.mapf(combinators.many1(one_of(s))) def _action(cs): return "".join(cs) return combinators.choice(_action, primitives.error(list(s)))
def test_parses_some(self): self.assertParse( combinators.many1(primitives.match(lambda c: c == "h")), ["h"], "ello", "hello")
def test_fails_to_parse(self): e = self.assertParseFailure( combinators.many1(primitives.error({"error!"})), "hello") self.assertEqual({"error!"}, e.expected)
def test_parses(self): self.assertParse(combinators.many1(primitives.any_), list("hello"), "", "hello")