]> hydra-www.ietfng.org Git - dyna2/commitdiff
Misc.
authorTim Vieira <tim.f.vieira@gmail.com>
Fri, 2 Aug 2013 14:00:16 +0000 (10:00 -0400)
committerTim Vieira <tim.f.vieira@gmail.com>
Fri, 2 Aug 2013 14:00:16 +0000 (10:00 -0400)
 - Use IPython's external dependency on path.py in order to avoid the extra dep.

 - Added command to REPL for pasting mulitline rules. Related to issue #22.

14 files changed:
src/Dyna/Backend/Python/chart.py
src/Dyna/Backend/Python/config.py
src/Dyna/Backend/Python/debug.py
src/Dyna/Backend/Python/interpreter.py
src/Dyna/Backend/Python/load/matrix.py
src/Dyna/Backend/Python/load/pickled.py
src/Dyna/Backend/Python/load/sexpr.py
src/Dyna/Backend/Python/load/tsv.py
src/Dyna/Backend/Python/main.py
src/Dyna/Backend/Python/post/trace.py
src/Dyna/Backend/Python/repl.py
src/Dyna/Backend/Python/stdlib.py
src/Dyna/Backend/Python/term.py
src/Dyna/Backend/Python/utils.py

index 84cc669f165593dd2c691c14392af950e7f90341..1c09ea193e44612693d9eafb1831329e8d671d4a 100644 (file)
@@ -19,7 +19,7 @@ class Chart(object):
     def set_aggregator(self, agg):
         self.agg_name = agg
         for item in self.intern.values():
-            assert item.value is None           # shouldn't aggregator when non-null.
+            assert item.value is None   # shouldn't change aggregator when non-null.
             item.aggregator = self.new_aggregator(item)
 
     def __repr__(self):
index 7b67212bc6c8c42357f76768ab647c439a8c8810..4695c0a954d6288fcc987720cfaf378053131d97 100644 (file)
@@ -1,5 +1,5 @@
 import os
-from path import path
+from IPython.external.path import path
 
 dotdynadir = path('~/.dyna').expand()
 if not dotdynadir.exists():
index 715509aabdba17185eb3eea68656bb2d03cb6bef..8075c0c9325dde80d05e9ffcb1041466aaecab22 100644 (file)
@@ -8,7 +8,7 @@ import re, os, shutil, webbrowser
 from collections import defaultdict
 from utils import dynac, read_anf
 from config import dynahome
-from path import path
+from IPython.external.path import path
 from warnings import warn
 
 try:
index 4eef6dc9e886b9d7128b26a18066eeb210ba760e..4f2fdda82d8220f388c09ca4b47a7273636fdc92 100644 (file)
@@ -3,7 +3,7 @@
 import re, os, sys, imp, traceback
 from collections import defaultdict
 from hashlib import sha1
-from path import path
+from IPython.external.path import path
 
 from term import Term, Cons, Nil, MapsTo, Error
 from chart import Chart
index 4162804d24da14b4dd1593a8eba7bf513bdf1a99..4b28443919c3f280867db9e84fd308683804e5fd 100644 (file)
@@ -1,5 +1,6 @@
 import re
-from path import path
+from IPython.external.path import path
+
 
 class matrix(object):
     """
index 7104922966c63e8cc93397dafcb78128e4fdf634..d7f8f28eeb8ffcfd3c029e495906d9f4f7c8594c 100644 (file)
@@ -7,7 +7,8 @@ TODO: Can we merge a pickled interpreter into an existing one?
 """
 
 import cPickle
-from path import path
+from IPython.external.path import path
+
 
 class pickled(object):
 
index 5379db2e4dae31b65492450010f0bc1ee14c0ff1..f701ffab61052902d870f5fbe1f3efe7e478e1a1 100644 (file)
@@ -1,7 +1,8 @@
 from cStringIO import StringIO
 from utils import parse_sexpr
 from stdlib import todyna
-from path import path
+from IPython.external.path import path
+
 
 class sexpr(object):
     """
index 13b59ecffc98bab4a068975ba3380b1c010a3eaa..761385a603fa64747d45320ad72e194acd2028a2 100644 (file)
@@ -5,7 +5,8 @@ TODO: option for strict number of columns.
 
 import re
 from utils import true
-from path import path
+from IPython.external.path import path
+
 
 class tsv(object):
     """
index 31bcbb55eadb4dffa751594405e313d58935bb2d..e2949db744f8b087909093850ba56c4ef9fc5b70 100644 (file)
@@ -1,5 +1,5 @@
 import argparse
-from path import path
+from IPython.external.path import path
 from errors import DynaCompilerError
 from errors import crash_handler
 from interpreter import Interpreter
index 9444553a206003d3ad125236119954c740dcc5e9..cfeeaa68508c24ce3cb3d38da7e05ad5792296f9 100644 (file)
@@ -1,11 +1,10 @@
 # -*- coding: utf-8 -*-
 
 import re
-from collections import defaultdict
 
 import debug
 from draw_circuit import infer_edges
-from utils import yellow, green, cyan, red, _repr
+from utils import yellow, green, cyan, red, _repr, groupby
 
 
 class trace(object):
@@ -49,13 +48,6 @@ class Tracer(object):
                             depth_limit = depth_limit))
 
 
-def groupby(key, data):
-    g = defaultdict(list)
-    for x in data:
-        g[key(x)].append(x)
-    return dict(g)
-
-
 def dig(head, visited, tail, groups, interp, depth_limit=-1):
 
     if depth_limit >= 0 and len(tail) >= depth_limit:
index 37ceac8130fd42b2a6dcbac516da2e0c2360c499..54a42c2e09bf4b3960fbe693a042a9fc88228759 100644 (file)
@@ -575,6 +575,21 @@ class REPL(cmd.Cmd, object):
             # query must have failed.
             pass
 
-
     do_load.__doc__ = do_load.__doc__.format(load=', '.join(load.available))
     do_post.__doc__ = do_post.__doc__.format(post=', '.join(post.available))
+
+    def do_paste(self, _):
+        """
+        Add a new rule to program by pasting from clipboard. The advantage of
+        using this paste` command is that newlines within will not break a rule
+        definition.
+
+        TODO: support execution of other commands, e.g. 'load' or 'sol'.
+        """
+        from IPython.core.hooks import clipboard_get
+        x = clipboard_get(None)
+        print x
+        if raw_input('%s ok? [Y/n] ' % yellow % '>>>') == 'n':  # control-c works too
+            pass
+        else:
+            self.default(x)
index 94f39165f890f01619fd6bd804c86a788c7e21ae..d74ee3835c4cec04d1e4d7dc05ea78b3577587cd 100644 (file)
@@ -1,4 +1,4 @@
-import re
+import re, os
 from term import Term, Cons, Nil, MapsTo
 from collections import Counter
 from utils import pretty, pretty_print, true, false, null, isbool
index 84f46abbc3b70854a9e05fffdaf55ad251620e42..404a0cee19c315078a3d1155f57f127d347a772f 100644 (file)
@@ -20,7 +20,10 @@ class Term(object):
         if self is other:
             return 0
         try:
-            return cmp((self.fn, self.args), (other.fn, other.args))
+            if self.fn == other.fn:
+                return cmp(self.args, other.args)
+            else:
+                return cmp(self.fn, other.fn)
         except AttributeError:
             return 1
 
index 1559f5676011c01c3f01ab10311e706474820b21..47fa5a58430829c6a4adad1cce1a1804ca092957 100644 (file)
@@ -1,12 +1,19 @@
 import re
 from IPython.frontend.terminal.embed import InteractiveShellEmbed
-from path import path
+from IPython.external.path import path
 from subprocess import Popen, PIPE
 from config import dynahome, dotdynadir
-from collections import namedtuple
+from collections import namedtuple, defaultdict
 from cStringIO import StringIO
 
 
+def groupby(key, data):
+    g = defaultdict(list)
+    for x in data:
+        g[key(x)].append(x)
+    return dict(g)
+
+
 # TODO: This is pretty hacking we should have the codegen produce something
 # easier to serialize/modify/unserialize. XREF:parser-state
 def parse_parser_state(parser_state):
@@ -103,11 +110,15 @@ def get_module(cmd, sub):
         return m
 
 
-black, red, green, yellow, blue, magenta, cyan, white = \
-    map('\033[3%sm%%s\033[0m'.__mod__, range(8))
+red, green, yellow, blue, magenta, cyan, white = \
+    map('\033[3%sm%%s\033[0m'.__mod__, range(1,8))
 bold = '\033[1m%s\033[0m'
 
 
+# TODO: use fabulous colors
+#from fabulous.color import red, green, yellow, blue, magenta, cyan, white, bold, underline
+
+
 _comments = re.compile('%.*$', re.MULTILINE)
 def strip_comments(src):
     return _comments.sub('', src).strip()
@@ -139,7 +150,7 @@ def dynac(f, out, anf=None, compiler_args=()):
     stdout, stderr = p.communicate()
     if p.returncode:
         assert not stdout.strip(), [stdout, stderr]
-        stderr = hide_ugly_filename(stderr, lambda m: '\n  %s\n' % rule_source(m.group(0)))
+        stderr = hide_ugly_filename(stderr, lambda m: '\n  %s\n' % span_to_src(m.group(0)))
         raise DynaCompilerError(stderr, f)
 
 
@@ -297,13 +308,14 @@ def read_anf(e):
 def parse_attrs(fn):
     attrs = dict(re.findall('\s*(\S+):\s*(.*)\s*\n', fn.__doc__.strip()))
     if 'Span' in attrs:
-        attrs['rule'] = rule_source(attrs['Span']).strip()
+        attrs['rule'] = span_to_src(attrs['Span']).strip()
     return attrs
 
 
-def rule_source(span, src=None):
+def span_to_src(span, src=None):
     """
-    Utility for retrieving source code for Parsec error message.
+    Utility for retrieving source code for Parsec error message (there is
+    nothing specific about rules)
     """
     try:
         [(filename, bl, bc, el, ec)] = re.findall(r'(.*):(\d+):(\d+)-\1:(\d+):(\d+)', span)