Nicer error messages when post/load commands are not understood.
+++ /dev/null
-
-% trace of a matrix named "a"
-trace("A") += matrix("A", X, X).
self.rules = ddict(Rule)
self.error = {}
+ # not essential, available in parser_state
+ self.backchained = set()
+
def __getstate__(self):
return ((self.chart,
self.agenda,
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
# 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)
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()
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)
# -*- coding: utf-8 -*-
"""
Examine solution as an outline of computation.
+
+TODO: backchained stuff
"""
import re
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
class trace(object):
"""
- Crude visualization of circuit pertaining to state of the interpreter.
+ Examine solution as an outline of computation.
"""
def __init__(self, interp):
--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()' \
"$@"