예제 #1
0
 def test_fails_to_parse_non_ll1(self):
     e = self.assertSimpleParseFailure(
         combinators.choice(
             combinators.sequence(primitives.match(lambda c: c == "h"),
                                  primitives.match(lambda c: c == "a")),
             combinators.sequence(primitives.match(lambda c: c == "b"),
                                  primitives.match(lambda c: c == "e"))),
         "hello")
     self.assertEqual("e", e.value)
     self.assertEqual(list("llo"), list(e.it))
     self.assertEqual(set(), e.expected)
예제 #2
0
 def test_fails_to_parse_second(self):
     e = self.assertSimpleParseFailure(
         combinators.sequence(primitives.any_, primitives.error({"error!"})),
         "hello")
     self.assertEqual("e", e.value)
     self.assertEqual(list("llo"), list(e.it))
     self.assertEqual({"error!"}, e.expected)
예제 #3
0
 def test_fails_to_parse_ll2(self):
     e = self.assertParseFailure(
         combinators.try_(combinators.sequence(
             primitives.any_, primitives.any_,
             primitives.error({"error!"}))),
         "test")
     self.assertEqual({"error!"}, e.expected)
예제 #4
0
파일: string.py 프로젝트: rfw/kessel
def literal(s):
    """Parse a predefined literal.

    Args:
      s: The literal to parse.

    Returns:
      The parsing function.
    """

    @combinators.mapf(combinators.sequence(*[char(c) for c in s]))
    def _action(cs):
        return "".join(cs)
    return combinators.choice(combinators.suppress_expect(_action),
                              primitives.error([s]))
예제 #5
0
파일: parser.py 프로젝트: rfw/kessel
 def __add__(self, rhs):
     return Parser(combinators.sequence(self, rhs))
예제 #6
0
 def test_fails_to_parse(self):
     e = self.assertParseFailure(
         combinators.sequence(primitives.error({"error!"}), primitives.any_),
         "hello")
     self.assertEqual({"error!"}, e.expected)
예제 #7
0
 def test_parses(self):
     self.assertParse(
         combinators.sequence(primitives.any_, primitives.any_),
         ["h", "e"], "llo", "hello")
예제 #8
0
 def test_parses_non_ll1(self):
     self.assertParse(
         combinators.not_followed_by(combinators.sequence(
             primitives.match(lambda c: c == "h"),
             primitives.match(lambda c: c == "e"))),
         None, "hllo", "hllo")