示例#1
0
 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
 def test_fails_to_parse(self):
     e = self.assertParseFailure(
         combinators.sep_by1(primitives.match(lambda c: c == ","),
                             primitives.match(lambda c: c == "h",
                                              {"error!"})),
         "ello")
     self.assertEqual({"error!"}, e.expected)
示例#3
0
 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)
示例#4
0
 def test_fails_to_parse_non_ll1(self):
     e = self.assertSimpleParseFailure(
         combinators.option(
             combinators.sequence(primitives.match(lambda c: c == "h"),
                                  primitives.match(lambda c: c == "e"))),
         "hzllo")
     self.assertEqual("z", e.value)
     self.assertEqual(list("llo"), list(e.it))
     self.assertEqual(set(), e.expected)
示例#5
0
 def test_fails_to_parse_second(self):
     e = self.assertSimpleParseFailure(
         combinators.count(5, primitives.match(lambda c: c == "h",
                                               {"error!"})),
         "hello")
     self.assertEqual("e", e.value)
     self.assertEqual(list("llo"), list(e.it))
     self.assertEqual({"error!"}, e.expected)
示例#6
0
文件: string.py 项目: rfw/kessel
def one_of(s):
    """Parse a single character that match a list of characters.

    Args:
      s: Characters to parse.

    Returns:
      The parsing function.
    """

    @combinators.mapf(primitives.match(lambda a: a.char in s, list(s)))
    def _action(a):
        return a.char
    return _action
示例#7
0
 def test_parses(self):
     self.assertParse(primitives.match(lambda c: c == "h"), "h", "ello",
                      "hello")
示例#8
0
文件: string.py 项目: rfw/kessel
def none_of(s):
    @combinators.mapf(primitives.match(lambda a: a.char not in s, list(s)))
    def _action(a):
        return a.char
    return _action
示例#9
0
 def test_parses_second(self):
     self.assertParse(
         combinators.choice(primitives.match(lambda c: c == "h"),
                            primitives.match(lambda c: c == "y")),
         "y", "ello", "yello")
示例#10
0
 def test_parses(self):
     self.assertParse(combinators.try_(primitives.match(lambda c: c == "h")),
                      "h", "ello", "hello")
示例#11
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")
示例#12
0
 def test_fails_to_parse(self):
     e = self.assertSimpleParseFailure(
         combinators.not_followed_by(primitives.match(lambda c: c == "h")),
         "hello")
     self.assertEqual(set(), e.expected)
示例#13
0
 def test_parses_some(self):
     self.assertParse(
         combinators.many1(primitives.match(lambda c: c == "h")), ["h"],
         "ello", "hello")
示例#14
0
 def test_parses(self):
     self.assertParse(
         combinators.not_followed_by(primitives.match(lambda c: c == "h")),
         None, "ello", "ello")
示例#15
0
 def test_fails_to_parse(self):
     self.assertParseFailure(primitives.match(lambda c: c == "h"),
                             "ello")
示例#16
0
 def test_parses(self):
     self.assertParse(
         combinators.sep_by1(primitives.match(lambda c: c == ","),
                             primitives.match(lambda c: c == "h")),
         ["h", "h", "h"], "ello", "h,h,hello")
示例#17
0
 def test_parses_none_2(self):
     self.assertParse(
         combinators.sep_by(primitives.match(lambda c: c == ","),
                            primitives.error({"error!"})),
         [], "hello", "hello")
示例#18
0
 def test_parses_none(self):
     self.assertParse(
         combinators.sep_by(primitives.match(lambda c: c == ","),
                            primitives.match(lambda c: c == "h")),
         [], "ello", "ello")
示例#19
0
 def test_parses(self):
     self.assertParse(
         combinators.between(primitives.match(lambda c: c == "h"),
                             primitives.match(lambda c: c == "l"),
                             primitives.match(lambda c: c == "e")),
         "e", "lo", "hello")
示例#20
0
 def test_fails_to_parse_with_expect(self):
     e = self.assertParseFailure(primitives.match(lambda c: c == "h",
                                                  {"error!"}),
                                 "ello")
     self.assertEqual({"error!"}, e.expected)
示例#21
0
 def test_parse_some(self):
     self.assertParse(
         combinators.sep_by1(primitives.error({"error!"}),
                             primitives.match(lambda c: c == "h")),
         ["h"], "ello", "hello")