示例#1
0
 def testoptionalcut(self):
     x, s = Var('x'), Var('s')
     ruleList = [(s, function(((x, ), and_p(-char('a'), cut, char(x)))))]
     eq_(eval(let(ruleList, parse_text(s(x), 'aa'), x)), 'a')
     eq_(eval(let(ruleList, parse_text(s(x), 'b'), x)), 'b')
     assert_raises(NoSolutionFound, eval,
                   let(ruleList, parse_text(s(x), 'a'), x))
示例#2
0
 def test_kleene1(self):
     f, item, kleene = Var('f'), Var('item'), Var('kleene')
     fun = macro(((item, ),
                  letr([(f, macro(((), eval_(item), f()), ((), nullword)))],
                       f())))
     eq_(eval(let([(kleene, fun)], set_text('aa'), kleene(char('a')))),
         True)
示例#3
0
 def test_kleene2(self):
   f, pred, kleene = Var('f'), Var('pred'), Var('kleene')
   fun = macro(((pred,),  
                        letr([(f,macro( ((x,), pred(x), f(x)),
                                         ((x,), nullword)))], 
                             f(x))))
   eq_(eval(let([(kleene,fun)], set_text('ab'), kleene(char))), True)
示例#4
0
 def test_chars(self):
     x, cs, chars = Var('x'), Var('cs'), Var('chars')
     eq_(
         eval(
             let([(chars, function(
                 ((x, cs), and_p(char(x), contain(cs, x)))))],
                 parse_text(chars(x, 'a'), 'a'))), True)
示例#5
0
 def test_kleene1(self):
   f, item, kleene = Var('f'), Var('item'), Var('kleene')
   fun = macro(((item,),  
                        letr([(f,macro(((), eval_(item), f()),
                                        ((), nullword)))], 
                             f())))
   eq_(eval(let([(kleene,fun)], set_text('aa'), kleene(char('a')))), True)
示例#6
0
文件: testeval.py 项目: charyorde/dao
 def testLoopWhen(self):
   eq_(eval(tag_loop_label(let([(i,3)], LoopWhenForm((set(i, sub(i, 1)), prin(i)), 
                                    gt(i,0))))), None)
示例#7
0
文件: testeval.py 项目: charyorde/dao
 def testLoopTimes(self):
   eq_(eval(tag_loop_label(let([(i,3)], LoopTimesForm(3, (set(i, sub(i, 1)), prin(i)))))), None)
示例#8
0
文件: testdinpy.py 项目: chaosim/dao
 def test_let2(self):
   let1 = let(v.a<<1).do[prin(1)]
   eq_(preparse(let1), special.let([(a,1)], prin(1)))
示例#9
0
 def test_let2(self):
     let1 = let(v.a << 1).do[prin(1)]
     eq_(preparse(let1), special.let([(a, 1)], prin(1)))
示例#10
0
 def test_nongreedy_optional(self):
     x, s = Var('x'), Var('s')
     ruleList = [(s, function(((x, ), and_p(-char('a'), char(x)))))]
     eq_(eval(let(ruleList, parse_text(s(x), 'a'), x)), 'a')
     eq_(eval(let(ruleList, parse_text(s(x), 'aa'), x)), 'a')
     eq_(eval(let(ruleList, parse_text(s(x), 'b'), x)), 'b')
示例#11
0
文件: testeval.py 项目: charyorde/dao
 def testlet(self):
   eq_(eval(let([(x,1)], x)), (1))
   eq_(eval(let([(x,1)], let([(x,2)], x))), 2)
   eq_(eval(let([(x,1), (y,2)], add(x, y))), 3)
示例#12
0
文件: testeval.py 项目: charyorde/dao
 def testfrom(self):
   a, m = Var('a'), Var('m')
   eq_(eval(let([(m,module(define(a,1)))], from_(m,a))), 1)
示例#13
0
文件: testeval.py 项目: charyorde/dao
 def testblock(self):
   f = Var('f')
   eq_(eval(block('foo', let([(f, lambda_((), exit_block('foo',1)))], 
                           mul(2,block('foo', f()))))), 
       1)
示例#14
0
文件: testeval.py 项目: charyorde/dao
 def test_closure4(self):
   eq_(eval(let([(f, macro([[x], x])),
                 (x, 1)],
            f(x+x))), 2) 
示例#15
0
文件: testeval.py 项目: charyorde/dao
 def test_closure3(self):
   eq_(eval(let([(f, function([[x], prin(x)])),
                 (x, 1)],
            f(x+x))), None) 
示例#16
0
文件: testeval.py 项目: charyorde/dao
 def test_closure2(self):
   eq_(eval(let([(f, macro([[x], prin(x)])),
                 (x, 1)],
            f(x+x))), None) 
示例#17
0
文件: testeval.py 项目: charyorde/dao
 def testdouble2(self):
   f = Var('f')
   eq_(eval(let([(f, function([[x], x+x]))], f(1))), 2) 
   eq_(eval(let([(f, function([[x], x+x]))], f(f(1)))), 4) 
示例#18
0
 def test_let3(self):
     let1 = let(v.a << v.b << 1).do[prin(1)]
     eq_(preparse(let1), special.let(((b, 1), (a, b)), prin(1)))
示例#19
0
文件: testeval.py 项目: charyorde/dao
 def testLoopUntil(self):
   eq_(eval(tag_loop_label(let([(i,3)], LoopUntilForm((set(i, sub(i, 1)), prin(i)), 
                                    eq(i,0))))), None)
示例#20
0
文件: testeval.py 项目: charyorde/dao
 def test_let_set(self):
   eq_(eval(let([(a,1)], set(a,2), a)), 2)
   eq_(eval(let([(a,1)], 
                 let([(b,1)], set(a,2), a))), 2)
示例#21
0
文件: testeval.py 项目: charyorde/dao
 def test_embeded_module(self):
   a, m1, m2 = Var('a'), Var('m1'), Var('m2')
   eq_(eval(let([(m1,module(define(a,1),define(m2, module(define(a,2)))))], 
              from_(from_(m1,m2),a))), 2) 
示例#22
0
文件: testeval.py 项目: charyorde/dao
 def testletdouble(self):
   f = Var('f')
   eq_(eval(let([(f, lambda_([x], add(x, x)))], f(1))), 2)
示例#23
0
 def test_kleene2(self):
     f, pred, kleene = Var('f'), Var('pred'), Var('kleene')
     fun = macro(((pred, ),
                  letr([(f, macro(((x, ), pred(x), f(x)),
                                  ((x, ), nullword)))], f(x))))
     eq_(eval(let([(kleene, fun)], set_text('ab'), kleene(char))), True)
示例#24
0
文件: testdinpy.py 项目: chaosim/dao
 def test_let3(self):
   let1 = let(v.a << v.b << 1).do[prin(1)]
   eq_(preparse(let1), special.let(((b,1), (a,b)), prin(1)))
示例#25
0
 def testoptionalcut(self):
   x, s = Var('x'), Var('s')
   ruleList = [(s, function( ((x,), and_p(-char('a'), cut, char(x)))))]
   eq_(eval(let(ruleList, parse_text(s(x),  'aa'), x)), 'a')         
   eq_(eval(let(ruleList, parse_text(s(x),  'b'), x)), 'b') 
   assert_raises(NoSolutionFound, eval, let(ruleList, parse_text(s(x), 'a'), x))
示例#26
0
文件: testeval.py 项目: charyorde/dao
 def test_let_in_module(self):
   a, m1, m2 = Var('a'), Var('m1'), Var('m2')
   eq_(eval(let([(m1,module(define(a,1), let([(a,2)], define(a,3))))], 
              from_(m1,a))), 1) 
示例#27
0
 def test_let1(self):
     eq_(preparse(let(v.i << 1).do[1, 2]), special.let(((i, 1), ), 1, 2))
示例#28
0
 def test_nongreedy_optional(self):
   x, s = Var('x'), Var('s')
   ruleList =[(s, function( ((x,), and_p(-char('a'),char(x)))))]
   eq_(eval(let(ruleList, parse_text(s(x), 'a'), x)), 'a')
   eq_(eval(let(ruleList, parse_text(s(x),  'aa'), x)), 'a')         
   eq_(eval(let(ruleList, parse_text(s(x),  'b'), x)), 'b')
示例#29
0
文件: testeval.py 项目: charyorde/dao
 def testeval2(self):
   eq_(eval(let([(x,1)], eval_(quote(x)))), 1)
示例#30
0
 def test_chars(self):
   x, cs,chars = Var('x'), Var('cs'), Var('chars')
   eq_(eval(let([(chars, function(((x, cs), and_p(char(x), contain(cs, x)))))],
                           parse_text(chars(x, 'a'), 'a'))), True)
示例#31
0
文件: testeval.py 项目: charyorde/dao
 def testloop(self):
   eq_(eval(let([(i,3)], 
                block(a, set(i, sub(i, 1)), 
                           if_(eq(i, 0), exit_block(a, 1)),
                           continue_block(a)), i)), 0)
示例#32
0
文件: testeval.py 项目: charyorde/dao
 def test_unwind_protect_loop(self):
   eq_(eval(let([(i,3)], 
                block(a, set(i, sub(i, 1)), 
                           if_(eq(i, 0), exit_block(a, 1)),
                           unwind_protect(continue_block(a), prin(2))), i)), 0)
示例#33
0
文件: testdinpy.py 项目: chaosim/dao
 def test_let1(self):
   eq_(preparse(let(v.i << 1).do[1,2]), special.let(((i,1),), 1, 2))