Пример #1
0
 def test_if_p(self):
     from dao.builtins.control import if_p
     eq_(eval(if_p(succeed, succeed)), True)
     assert_raises(NoSolutionFound, eval, if_p(succeed, fail))
     # This below unusual semantics is part of the ISO and all de-facto Prolog standards.
     # see SWI-Prolog help.
     assert_raises(NoSolutionFound, eval, if_p(fail, succeed))
     assert_raises(NoSolutionFound, eval, if_p(fail, fail))
Пример #2
0
 def test_if_p(self):
   from dao.builtins.control import if_p
   eq_(eval(if_p(succeed, succeed)), True)
   assert_raises(NoSolutionFound, eval, if_p(succeed, fail))
   # This below unusual semantics is part of the ISO and all de-facto Prolog standards.
   # see SWI-Prolog help.
   assert_raises(NoSolutionFound, eval, if_p(fail, succeed))
   assert_raises(NoSolutionFound, eval, if_p(fail, fail))
Пример #3
0
    ([exp_list], and_p(char('['), spaces0(_), from_sexp(sexpression_list)(exp_list), spaces0(_), char(']'))))),
  
  define(punct_expression, function(
    ([L(quote, exp)], and_p(char("'"), from_sexp(sexpression)(exp))),
    ([L(quasiquote, exp)], and_p(char("`"), from_sexp(sexpression)(exp))),
    ([L(unquote_splice, exp)], and_p(literal(",@"), from_sexp(sexpression)(exp))),
    ([L(unquote, exp)], and_p(char(","), from_sexp(sexpression)(exp))))),
  
  define(sexpression_list, function(
    ([Cons(exp, exp_list)], and_p(from_sexp(sexpression)(exp), from_sexp(maybe_spaces)(), from_sexp(sexpression_list)(exp_list))),
    ([nil], null))),
  
  define(sexpression1, function(
    ([exp], and_p(spaces0(_), from_sexp(sexpression_list)(exp), spaces0(_))))),
  
  define(maybe_spaces, function(
    ([], or_p(if_p(and_p(not_lead_chars('([])'), not_follow_chars('([])'), not_p(eoi)),
                   spaces(_)),
          spaces0(_) ) ) ) ),
  
  define(sexpression, function(
     # dynamic grammar arises!
    ([result], and_p(char('{'), from_sexp(sexpression)(exp2), char('}'), 
                     setvalue(result, eval_(pycall(cons2tuple, exp2))))),

    ([exp], from_sexp(atom)(exp)),
    ([exp], from_sexp(bracket_expression)(exp)),
    ([exp], from_sexp(punct_expression)(exp))),
   ),
  )