Пример #1
0
 def test_some(self):
     X, Y = Var('X'), Var('Y')
     eq_(eval(begin(parse_text(some(char(X), X, Y), '222'), Y)),
         ['2', '2', '2'])
     eq_(eval(begin(parse_text(some(char(X), X, Y), '234'), Y)), ['2'])
     assert_raises(NoSolutionFound, eval,
                   begin(parse_text(some(char(X), X, Y), ''), Y))
Пример #2
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(NoSolutionFound, eval, begin(parse_text(times_between(char(_), 2, 3, _, Y), '2'), Y))
   assert_raises(NoSolutionFound, eval, begin(parse_text((and_p, times_between(char(_), 2, 3, _, Y), eoi), '2345'), Y))
Пример #3
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)), [])
Пример #4
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(NoSolutionFound, eval,
                   begin(parse_text(times_more(char(_), 3, _, Y), '23'), Y))
Пример #5
0
 def test_times_a2(self):
     X, Y, S = Var('X'), Var('Y'), Var('S')
     function1 = function(((Y, ), times(char('a'), 2, 'a', Y)))
     eq_(eval(begin(parse_text(function1(X), 'aa'), X)), ['a', 'a'])
     assert_raises(NoSolutionFound, eval,
                   begin(parse_text(function1(X), 'a'), X))
     assert_raises(NoSolutionFound, eval,
                   begin(parse_text(and_p(function1(X), eoi), 'aaa'), X))
Пример #6
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(NoSolutionFound, eval,
                   begin(parse_text(some(char(_), _, Y), ''), Y))
Пример #7
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'])
Пример #8
0
 def test_seplist(self):
     X, Y = Var('X'), Var('Y')
     eq_(
         eval(
             begin(parse_text(seplist(char(X), char(','), X, Y), '2,2,2'),
                   Y)), ['2', '2', '2'])
     eq_(
         eval(
             begin(parse_text(seplist(char(X), char(','), X, Y), '2,3,4'),
                   Y)), ['2'])
     eq_(eval(begin(parse_text(seplist(char(X), char(','), X, Y), '2'), Y)),
         ['2'])
     eq_(eval(begin(parse_text(seplist(char(X), char(','), X, Y), ''), Y)),
         [])
Пример #9
0
 def test_any_some(self):
     X, Y = Var('X'), Var('Y')
     eq_(
         eval(
             begin(
                 parse_text(
                     char(X) + any(~char('b') + some(char(X))) + eoi,
                     'abaaaa'), X)), 'a')
Пример #10
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(
         NoSolutionFound, eval,
         preparse(
             begin(parse_text(times_less(char(_), 3, _, Y) + eoi, '2345'),
                   Y)))
Пример #11
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'])
Пример #12
0
 def test_cut2_no_Cut3_begin(self):
   a, b, c, d, x = Var('a'), Var('b'), Var('c'), Var('d'), Var('x')
   eq_(eval(letr([(a, function([[x], begin(b(x),c(x))],
                                [[x], d(x)])),
                    (b, function([[1], 'b1'],
                                [[4], 'b4'])),
                    (c, function([[4], 'c4'])),
                    (d, function([[3], 'd3']))],
            a(x), x)), 4) 
Пример #13
0
def make_expression(text):
  code = begin(
    sexpression_defines, 
    classic_defines, 
    set_text(text),
    from_(classic, program)(exp), 
    eoi,
    eval_(pycall(cons2tuple, exp)))
  return to_sexpression(code)
Пример #14
0
def make_fun6(name, rules, klass): 
  fun = varcache(name)
  rules = preparse(rules)
  if isinstance(rules, AtForm): 
    clauses = [(head if head is not None else (), bodies) 
              for head, bodies in rules.clauses]
    return special.begin(*[insert_def(fun, head, bodies, klass) 
                         for head, bodies in clauses])
  elif isinstance(rules, list):
    return insert_def(fun, head, [rules], klass) 
  else: raise DinpySyntaxError()
Пример #15
0
def make_fun1(name, rules, klass):
  fun = varcache(name)
  if len(rules)==0:
    return replace_def(fun, (), [[]], klass)
  if len(rules)==1:
    return replace_def(fun, preparse(rules[0][0]), preparse(rules[0][1]), klass)
  replaces = []
  for head, bodies in rules:
    head = preparse(head)
    bodies = preparse(bodies)
    replaces .append(replace_def(fun, head, bodies, klass))
  return special.begin(*replaces)  
Пример #16
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(
         NoSolutionFound, eval,
         begin(parse_text(times_between(char(_), 2, 3, _, Y), '2'), Y))
     assert_raises(
         NoSolutionFound, eval,
         begin(
             parse_text((and_p, times_between(char(_), 2, 3, _, Y), eoi),
                        '2345'), Y))
Пример #17
0
def make_fun6(name, rules, klass):
    fun = varcache(name)
    rules = preparse(rules)
    if isinstance(rules, AtForm):
        clauses = [(head if head is not None else (), bodies)
                   for head, bodies in rules.clauses]
        return special.begin(
            *
            [insert_def(fun, head, bodies, klass) for head, bodies in clauses])
    elif isinstance(rules, list):
        return insert_def(fun, head, [rules], klass)
    else:
        raise DinpySyntaxError()
Пример #18
0
def make_fun1(name, rules, klass):
    fun = varcache(name)
    if len(rules) == 0:
        return replace_def(fun, (), [[]], klass)
    if len(rules) == 1:
        return replace_def(fun, preparse(rules[0][0]), preparse(rules[0][1]),
                           klass)
    replaces = []
    for head, bodies in rules:
        head = preparse(head)
        bodies = preparse(bodies)
        replaces.append(replace_def(fun, head, bodies, klass))
    return special.begin(*replaces)
Пример #19
0
 def ___parse___(self, parser):
   # x << y << z << value
   y = parser.parse(self.y)
   if isinstance(self.x, _VarSymbol):
     return special.set(varcache(self.x.name), y)
   if isinstance(self.x, _lshift): 
     vars = _get_assign_vars_chain(self.x)
     i = len(vars)-1
     set_stmts = [special.set(vars[i], y)]
     while i>0:
       i -= 1
       set_stmts.append(special.set(vars[i], vars[i+1]))
     return special.begin(*set_stmts)
   elif isinstance(self.x, tuple) or isinstance(self.x, list):
     vars = self.x
   elif isinstance(self.x, _div):
     vars = _get_assign_vars_list(self.x)
   else: raise DinpySyntaxError()
   return special.set_list(vars, y)
Пример #20
0
 def ___parse___(self, parser):
   # x << y << z << value
   y = parser.parse(self.y)
   if isinstance(self.x, _VarSymbol):
     return special.set(varcache(self.x.name), y)
   if isinstance(self.x, _lshift): 
     vars = _get_assign_vars_chain(self.x)
     i = len(vars)-1
     set_stmts = [special.set(vars[i], y)]
     while i>0:
       i -= 1
       set_stmts.append(special.set(vars[i], vars[i+1]))
     return special.begin(*set_stmts)
   elif isinstance(self.x, tuple) or isinstance(self.x, list):
     vars = self.x
   elif isinstance(self.x, _div):
     vars = _get_assign_vars_list(self.x)
   else: raise DinpySyntaxError()
   return special.set_list(vars, y)
Пример #21
0
 def test_next(self):
   eq_(eval(begin(set_text('ab'), next_char(), next_char())), 'a')
Пример #22
0
 def test_seplist(self):
   X, Y = Var('X'), Var('Y')
   eq_(eval(begin(parse_text(seplist(char(X), char(','), X, Y), '2,2,2'), Y)), ['2','2','2'])
   eq_(eval(begin(parse_text(seplist(char(X), char(','), X, Y), '2,3,4'), Y)), ['2'])
   eq_(eval(begin(parse_text(seplist(char(X), char(','), X, Y), '2'), Y)), ['2'])
   eq_(eval(begin(parse_text(seplist(char(X), char(','), X, Y), ''), Y)), [])
Пример #23
0
 def test_spaces(self):
     x, y = Var('x'), Var('y')
     eq_(eval(begin(parse_text(unify_tabspaces(x), ' '), x)), " ")
     eq_(eval(begin(parse_text(unify_whitespaces(y), "\r\t\n"), y)),
         "\r\t\n")
Пример #24
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(NoSolutionFound, eval, preparse(begin(parse_text(times_less(char(_), 3, _, Y)+eoi, '2345'), Y)))
Пример #25
0
 def test_dummy_times(self):
   _, Y = DummyVar('_'), Var('Y')
   eq_(eval(begin(parse_text(times(char(_), 3, _, Y), '234'), Y)), ['2','3','4'])
Пример #26
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(NoSolutionFound, eval, begin(parse_text(some(char(_), _, Y), ''), Y))
Пример #27
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)), [])
Пример #28
0
 def test_next(self):
     eq_(eval(begin(set_text('ab'), next_char(), next_char())), 'a')
Пример #29
0
 def test_times_an(self):
     X, Y, S, n = Var('X'), Var('Y'), Var('S'), Var('n')
     function1 = function(((Y, ), times(char('a'), n, 'a', Y)))
     eq_(eval(begin(parse_text(function1(X), 'a'), X)), ['a'])
     eq_(eval(begin(parse_text(function1(X), 'aa'), X)), ['a', 'a'])
     eq_(eval(begin(parse_text(function1(X), 'aaa'), X)), ['a', 'a', 'a'])
Пример #30
0
 def test_string(self):
     x, y = Var('x'), Var('y')
     eq_(eval(begin(parse_text(dqstring(x), '"2"'), x)), "2")
     eq_(eval(begin(parse_text(sqstring(y), "'1'"), y)), "1")
Пример #31
0
 def test_step(self):
     eq_(eval(begin(set_text('ab'), step(), step())), 'b')
     eq_(eval(begin(set_text('ab'), step(), left())), 'b')
Пример #32
0
 def test_any(self):
     X, Y = Var('X'), Var('Y')
     eq_(eval(begin(parse_text(any(char(X), X, Y), '222'), Y)),
         ['2', '2', '2'])
     eq_(eval(begin(parse_text(any(char(X), X, Y), '234'), Y)), ['2'])
     eq_(eval(begin(parse_text(any(char(X), X, Y), ''), Y)), [])
Пример #33
0
 def test_position(self):
   eq_(eval(begin(set_text('ab'), position())), 0)
Пример #34
0
 def test_dummy_times(self):
     _, Y = DummyVar('_'), Var('Y')
     eq_(eval(begin(parse_text(times(char(_), 3, _, Y), '234'), Y)),
         ['2', '3', '4'])
Пример #35
0
 def test_skip(self):
   eq_(eval(begin(set_text('abcde'), skip(3), next())), 'd')
   eq_(eval(begin(set_text('abcde'), skip(4), skip(-2), next())), 'c')
Пример #36
0
 def test_some(self):
   X, Y = Var('X'), Var('Y')
   eq_(eval(begin(parse_text(some(char(X), X, Y), '222'), Y)), ['2','2','2'])
   eq_(eval(begin(parse_text(some(char(X), X, Y), '234'), Y)), ['2'])
   assert_raises(NoSolutionFound, eval, begin(parse_text(some(char(X), X, Y), ''), Y))
Пример #37
0
 def test_goto(self):
   eq_(eval(begin(set_text('abcde'), goto(1))), 'bcde')
Пример #38
0
 def test_times(self):
   X, Y = Var('X'), Var('Y')
   eq_(eval(begin(parse_text(times(char(X), 3, X, Y), '222'), Y)), ['2','2','2'])
   assert_raises(NoSolutionFound, eval, parse_text(times(char(X), 3, X, Y), '2234'))
Пример #39
0
 def test_string(self):
   x ,y  = Var('x'), Var('y')
   eq_(eval(begin(parse_text(dqstring(x), '"2"'), x)), "2")
   eq_(eval(begin(parse_text(sqstring(y), "'1'"), y)), "1")
Пример #40
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(NoSolutionFound, eval, begin(parse_text(times_more(char(_), 3, _, Y), '23'), Y))
Пример #41
0
 def test_step(self):
   eq_(eval(begin(set_text('ab'), step(), step())), 'b')
   eq_(eval(begin(set_text('ab'), step(), left())), 'b')
Пример #42
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'])
Пример #43
0
 def test_uLetterdigit(self):
     x, y = Var('x'), Var('y')
     eq_(eval(begin(parse_text(uLetterdigitString(x), '_ad123'), x)),
         "_ad123")
     eq_(eval(begin(parse_text(uLetterdigitString(y), "ad1sff23"), y)),
         "ad1sff23")
Пример #44
0
 def test_times_a2(self): 
   X, Y, S = Var('X'), Var('Y'), Var('S')
   function1 = function(((Y,), times(char('a'), 2, 'a', Y)))
   eq_(eval(begin(parse_text(function1(X),'aa'), X)), ['a', 'a'])
   assert_raises(NoSolutionFound, eval, begin(parse_text(function1(X), 'a'), X))
   assert_raises(NoSolutionFound, eval, begin(parse_text(and_p(function1(X), eoi), 'aaa'), X))
Пример #45
0
 def test_skip(self):
     eq_(eval(begin(set_text('abcde'), skip(3), next())), 'd')
     eq_(eval(begin(set_text('abcde'), skip(4), skip(-2), next())), 'c')
Пример #46
0
 def test_times_an(self): 
   X, Y, S, n = Var('X'), Var('Y'), Var('S'), Var('n')
   function1 = function( ((Y,), times(char('a'), n, 'a', Y)))
   eq_(eval(begin(parse_text(function1(X), 'a'), X)), ['a'])
   eq_(eval(begin(parse_text(function1(X), 'aa'), X)), ['a', 'a'])
   eq_(eval(begin(parse_text(function1(X), 'aaa'), X)), ['a', 'a', 'a'])
Пример #47
0
 def test_skip(self):
     eq_(eval(begin(set_text('abcde'), goto(2), next_char())), 'c')
Пример #48
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'])
Пример #49
0
 def test_goto(self):
     eq_(eval(begin(set_text('abcde'), goto(1))), 'bcde')
Пример #50
0
 def test_left(self):
   eq_(eval(begin(set_text('ab'), left())), 'ab')
Пример #51
0
 def test_any(self):
   X, Y = Var('X'), Var('Y')
   eq_(eval(begin(parse_text(any(char(X), X, Y), '222'), Y)), ['2','2','2'])
   eq_(eval(begin(parse_text(any(char(X), X, Y), '234'), Y)), ['2'])
   eq_(eval(begin(parse_text(any(char(X), X, Y), ''), Y)), [])
Пример #52
0
 def test_subtext(self):
   eq_(eval(begin(set_text('abcde'), subtext(0,3))), 'abc')
Пример #53
0
 def test_times(self):
     X, Y = Var('X'), Var('Y')
     eq_(eval(begin(parse_text(times(char(X), 3, X, Y), '222'), Y)),
         ['2', '2', '2'])
     assert_raises(NoSolutionFound, eval,
                   parse_text(times(char(X), 3, X, Y), '2234'))
Пример #54
0
 def test_skip(self):
   eq_(eval(begin(set_text('abcde'), goto(2), next_char())), 'c')
Пример #55
0
 def test_left(self):
     eq_(eval(begin(set_text('ab'), left())), 'ab')
Пример #56
0
 def test_number(self):
   x, y, z = Var('y'), Var('x'), Var('z')
   eq_(eval(begin(parse_text(number(x), '2'), x)), 2)
   eq_(eval(begin(parse_text(number(y), '234'), y)), 234)
   eq_(eval(begin(parse_text(number(z), '0232'), z)), 154) #0ctal
Пример #57
0
 def test_position(self):
     eq_(eval(begin(set_text('ab'), position())), 0)
Пример #58
0
 def test_spaces(self):
   x ,y  = Var('x'), Var('y')
   eq_(eval(begin(parse_text(spaces(x), ' '), x)), " ")
   eq_(eval(begin(parse_text(spaces(y), "\r\t\n"), y)), "\r\t\n")
Пример #59
0
 def test_subtext(self):
     eq_(eval(begin(set_text('abcde'), subtext(0, 3))), 'abc')