コード例 #1
0
ファイル: test_combinators.py プロジェクト: rfw/kessel
 def test_fails_to_parse_front(self):
     e = self.assertParseFailure(
         combinators.between(primitives.error({"error!"}),
                             primitives.match(lambda c: c == "l"),
                             primitives.match(lambda c: c == "e")),
         "hello")
     self.assertEqual({"error!"}, e.expected)
コード例 #2
0
ファイル: test_combinators.py プロジェクト: rfw/kessel
 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
ファイル: test_combinators.py プロジェクト: rfw/kessel
 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
ファイル: test_combinators.py プロジェクト: rfw/kessel
 def test_fails_to_parse_back(self):
     e = self.assertSimpleParseFailure(
         combinators.between(primitives.match(lambda c: c == "h"),
                             primitives.error({"error!"}),
                             primitives.match(lambda c: c == "e")),
         "hello")
     self.assertEqual("l", e.value)
     self.assertEqual(list("lo"), list(e.it))
     self.assertEqual({"error!"}, e.expected)
コード例 #5
0
ファイル: string.py プロジェクト: 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)))
コード例 #6
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]))
コード例 #7
0
ファイル: test_primitives.py プロジェクト: rfw/kessel
 def test_fails_to_parse(self):
     e = self.assertParseFailure(primitives.error({"error!"}), "hello")
     self.assertEqual({"error!"}, e.expected)
コード例 #8
0
ファイル: test_combinators.py プロジェクト: rfw/kessel
 def test_fails_to_parse(self):
     e = self.assertParseFailure(
         combinators.sequence(primitives.error({"error!"}), primitives.any_),
         "hello")
     self.assertEqual({"error!"}, e.expected)
コード例 #9
0
ファイル: test_combinators.py プロジェクト: rfw/kessel
 def test_fails_to_parse(self):
     e = self.assertParseFailure(
         combinators.choice(primitives.error({"error1!"}),
                            primitives.error({"error2!"})),
         "hello")
     self.assertEqual({"error1!", "error2!"}, e.expected)
コード例 #10
0
ファイル: test_combinators.py プロジェクト: rfw/kessel
 def test_fails_to_parse_2(self):
     e = self.assertParseFailure(
         combinators.sep_by1(primitives.match(lambda c: c == ","),
                             primitives.error({"error!"})),
         "hello")
     self.assertEqual({"error!"}, e.expected)
コード例 #11
0
ファイル: test_combinators.py プロジェクト: rfw/kessel
 def test_parse_some(self):
     self.assertParse(
         combinators.sep_by1(primitives.error({"error!"}),
                             primitives.match(lambda c: c == "h")),
         ["h"], "ello", "hello")
コード例 #12
0
ファイル: test_combinators.py プロジェクト: rfw/kessel
 def test_parses_none_2(self):
     self.assertParse(
         combinators.sep_by(primitives.match(lambda c: c == ","),
                            primitives.error({"error!"})),
         [], "hello", "hello")
コード例 #13
0
ファイル: test_combinators.py プロジェクト: rfw/kessel
 def test_parses_none(self):
     self.assertParse(combinators.many(primitives.error(set())), [], "hello",
                      "hello")
コード例 #14
0
ファイル: test_combinators.py プロジェクト: rfw/kessel
 def test_parses_none(self):
     self.assertParse(combinators.option(primitives.error(set())), None,
                      "hello", "hello")
コード例 #15
0
ファイル: test_combinators.py プロジェクト: rfw/kessel
 def test_fails_to_parse(self):
     e = self.assertParseFailure(
         combinators.count(1, primitives.error({"error!"})), "hello")
     self.assertEqual({"error!"}, e.expected)