Fixes #135.
# python 3.0 differences
if sys.hexversion > 0x3000000:
- def u(x):
- return x
+ _u = lambda x: x
+ _s2u = lambda x: x
else:
import codecs
- def u(x):
- return codecs.unicode_escape_decode(x)[0]
-
+ _u = lambda x: codecs.unicode_escape_decode(x)[0]
+ _s2u = lambda x: unicode(x)
if sys.version_info[0] >= 3:
str_types = [str]
# Keywords
# A specially prefixed string
def _keyword(str):
- if str[0] == u("\u029e"): return str
- else: return u("\u029e") + str
+ if str[0] == _u("\u029e"): return str
+ else: return _u("\u029e") + str
def _keyword_Q(exp):
- return _string_Q(exp) and exp[0] == u("\u029e")
+ return _string_Q(exp) and exp[0] == _u("\u029e")
# Functions
def _function(Eval, Env, ast, env, params):
ret.extend((_pr_str(k), _pr_str(obj[k],_r)))
return "{" + " ".join(ret) + "}"
elif types._string_Q(obj):
- if len(obj) > 0 and obj[0] == types.u('\u029e'):
+ if len(obj) > 0 and obj[0] == types._u('\u029e'):
return ':' + obj[1:]
elif print_readably:
return '"' + _escape(obj) + '"'
import re
-from mal_types import (_symbol, _keyword, _list, _vector, _hash_map)
+from mal_types import (_symbol, _keyword, _list, _vector, _hash_map, _s2u)
class Blank(Exception): pass
if re.match(int_re, token): return int(token)
elif re.match(float_re, token): return int(token)
elif token[0] == '"':
- if token[-1] == '"': return _unescape(token[1:-1])
+ if token[-1] == '"': return _s2u(_unescape(token[1:-1]))
else: raise Exception("expected '\"', got EOF")
elif token[0] == ':': return _keyword(token[1:])
elif token == "nil": return None