diff --git a/AUTHORS b/AUTHORS index 2247f9c..d18f375 100644 --- a/AUTHORS +++ b/AUTHORS @@ -11,3 +11,4 @@ * Vladimir Gorbunov * John Jacobsen * rogererens +* Thomas Ballinger diff --git a/docs/language/api.rst b/docs/language/api.rst index 47d99d8..31a32a7 100644 --- a/docs/language/api.rst +++ b/docs/language/api.rst @@ -12,7 +12,7 @@ Theory of Hy ============ Hy maintains, over everything else, 100% compatibility in both directions -with Python it's self. All Hy code follows a few simple rules. Memorize +with Python itself. All Hy code follows a few simple rules. Memorize this, it's going to come in handy. These rules help make sure code is idiomatic and interface-able in both diff --git a/eg/clint/clint-progress.hy b/eg/clint/clint-progress.hy new file mode 100644 index 0000000..4d247f1 --- /dev/null +++ b/eg/clint/clint-progress.hy @@ -0,0 +1,6 @@ +(import [clint.textui [progress]] + [time [sleep]] + [random [random]]) + +(for [x (.bar progress (range 100))] + (sleep (* (random) 0.1))) diff --git a/hy/lex/states.py b/hy/lex/states.py index 51255bd..9c81967 100644 --- a/hy/lex/states.py +++ b/hy/lex/states.py @@ -255,8 +255,9 @@ class String(State): """ if self.escaped: self.escaped = False - if char == "n": - self.nodes.append("\n") + simple_escapables = tuple('abfnrtv') + if char in simple_escapables: + self.nodes.append(eval('"\\'+char+'"')) return if char == "\\": self.nodes.append("\\") diff --git a/hy/macros.py b/hy/macros.py index 5149cc7..d3530fd 100644 --- a/hy/macros.py +++ b/hy/macros.py @@ -57,20 +57,25 @@ def _wrap_value(x): else: return wrapper(x) -_wrappers = {int: HyInteger, - bool: lambda x: HySymbol("True") if x else HySymbol("False"), - float: HyFloat, - complex: HyComplex, - str_type: HyString, - dict: lambda d: HyDict(_wrap_value(x) for x in sum(d.items(), ())), - list: lambda l: HyList(_wrap_value(x) for x in l)} +_wrappers = { + int: HyInteger, + bool: lambda x: HySymbol("True") if x else HySymbol("False"), + float: HyFloat, + complex: HyComplex, + str_type: HyString, + dict: lambda d: HyDict(_wrap_value(x) for x in sum(d.items(), ())), + list: lambda l: HyList(_wrap_value(x) for x in l) +} + def process(tree, module_name): if isinstance(tree, HyExpression): fn = tree[0] if fn in ("quote", "quasiquote"): return tree - ntree = HyExpression([fn] + [process(x, module_name) for x in tree[1:]]) + ntree = HyExpression( + [fn] + [process(x, module_name) for x in tree[1:]] + ) ntree.replace(tree) if isinstance(fn, HyString): diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index cf345f4..07ed7db 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -728,3 +728,7 @@ (assert (= x [3 2 1])) "success") (except [NameError] "failure"))))) + +(defn test-encoding-nightmares [] + "NATIVE: test unicode encoding escaping crazybits" + (assert (= (len "ℵℵℵ♥♥♥\t♥♥\r\n") 11)))