Ejemplo n.º 1
0
 def test_seplist5(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     eq_(
         eval(
             begin(set_text('a,b,cd'), seplist(char(_), char(','), _, y),
                   char(_), eoi, getvalue(y))), ['a', 'b', 'c'])
Ejemplo n.º 2
0
 def test_greedy_some5(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     assert_raises(
         NoSolution, eval,
         begin(set_text('aaa'), greedy_some(char(_), _, y), char(_), eoi,
               y))
Ejemplo n.º 3
0
 def test_any5(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     eq_(
         eval(
             begin(set_text('aaa'), any(char(_), _, y), char(_), eoi,
                   getvalue(y))), ['a', 'a'])
Ejemplo n.º 4
0
 def test_some5(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     eq_(
         eval(
             begin(set_text('abc'), some(char(_), _, y), char(_), eoi,
                   getvalue(y))), ['a', 'b'])
Ejemplo n.º 5
0
 def test_greedy_some4(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     eq_(
         eval(
             begin(set_text('aaa'), greedy_some(char(_), _, y), eoi,
                   getvalue(y))), ['a', 'a', 'a'])
Ejemplo n.º 6
0
 def test_dummy_any(self):
     _, Y = DummyVar('_'), Var('Y')
     eq_(eval(begin(parse_text(any(char(_), _, Y), '222'), Y)),
         ['2', '2', '2'])
     eq_(eval(begin(parse_text(any(char(_), _, Y), '234'), Y)),
         ['2', '3', '4'])
     eq_(eval(begin(parse_text(any(char(_), _, Y), ''), Y)), [])
Ejemplo n.º 7
0
 def test_times4(self):
     _ = DummyVar('_')
     x = LogicVar('x')
     eq_(
         eval(
             begin(set_text('aaa'), times(char(_), 3, _, x), eoi,
                   getvalue(x))), ['a', 'a', 'a'])
Ejemplo n.º 8
0
 def test_greedy_seplist5(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     assert_raises(
         NoSolution, eval,
         begin(set_text('a,a,a'), greedy_seplist(char(_), char(','), _, y),
               char(_), eoi, getvalue(y)))
Ejemplo n.º 9
0
 def test_kleene2(self):
     f, kleene = MacroVar('f'), MacroVar('kleene')
     _ = DummyVar('_')
     item = Var('item')
     fun = macro((item, ),
                 letrec([(f, macrorules(((), item, f()), ((), nullword)))],
                        f()))
     eq_(eval(let([(kleene, fun)], set_text('ab'), kleene(char(_)))), True)
Ejemplo n.º 10
0
 def test_dummy_times_more(self):
     _, Y = DummyVar('_'), Var('Y')
     eq_(eval(begin(parse_text((times_more, char(_), 3, _, Y), '234'), Y)),
         ['2', '3', '4'])
     eq_(eval(begin(parse_text((times_more, char(_), 3, _, Y), '2345'), Y)),
         ['2', '3', '4', '5'])
     assert_raises(NoSolution, eval,
                   begin(parse_text(times_more(char(_), 3, _, Y), '23'), Y))
Ejemplo n.º 11
0
 def test_dumy_some(self):
     _, Y = DummyVar('_'), Var('Y')
     eq_(eval(begin(parse_text(some(char(_), _, Y), '222'), Y)),
         ['2', '2', '2'])
     eq_(eval(begin(parse_text(some(char(_), _, Y), '234'), Y)),
         ['2', '3', '4'])
     assert_raises(NoSolution, eval,
                   begin(parse_text(some(char(_), _, Y), ''), Y))
Ejemplo n.º 12
0
 def test_lazy_seplist5(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     eq_(
         eval(
             begin(set_text('a,a,aa'), lazy_seplist(char(_), char(','), _,
                                                    y), char(_), eoi,
                   getvalue(y))), ['a', 'a', 'a'])
Ejemplo n.º 13
0
 def test_dummy_times_less_lazy(self):
     _, Y = DummyVar('_'), Var('Y')
     eq_(
         eval(
             preparse(
                 begin(
                     parse_text(
                         times_less(char(_), 3, _, Y, lazy) + char('4'),
                         '234'), Y))), ['2', '3'])
Ejemplo n.º 14
0
 def testIndentUndent(self):
     _, n, s, line = DummyVar('_'), Var('n'), Var('s'), Var('line')
     space = char(' ')
     ruleList = [(s,
                  function(((n, ), some(line(n)), s(add(n, 1))),
                           ((n, ), some(line(n))))),
                 (line,
                  function(((n, ), times(space, n), some(letter(_)),
                            any(space), char('\n'))))]
     eq_(eval(letr(ruleList, parse_text(s(0), 'a\n b\n c\n'))), True)
     eq_(eval(letr(ruleList, parse_text(s(0), 'asd\n bdf\n cdfh\n'))), True)
Ejemplo n.º 15
0
 def test_dummy_seplist(self):
     _, Y = DummyVar('_'), Var('Y')
     eq_(
         eval(
             begin(parse_text(seplist(char(_), char(','), _, Y), '2,2,2'),
                   Y)), ['2', '2', '2'])
     eq_(
         eval(
             begin(parse_text(seplist(char(_), char(','), _, Y), '2,3,4'),
                   Y)), ['2', '3', '4'])
     eq_(eval(begin(parse_text(seplist(char(_), char(','), _, Y), '2'), Y)),
         ['2'])
Ejemplo n.º 16
0
 def testKleene4(self):
     x, _, c, s, kleene = Var('x'), DummyVar('_'), Var('c'), Var('s'), Var(
         'kleene')
     ruleList = [(s, function(((x, ), kleene(_, x)))),
                 (kleene,
                  function(((_, Cons(c, x)), char(c) & kleene(_, x)),
                           ((_, nil), nullword)))]
     eq_(eval(letr(ruleList, parse_text(s(x), 'a'), x)), L('a'))
     eq_(eval(letr(ruleList, parse_text(s(x), 'aa'), x)), L('a', 'a'))
     eq_(eval(letr(ruleList, parse_text(s(x), 'aaa'), x)), L('a', 'a', 'a'))
     eq_(eval(letr(ruleList, parse_text(s(x), 'bbb'), x)), L('b', 'b', 'b'))
     eq_(eval(letr(ruleList, parse_text(s(x), 'abc'), x)), L('a', 'b', 'c'))
     eq_(eval(letr(ruleList, parse_text(s(x), ''), x)), nil)
Ejemplo n.º 17
0
 def test_dummy_times_less(self):
     _, Y = DummyVar('_'), Var('Y')
     eq_(
         eval(
             preparse(
                 begin(
                     parse_text(
                         times_less(char(_), 3, _, Y) + char('4'), '234'),
                     Y))), ['2', '3'])
     eq_(eval(begin(parse_text(times_less(char(_), 3, _, Y), '234'), Y)),
         ['2', '3', '4'])
     eq_(eval(begin(parse_text(times_less(char(_), 3, _, Y), '23'), Y)),
         ['2', '3'])
     assert_raises(
         NoSolution, eval,
         preparse(
             begin(parse_text(times_less(char(_), 3, _, Y) + eoi, '2345'),
                   Y)))
Ejemplo n.º 18
0
 def test_dummy_times_between(self):
     _, Y = DummyVar('_'), Var('Y')
     eq_(
         eval(
             begin(parse_text(times_between(char(_), 2, 3, _, Y), '234'),
                   Y)), ['2', '3', '4'])
     eq_(
         eval(begin(parse_text(times_between(char(_), 2, 3, _, Y), '23'),
                    Y)), ['2', '3'])
     eq_(
         eval(
             begin(parse_text(times_between(char(_), 2, 3, _, Y), '2345'),
                   Y)), ['2', '3', '4'])
     assert_raises(
         NoSolution, eval,
         begin(parse_text(times_between(char(_), 2, 3, _, Y), '2'), Y))
     assert_raises(
         NoSolution, eval,
         begin(
             parse_text((and_p, times_between(char(_), 2, 3, _, Y), eoi),
                        '2345'), Y))
Ejemplo n.º 19
0
 def test_dummy_times(self):
     _, Y = DummyVar('_'), Var('Y')
     eq_(eval(begin(parse_text(times(char(_), 3, _, Y), '234'), Y)),
         ['2', '3', '4'])