From a892529247281272aecb2b678c456cdd6eb69e24 Mon Sep 17 00:00:00 2001 From: Tim Vieira Date: Sun, 7 Jul 2013 20:25:42 -0400 Subject: [PATCH] make run-doctest.py executable catch errors when retracting rules. --- Makefile | 2 +- run-doctests.py | 1 + src/Dyna/Backend/Python/interpreter.py | 5 ++++- src/Dyna/Backend/Python/post/__init__.py | 2 +- src/Dyna/Backend/Python/term.py | 21 +++++++++++++++------ test/repl/data/english.par | 2 +- 6 files changed, 23 insertions(+), 10 deletions(-) mode change 100644 => 100755 run-doctests.py diff --git a/Makefile b/Makefile index 4e4439c..0b1cd38 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ build: cabal build test tests: build - ( dist/build/dyna-selftests/dyna-selftests ; python run-doctests.py ) + ( dist/build/dyna-selftests/dyna-selftests ; ./run-doctests.py ) # cabal test # Compilation takes a while; for faster iteration while developing, diff --git a/run-doctests.py b/run-doctests.py old mode 100644 new mode 100755 index 0ec1b56..7b4ddc5 --- a/run-doctests.py +++ b/run-doctests.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python from path import path from cStringIO import StringIO diff --git a/src/Dyna/Backend/Python/interpreter.py b/src/Dyna/Backend/Python/interpreter.py index ab12b57..b4b54d8 100644 --- a/src/Dyna/Backend/Python/interpreter.py +++ b/src/Dyna/Backend/Python/interpreter.py @@ -336,7 +336,10 @@ class Interpreter(object): xs.remove(u) assert u not in xs, 'Several occurrences of u in xs' # run initializer in delete mode - rule.init(emit=self.delete_emit) + try: + rule.init(emit=self.delete_emit) + except (TypeError, ZeroDivisionError): + pass else: assert rule.query is not None # remove query handler diff --git a/src/Dyna/Backend/Python/post/__init__.py b/src/Dyna/Backend/Python/post/__init__.py index f4f3e7b..381a54a 100644 --- a/src/Dyna/Backend/Python/post/__init__.py +++ b/src/Dyna/Backend/Python/post/__init__.py @@ -1,7 +1,7 @@ import re as _re from utils import get_module -available = 'trace', 'dump_solution', 'draw_circuit', 'graph', 'save' +available = 'trace', 'dump_solution', 'draw_circuit', 'graph', 'save', 'draw' def run(interp, line): diff --git a/src/Dyna/Backend/Python/term.py b/src/Dyna/Backend/Python/term.py index dae2ad7..0b95982 100644 --- a/src/Dyna/Backend/Python/term.py +++ b/src/Dyna/Backend/Python/term.py @@ -102,17 +102,26 @@ class _Nil(Term): Term.__init__(self, 'nil/0', ()) self.aggregator = NoAggregator self.aslist = [] + def __repr__(self): return '[]' - def __iter__(self): - for a in self.aslist: - if not isinstance(a, Term): - yield a, (None,), a - else: - yield a, (None,), a + def __contains__(self, x): return False + def like_chart(self): + return iter([]) + + def __iter__(self): + return iter([]) + + def __eq__(self, other): + try: + return self.aslist == other.aslist + except AttributeError: + return False + + Nil = _Nil() diff --git a/test/repl/data/english.par b/test/repl/data/english.par index e7c49ba..98cf938 100644 --- a/test/repl/data/english.par +++ b/test/repl/data/english.par @@ -20,4 +20,4 @@ (ROOT (S (NP Papa) (VP (Modal would) (VP (V have) (VP (V (V eat) -ed) (NP (Det his) (N (N sandwich) -s)))))) .) (ROOT (S (NP (Det every) (N sandwich)) (VP (V was) (VP (V (V go) -ing) (VP (V to (V have)) (VP (V been) (Adj delicious)))))) .) (ROOT (S (NP (NP (Det the) (N (Adj (Adj fine) and (Adj blue)) (N woman))) and (NP (Det every) (N man))) (VP (VP (Modal must) (VP (V have) (VP (VP (V (V eat) -ed) (NP (Det two) (N (N sandwich) -s))) and (VP (V (V sleep) -ed))))) (PP (P on) (NP (Det the) (N floor))))) .) -(a b c d) +(ROOT (A a) (B b) (C c) (D d)) -- 2.50.1