1. Carl Friedrich Bolz
  2. Pyrolog

Commits

Rene Bartelmus  committed 3349d6f

view-friendly output, added format_query(...), Fixed bug in TraceFailureContinuation

  • Participants
  • Parent commits cd52250
  • Branches tracing-support

Comments (0)

Files changed (1)

File prolog/interpreter/continuation.py

View file
  • Ignore whitespace
     if port == "Fail":
         write("%s: (%d) %s ?" % (port, depth, query))
         return
+    if dereference:
+        query = query.getvalue(None)
+    tm = port, depth, format_query(engine, query)
+    write("%s: (%d) %s ?" % tm)
+    return tm[2]
+
+def format_query(engine, query):
     from prolog.builtin import formatting
     f = formatting.TermFormatter(engine, quoted=True, max_depth=20)
-    if dereference:
-        query = query.getvalue(None)
-    tm = port, depth, f.format(query)
-    write("%s: (%d) %s ?" % tm)
-    return tm[2]
+    return f.format(query)
 
 def get_goal_string(engine, query, depth):
     from prolog.builtin import formatting
         if query is None and port is not None:
             query = self.innercont.query
         self.query = query
-        self.raw_query = ""
+        self.raw_query = format_query(self.engine, self.query)
 
     def is_done(self):
         return False
     # XXX optimize
     def activate(self, fcont, heap):
         if not self.port in ["Call", "Exit", "Exception", None]:
-            raise NotImplementedError("Port '"+str(self.port)+"' is not supported")
+            raise NotImplementedError("Port "+repr(self.port)+" is not supported")
 
         skip = self.engine.tracewrapper.skip(self.depth, self.port)
 
             res = "creep"
             if not skip:
                 # remember call query for fail
-                self.raw_query = print_trace_step(self.engine, self.port, self.query, write, self.depth)
+                self.raw_query = print_trace_step(
+                        self.engine, self.port, self.query, write, self.depth)
                 if self.engine.tracewrapper.is_leashed(self.port.lower()):
                     res = get_decision(write, getch)
                 else:
 
     # __________Helper methods
 
+    # XXX crop processed TraceFailureContinuations
     def make_next_fcont(self, fcont):
         """ Prepend an element to fcont-chain for fail output, if innercont fails. """
         nextc = self.innercont
         return self
 
     def __repr__(self):
-        return "<TraceSuccessContinuation %s depth=%d innercont=%s>" % (
-                self.port, self.depth, self.innercont)
+        return "<TraceSuccessContinuation '%s: (%d) %s ?' innercont=%s>" % (
+                self.port, self.depth, self.raw_query, self.innercont)
 
     _dot = _dot
 
     def fail(self, heap):
         """ Innerfcont contains the query for -Fail- and -Redo- output.
         Nextcont is the failure continuation."""
-        if not self.port in ["Fail", "Redo", None]:
-            raise NotImplementedError("Port '"+str(self.port)+"' is not supported")
+        if not self.port in ["Fail", "Redo"]:
+            raise NotImplementedError("Port "+repr(self.port)+" is not supported")
 
         skip = self.engine.tracewrapper.skip(self.depth, self.port)
 
         return self.innerfcont.trace_unwrap()
 
     def __repr__(self):
-        return "<TraceFailureContinuation %s depth=%d innerfcont=%s>" % (self.port, self.depth, self.innerfcont)
+        return "<TraceFailureContinuation '%s: (%d) %s ?' innerfcont=%s>" % (
+                self.port, self.depth, format_query(self.engine, self.query), self.innerfcont)
 
     _dot = _dot