- 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.
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):
import os
-from path import path
+from IPython.external.path import path
dotdynadir = path('~/.dyna').expand()
if not dotdynadir.exists():
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:
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
import re
-from path import path
+from IPython.external.path import path
+
class matrix(object):
"""
"""
import cPickle
-from path import path
+from IPython.external.path import path
+
class pickled(object):
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):
"""
import re
from utils import true
-from path import path
+from IPython.external.path import path
+
class tsv(object):
"""
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
# -*- 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):
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:
# 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)
-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
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
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):
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()
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)
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)