Esempio n. 1
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)), [])
Esempio n. 2
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))
Esempio n. 3
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))
Esempio n. 4
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'])
Esempio n. 5
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)
Esempio n. 6
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'])
Esempio n. 7
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)
Esempio n. 8
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)))
Esempio n. 9
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))
Esempio n. 10
0
        return head(*tuple(sexpression2daoexpression(x) for x in item.tail))
    else:
        return item


X, Expr, ExprList, Result, Y, Expr2 = vars(
    'X, Expr, ExprList, Result, Y, Expr2')

(
    sexpression1, sexpression, bracketExpression, puncExpression,
    sexpressionList, atom_expression, spaces_on_condition, eval_parse_result
) = vars(
    'sexpression1, sexpression, bracketExpression, puncExpression, sexpressionList, '
    'atom_expression, spaces_on_condition, eval_parse_result')

_ = DummyVar('_')

sexpression_rules = [
    (atom_expression,
     function(([X], integer(X)), ([X], dqstring(X)), ([X], symbol(X)))),
    (bracketExpression,
     function(([ExprList],
               and_p(char('('), whitespaces0, sexpressionList(ExprList),
                     whitespaces0, char(')'))),
              ([ExprList],
               and_p(char('['), whitespaces0, sexpressionList(ExprList),
                     whitespaces0, char(']'))))),
    (puncExpression,
     function(
         ([L(quote, Expr)], and_p(char("'"), sexpression(Expr))),
         ([L(quasiquote, Expr)], and_p(char("`"), sexpression(Expr))),
Esempio n. 11
0
 def test_dummy_times(self):
     _, Y = DummyVar('_'), Var('Y')
     eq_(eval(begin(parse_text(times(char(_), 3, _, Y), '234'), Y)),
         ['2', '3', '4'])
Esempio n. 12
0
def getitem_to_list(argument=None):
  if argument is not None:
    _x = DummyVar('_x')
    return and_p(getitem(_x), special.set(argument, to_list(_x)))
  else: return getitem()