Merge branch 'jd/remove-pass' of git://github.com/jd/hy into pr-122
This commit is contained in:
commit
3b3768853a
@ -145,14 +145,17 @@ class HyASTCompiler(object):
|
|||||||
"Unknown type - `%s' - %s" % (str(type(tree)), tree))
|
"Unknown type - `%s' - %s" % (str(type(tree)), tree))
|
||||||
|
|
||||||
def _mangle_branch(self, tree, start_line, start_column):
|
def _mangle_branch(self, tree, start_line, start_column):
|
||||||
|
tree = list(flatten_literal_list(tree))
|
||||||
|
tree = list(filter(bool, tree)) # Remove empty statements
|
||||||
|
|
||||||
# If tree is empty, just return a pass statement
|
# If tree is empty, just return a pass statement
|
||||||
if tree == []:
|
if tree == []:
|
||||||
return [ast.Pass(lineno=start_line, col_offset=start_column)]
|
return [ast.Pass(lineno=start_line, col_offset=start_column)]
|
||||||
|
|
||||||
ret = []
|
|
||||||
tree = list(flatten_literal_list(tree))
|
|
||||||
tree.reverse()
|
tree.reverse()
|
||||||
|
|
||||||
|
ret = []
|
||||||
|
|
||||||
if self.returnable and len(tree) > 0:
|
if self.returnable and len(tree) > 0:
|
||||||
el = tree[0]
|
el = tree[0]
|
||||||
if not isinstance(el, ast.stmt):
|
if not isinstance(el, ast.stmt):
|
||||||
@ -447,11 +450,6 @@ class HyASTCompiler(object):
|
|||||||
kw_defaults=[]),
|
kw_defaults=[]),
|
||||||
body=self.compile(body))
|
body=self.compile(body))
|
||||||
|
|
||||||
@builds("pass")
|
|
||||||
@checkargs(0)
|
|
||||||
def compile_pass_expression(self, expr):
|
|
||||||
return ast.Pass(lineno=expr.start_line, col_offset=expr.start_column)
|
|
||||||
|
|
||||||
@builds("yield")
|
@builds("yield")
|
||||||
@checkargs(max=1)
|
@checkargs(max=1)
|
||||||
def compile_yield_expression(self, expr):
|
def compile_yield_expression(self, expr):
|
||||||
|
@ -192,17 +192,6 @@ def test_ast_bad_lambda():
|
|||||||
cant_compile("(lambda [])")
|
cant_compile("(lambda [])")
|
||||||
|
|
||||||
|
|
||||||
def test_ast_good_pass():
|
|
||||||
"Make sure AST can compile valid pass"
|
|
||||||
hy_compile(tokenize("(pass)"))
|
|
||||||
|
|
||||||
|
|
||||||
def test_ast_bad_pass():
|
|
||||||
"Make sure AST can't compile invalid pass"
|
|
||||||
cant_compile("(pass 1)")
|
|
||||||
cant_compile("(pass 1 2)")
|
|
||||||
|
|
||||||
|
|
||||||
def test_ast_good_yield():
|
def test_ast_good_yield():
|
||||||
"Make sure AST can compile valid yield"
|
"Make sure AST can compile valid yield"
|
||||||
hy_compile(tokenize("(yield 1)"))
|
hy_compile(tokenize("(yield 1)"))
|
||||||
|
@ -172,11 +172,11 @@
|
|||||||
|
|
||||||
(try (do))
|
(try (do))
|
||||||
|
|
||||||
(try (pass))
|
(try (do))
|
||||||
|
|
||||||
(try (pass) (except))
|
(try (do) (except))
|
||||||
|
|
||||||
(try (pass) (except [IOError]) (except))
|
(try (do) (except [IOError]) (except))
|
||||||
|
|
||||||
;; Test correct (raise)
|
;; Test correct (raise)
|
||||||
(let [[passed false]]
|
(let [[passed false]]
|
||||||
@ -208,16 +208,15 @@
|
|||||||
(except [[IOError]] (assert false))
|
(except [[IOError]] (assert false))
|
||||||
(catch [e [KeyError]] (assert e)))
|
(catch [e [KeyError]] (assert e)))
|
||||||
|
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(get [1] 3)
|
(get [1] 3)
|
||||||
(catch [IndexError] (assert true))
|
(catch [IndexError] (assert true))
|
||||||
(except [IndexError] (pass)))
|
(except [IndexError] (do)))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(print foobar42ofthebaz)
|
(print foobar42ofthebaz)
|
||||||
(catch [IndexError] (assert false))
|
(catch [IndexError] (assert false))
|
||||||
(except [NameError] (pass)))
|
(except [NameError] (do)))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(get [1] 3)
|
(get [1] 3)
|
||||||
@ -233,11 +232,11 @@
|
|||||||
|
|
||||||
(try
|
(try
|
||||||
(print foobar42)
|
(print foobar42)
|
||||||
(catch [[IndexError NameError]] (pass)))
|
(catch [[IndexError NameError]] (do)))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(get [1] 3)
|
(get [1] 3)
|
||||||
(catch [[IndexError NameError]] (pass)))
|
(catch [[IndexError NameError]] (do)))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(print foobar42ofthebaz)
|
(print foobar42ofthebaz)
|
||||||
@ -249,7 +248,7 @@
|
|||||||
|
|
||||||
(try
|
(try
|
||||||
(print foobar42ofthebaz)
|
(print foobar42ofthebaz)
|
||||||
(except [] (pass)))
|
(except [] (do)))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(print foobar42ofthebaz)
|
(print foobar42ofthebaz)
|
||||||
@ -259,7 +258,7 @@
|
|||||||
|
|
||||||
(let [[passed false]]
|
(let [[passed false]]
|
||||||
(try
|
(try
|
||||||
(try (pass) (except) (else (bla)))
|
(try (do) (except) (else (bla)))
|
||||||
(except [NameError] (setv passed true)))
|
(except [NameError] (setv passed true)))
|
||||||
(assert passed))
|
(assert passed))
|
||||||
|
|
||||||
@ -324,7 +323,7 @@
|
|||||||
|
|
||||||
(defn test-pass []
|
(defn test-pass []
|
||||||
"NATIVE: Test pass worksish"
|
"NATIVE: Test pass worksish"
|
||||||
(if true (pass) (pass))
|
(if true (do) (do))
|
||||||
(assert (= 1 1)))
|
(assert (= 1 1)))
|
||||||
|
|
||||||
|
|
||||||
@ -362,7 +361,7 @@
|
|||||||
(defn test-context []
|
(defn test-context []
|
||||||
"NATIVE: test with"
|
"NATIVE: test with"
|
||||||
(with [fd (open "README.md" "r")] (assert fd))
|
(with [fd (open "README.md" "r")] (assert fd))
|
||||||
(with [(open "README.md" "r")] (pass)))
|
(with [(open "README.md" "r")] (do)))
|
||||||
|
|
||||||
|
|
||||||
(defn test-for-doodle []
|
(defn test-for-doodle []
|
||||||
@ -521,8 +520,8 @@
|
|||||||
2)
|
2)
|
||||||
1)))
|
1)))
|
||||||
(assert (= 1 (let [[x 1] [y 2]]
|
(assert (= 1 (let [[x 1] [y 2]]
|
||||||
(pass)
|
(do)
|
||||||
(pass)
|
(do)
|
||||||
((fn [] 1))))))
|
((fn [] 1))))))
|
||||||
|
|
||||||
(defn test-keyword []
|
(defn test-keyword []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user