]> hydra-www.ietfng.org Git - dyna2/commitdiff
Backchained items are no longer displayed in solution.
authorTim Vieira <tim.f.vieira@gmail.com>
Fri, 28 Jun 2013 01:09:23 +0000 (21:09 -0400)
committerTim Vieira <tim.f.vieira@gmail.com>
Fri, 28 Jun 2013 01:09:23 +0000 (21:09 -0400)
Nicer error messages when post/load commands are not understood.

examples/trace.dyna [deleted file]
src/Dyna/Backend/Python/interpreter.py
src/Dyna/Backend/Python/load/__init__.py
src/Dyna/Backend/Python/post/__init__.py
src/Dyna/Backend/Python/post/trace.py
test/repl/load.bash

diff --git a/examples/trace.dyna b/examples/trace.dyna
deleted file mode 100644 (file)
index e935f60..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-
-% trace of a matrix named "a"
-trace("A") += matrix("A", X, X).
index 1a0fb535d8b6a3234a09ec1e4fbb785046aa74bb..f3998b59ee6d3c026b2f78ebe139b81a8fd7c7f2 100644 (file)
@@ -281,6 +281,9 @@ class Interpreter(object):
         self.rules = ddict(Rule)
         self.error = {}
 
+        # not essential, available in parser_state
+        self.backchained = set()
+
     def __getstate__(self):
         return ((self.chart,
                  self.agenda,
@@ -324,6 +327,7 @@ class Interpreter(object):
         print >> out, '========'
         fns = self.chart.keys()
         fns.sort()
+        fns = [x for x in fns if x not in self.backchained]  # don't show backchained items
         nullary = [x for x in fns if x.endswith('/0')]
         others = [x for x in fns if not x.endswith('/0')]
         # show nullary charts first
@@ -614,6 +618,9 @@ class Interpreter(object):
 
             # accept the new parser state
             self.parser_state = env.parser_state
+
+            self.backchained = {f + '/' + a for f, a in re.findall(":-backchain '([^']+)'/(\d+).", env.parser_state)}
+
             # process emits
             for e in emits:
                 self.emit(*e, delete=False)
index dea5dffd9203302f299d42d381bfe65b3f800137..79da4baedb7a7a091e7d985eb61a0c403b3714c4 100644 (file)
@@ -6,7 +6,19 @@ from pickled import pickled
 import re as _re
 
 def run(interp, line):
-    [(name, module, args)] = _re.findall('^([a-z][a-zA-Z_0-9]*) = ([a-z][a-zA-Z_0-9]*)\((.*)\)', line)
-    m = getattr(__import__('load'), module)(interp, name)
+    try:
+        [(name, module, args)] = _re.findall('^([a-z][a-zA-Z_0-9]*) = ([a-z][a-zA-Z_0-9]*)\((.*)\)', line)
+    except ValueError:
+        print 'Error: failed to parse post command.'
+        print '    %s' % line
+        print
+        return
+
+    try:
+        m = getattr(__import__('load'), module)(interp, name)
+    except KeyError:
+        print 'did not recognize post-processor %r' % name
+        return
+
     exec 'm.main(%s)' % args
     interp.go()
index 77c90852b1afa867abd20b50bfc2152539f4ee48..1484307022f41735660b43e441d1a0ab5e6d6f61 100644 (file)
@@ -6,6 +6,19 @@ from dump_solution import dump_solution
 from trace import trace
 
 def run(interp, line):
-    [(name, args)] = _re.findall('([a-z][a-zA-Z_0-9]*)\((.*)\)$', line.strip())
-    m = globals()[name](interp)
+
+    try:
+        [(name, args)] = _re.findall('([a-z][a-zA-Z_0-9]*)\((.*)\)$', line.strip())
+    except ValueError:
+        print 'Error: failed to parse post command.'
+        print '    %s' % line
+        print
+        return
+
+    try:
+        m = globals()[name](interp)
+    except KeyError:
+        print 'did not recognize post-processor %r' % name
+        return
+
     eval('m.main(%s)' % args)
index 0fe076bd7ab6bd530675435899e965b92463e5f4..ba54ca2e12fb3301a23edca2c801ff5b748160b6 100644 (file)
@@ -1,6 +1,8 @@
 # -*- coding: utf-8 -*-
 """
 Examine solution as an outline of computation.
+
+TODO: backchained stuff
 """
 
 import re
@@ -8,9 +10,6 @@ from utils import yellow, green, red
 from defn import drepr
 from term import _repr
 import debug, defn
-
-import webbrowser
-from debug import Hypergraph
 from cStringIO import StringIO
 from utils import lexer, subst
 
@@ -20,7 +19,7 @@ from collections import defaultdict
 
 class trace(object):
     """
-    Crude visualization of circuit pertaining to state of the interpreter.
+    Examine solution as an outline of computation.
     """
 
     def __init__(self, interp):
index 293fadea534968d4ce061ad6e050e09c4b7fd781..b6021f41cd8b310be5a4b3cfd2ee86cfda183aea 100755 (executable)
@@ -6,5 +6,5 @@
   --load 'rules_tsv = tsv("test/repl/english.gr")' \
          'token = matrix("test/repl/english.sen", astype=str)' \
          'tree = sexpr("test/repl/english.par")' \
-  --post 'dump_chart()' \
+  --post 'dump_solution()' \
   "$@"