disable REPL run command.. it doesn't pass parser state along.
#!/usr/bin/env python
import re, sys
-sys.path.append('src/Dyna/Backend/Python')
-
from interpreter import Interpreter
from repl import REPL
from cStringIO import StringIO
def extract(code):
for block in re.compile('^> ', re.MULTILINE).split(code):
- for cmd, expect in re.findall('(.*?)\n([\w\W]*)$', block):
- yield cmd, expect
+ cmd = []
+ expect = []
+ for i, line in enumerate(block.split('\n')):
+ if line.startswith('|') or i == 0:
+ if line.startswith('|'):
+ line = line[1:]
+ cmd.append(line)
+ else:
+ expect.append(line)
+
+ yield '\n'.join(cmd).strip(), '\n'.join(expect).strip()
def run(code):
print
continue
print yellow % '> %s' % cmd
+
+ if strip_comments(cmd) == '*resume*':
+ repl.cmdloop()
+ continue
+
sys.stdout = x = StringIO()
try:
repl.onecmd(cmd)
sys.stdout = sys.__stdout__
got = x.getvalue().strip()
expect = expect.strip()
+
+ if strip_comments(expect) == '*ignore*':
+ continue
+
if strip_comments(expect) != strip_comments(got):
print green % expect
print red % got
- errors.append(cmd, expect, got)
+ errors.append([cmd, expect, got])
else:
print x.getvalue().rstrip()
print
if not errors:
print green % 'PASS!'
+ print
else:
print red % '%s errors' % len(errors)
- print
+ print
+ sys.exit(1)
+
if __name__ == '__main__':
for filename in sys.argv[1:]:
return item
for i in new_rules:
r = self.rules[i]
- agg, head, evals, unifs, result = r.anf[2:]
- r.item = rule(i, r.src, todyna([head, agg, result, evals, unifs]), r.init, r.query)
+ if hasattr(r, 'anf'): # XXX: all rules should have ANF!
+ agg, head, evals, unifs, result = r.anf[2:]
+ r.item = rule(i, r.src, todyna([head, agg, result, evals, unifs]), r.init, r.query)
#-----------------------------------------
return self.go()
# f.write(line)
# debug.main(f.name)
- def do_run(self, filename):
- """
- Load dyna rules from `filename`.
-
- > run examples/papa.dyna
-
- """
- try:
- changed = self.interp.do(self.interp.dynac(filename))
- except DynaCompilerError as e:
- print e
- else:
- self._changed(changed)
+# def do_run(self, filename):
+# """
+# Load dyna rules from `filename`.
+#
+# > run examples/papa.dyna
+#
+# """
+# try:
+# changed = self.interp.do(self.interp.dynac(filename))
+# except DynaCompilerError as e:
+# print e
+# else:
+# self._changed(changed)
def _query(self, q):
self._changed(changed)
def _changed(self, changed):
+ if not changed:
+ return
+
+ changed = [x for x in changed if not x.fn.startswith('$rule/')]
+
if not changed:
return
print
print 'Changes'
print '======='
- for x, v in sorted(changed.items()):
- if x.fn.startswith('$rule/'):
- continue
- print '%s = %s.' % (x, _repr(v))
+ for x in sorted(changed):
+ print '%s = %s.' % (x, _repr(x.value))
print
# def _changed_subscriptions(self, changed):