Пример #1
0
 def __init__(self, name, grammar):
   self.__form_name__ = name
   if grammar is None:
     self.__form_grammar__ = None
   else:
     #print grammar
     self.__form_grammar__ = to_sexpression(preparse(or_p(grammar, syntax_error)))
   self.__operator_data__ = []
Пример #2
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'])
Пример #3
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)))
Пример #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'])
Пример #5
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)))
Пример #6
0
def eval(exp):
  exp = preparse(exp)
  sexp = to_sexpression(exp)
  return make_solver().eval(sexp)
Пример #7
0
 def test_optional(self):
   x = Var('x')
   assert_raises(NoSolutionFound, eval, preparse(parse_text(~char(x)+char('1'), '1')))
   eq_(eval(parse_text(optional(char(x)), '1')), '1')
   eq_(eval(parse_text(optional(char(x)), '')), True)
Пример #8
0
def eval(exp):
    exp = preparse(exp)
    sexp = to_sexpression(exp)
    return make_solver().eval(sexp)
Пример #9
0
 def test_optional(self):
     x = Var('x')
     assert_raises(NoSolutionFound, eval,
                   preparse(parse_text(~char(x) + char('1'), '1')))
     eq_(eval(parse_text(optional(char(x)), '1')), '1')
     eq_(eval(parse_text(optional(char(x)), '')), True)
Пример #10
0
def element(name, grammar):
  ''' name = element(grammar)'''
  return _lead_element_class(FormTraveller)(name, preparse(grammar))
Пример #11
0
 def testbegin(self):
     eq_(preparse(begin(1, 2)), begin(1, 2))
Пример #12
0
 def testset(self):
     eq_(preparse(set(a, 2)), set(a, 2))
Пример #13
0
 def testquote(self):
     eq_(preparse(quote(x)), quote(x))
Пример #14
0
 def testInteger(self):
     eq_(preparse(1), (1))