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__ = []
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'])
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)))
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'])
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)))
def eval(exp): exp = preparse(exp) sexp = to_sexpression(exp) return make_solver().eval(sexp)
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)
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)
def element(name, grammar): ''' name = element(grammar)''' return _lead_element_class(FormTraveller)(name, preparse(grammar))
def testbegin(self): eq_(preparse(begin(1, 2)), begin(1, 2))
def testset(self): eq_(preparse(set(a, 2)), set(a, 2))
def testquote(self): eq_(preparse(quote(x)), quote(x))
def testInteger(self): eq_(preparse(1), (1))