Example #1
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)    
Example #2
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)
Example #3
0
 def testletdouble(self):
   f = Var('f')
   eq_(eval(let([(f, lambda_([x], add(x, x)))], f(1))), 2)
Example #4
0
 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)
Example #5
0
 def testLambda(self):
   eq_(eval(lambda_([x], 1)(2)), 1)
   eq_(eval(lambda_([x], x)(2)), 2)
   eq_(eval(lambda_((x, y), add(x, y))(1, 3)), 4)
Example #6
0
 def ___parse___(self, parser): 
   if isinstance(self.x, _Unary) and isinstance(self.x.x, _VarSymbol):
     x = varcache(self.x.x.name)
     return special.set(x, arith.add(x, 1))
   else: return parser.parse(self.x)
Example #7
0
 def test_too_many_unquote(self):
  assert_raises(DaoSyntaxError, eval, quasiquote((unquote(unquote(add(1,1))),2)))
Example #8
0
 def test_unquote_add(self):
   eq_(eval(quasiquote((unquote(add(1,1)),2))), (2,2))
Example #9
0
 def test_unquote_slice1(self):
   assert_raises(DaoSyntaxError, eval, quasiquote(unquote_slice(add(1,1))))
Example #10
0
 def test_too_many_unquote(self):
     assert_raises(DaoSyntaxError, eval,
                   quasiquote((unquote(unquote(add(1, 1))), 2)))
Example #11
0
 def test_unquote_slice(self):
     eq_(
         eval(
             quasiquote((unquote(add(1, 1)), unquote_splice(quote(
                 (3, 4)))))), (2, 3, 4))
Example #12
0
 def test_unquote_add(self):
     eq_(eval(quasiquote((unquote(add(1, 1)), 2))), (2, 2))
Example #13
0
 def test_tuple1(self):
     eq_(eval(quasiquote((1, ))), (1, ))
     eq_(eval(quasiquote((1, 2))), (1, 2))
     eq_(eval(quasiquote((add(1, 1), 2))), ((add, 1, 1), 2))
Example #14
0
 def test_unquote_slice1(self):
     assert_raises(DaoSyntaxError, eval,
                   quasiquote(unquote_splice(add(1, 1))))
Example #15
0
 def test_unquote1(self):
     eq_(eval(quasiquote(unquote(add(1, 1)))), 2)
Example #16
0
 def test_assign2(self):
   eq_(preparse_to_sexpression(put.i.j<<v.i+1), preparse_to_sexpression(special.set_list([i,j], arith.add(i, 1))))
Example #17
0
 def test_unquote1(self):
   eq_(eval(quasiquote(unquote(add(1,1)))), 2)
Example #18
0
 def test_assign2(self):
     eq_(preparse_to_sexpression(put.i.j << v.i + 1),
         preparse_to_sexpression(special.set_list([i, j], arith.add(i, 1))))
Example #19
0
 def test_tuple1(self):
   eq_(eval(quasiquote((1,))), (1,))
   eq_(eval(quasiquote((1,2))), (1,2))
   eq_(eval(quasiquote((add(1,1),2))), ((add,1,1),2))
Example #20
0
 def testdouble(self):
   eq_(eval(function([[x], add(x, x)])(2)), 4) 
Example #21
0
 def test_unquote_slice(self):
   eq_(eval(quasiquote((unquote(add(1,1)),unquote_slice(quote((3,4)))))), (2,3,4))
Example #22
0
 def testArithmetic(self):
   eq_(eval(add(1, 2)), 3) 
   eq_(eval(sub(1, 1)), 0)
   eq_(eval(mul(2, 2)), 4)
   eq_(eval(div(2, 2)), 1)
Example #23
0
 def testeval1(self):
   eq_(eval(eval_(quote(1))), (1))
   eq_(eval(eval_(quote(add(1, 1)))), (2))
Example #24
0
 def ___parse___(self, parser): 
   if isinstance(self.x, _Unary) and isinstance(self.x.x, _VarSymbol):
     x = varcache(self.x.x.name)
     return special.set(x, arith.add(x, 1))
   else: return parser.parse(self.x)