From a455800bc703bec7f90eaf9032d3dfba7b981e12 Mon Sep 17 00:00:00 2001 From: Morten Linderud Date: Mon, 24 Jun 2013 02:39:46 +0200 Subject: [PATCH 1/2] added break and continue --- hy/compiler.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hy/compiler.py b/hy/compiler.py index 2e63ec2..2ced07c 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -959,6 +959,20 @@ class HyASTCompiler(object): return ret + @builds("break") + def compile_break_expression(self, expr): + ret = ast.Break(lineno=e.start_line, + col_offset=e.start_column) + + return ret + + @builds("continue") + def compile_continue_expression(self, expr): + ret = ast.Continue(lineno=e.start_line, + col_offset=e.start_column) + + return ret + @builds("assert") @checkargs(1) def compile_assert_expression(self, expr): From 73c1f218e2a69d8780c6680ea1432a084f4fb043 Mon Sep 17 00:00:00 2001 From: Morten Linderud Date: Mon, 24 Jun 2013 03:26:40 +0200 Subject: [PATCH 2/2] fixed a bug and added tests --- hy/compiler.py | 8 ++++---- tests/native_tests/language.hy | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/hy/compiler.py b/hy/compiler.py index 2ced07c..4aa8365 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -961,15 +961,15 @@ class HyASTCompiler(object): @builds("break") def compile_break_expression(self, expr): - ret = ast.Break(lineno=e.start_line, - col_offset=e.start_column) + ret = ast.Break(lineno=expr.start_line, + col_offset=expr.start_column) return ret @builds("continue") def compile_continue_expression(self, expr): - ret = ast.Continue(lineno=e.start_line, - col_offset=e.start_column) + ret = ast.Continue(lineno=expr.start_line, + col_offset=expr.start_column) return ret diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index 41de1dc..534ae40 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -685,6 +685,7 @@ 42 43)))) + (defn test-try-except-return [] "NATIVE: test we can return from in a try except" (assert (= ((fn [] (try xxx (except [NameError] (+ 1 1))))) 2)) @@ -729,6 +730,7 @@ "success") (except [NameError] "failure"))))) + (defn test-encoding-nightmares [] "NATIVE: test unicode encoding escaping crazybits" (assert (= (len "ℵℵℵ♥♥♥\t♥♥\r\n") 11))) @@ -737,3 +739,19 @@ (defn test-keyword-dict-access [] "NATIVE: test keyword dict access" (assert (= "test" (:foo {:foo "test"})))) + + +(defn test-break-breaking [] + "NATIVE: test checking if break actually breaks" + (defn holy-grail [] (for [x (range 10)] (if (= x 5) (break))) x) + (assert (= (holy-grail) 5))) + + +(defn test-continue-continuation [] + "NATIVE: test checking if continue actually continues" + (setv y []) + (for [x (range 10)] + (if (!= x 5) + (continue)) + (.append y x)) + (assert (= y [5])))