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'])
def test_greedy_some5(self): _ = DummyVar('_') y = LogicVar('y') assert_raises( NoSolution, eval, begin(set_text('aaa'), greedy_some(char(_), _, y), char(_), eoi, y))
def test_any5(self): _ = DummyVar('_') y = LogicVar('y') eq_( eval( begin(set_text('aaa'), any(char(_), _, y), char(_), eoi, getvalue(y))), ['a', 'a'])
def test_some5(self): _ = DummyVar('_') y = LogicVar('y') eq_( eval( begin(set_text('abc'), some(char(_), _, y), char(_), eoi, getvalue(y))), ['a', 'b'])
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'])
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)), [])
def test_times4(self): _ = DummyVar('_') x = LogicVar('x') eq_( eval( begin(set_text('aaa'), times(char(_), 3, _, x), eoi, getvalue(x))), ['a', 'a', 'a'])
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)))
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)
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))
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))
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'])
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'])
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)
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'])
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)
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)))
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))
def test_dummy_times(self): _, Y = DummyVar('_'), Var('Y') eq_(eval(begin(parse_text(times(char(_), 3, _, Y), '234'), Y)), ['2', '3', '4'])