Example #1
0
File: string.py Project: rfw/kessel
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)))
Example #2
0
 def test_parses_some(self):
     self.assertParse(
         combinators.many1(primitives.match(lambda c: c == "h")), ["h"],
         "ello", "hello")
Example #3
0
 def test_fails_to_parse(self):
     e = self.assertParseFailure(
         combinators.many1(primitives.error({"error!"})), "hello")
     self.assertEqual({"error!"}, e.expected)
Example #4
0
 def test_parses(self):
     self.assertParse(combinators.many1(primitives.any_), list("hello"), "",
                      "hello")