Fixing 3.x AST
This commit is contained in:
parent
b12e14b96b
commit
9f057e8c8f
@ -28,6 +28,7 @@ from hy.models.list import HyList
|
|||||||
from hy.models.dict import HyDict
|
from hy.models.dict import HyDict
|
||||||
|
|
||||||
import ast
|
import ast
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class HyCompileError(HyError):
|
class HyCompileError(HyError):
|
||||||
@ -90,21 +91,30 @@ class HyASTCompiler(object):
|
|||||||
@builds("throw")
|
@builds("throw")
|
||||||
def compile_throw_expression(self, expr):
|
def compile_throw_expression(self, expr):
|
||||||
expr.pop(0)
|
expr.pop(0)
|
||||||
|
exc = self.compile(expr.pop(0))
|
||||||
return ast.Raise(
|
return ast.Raise(
|
||||||
lineno=expr.start_line,
|
lineno=expr.start_line,
|
||||||
col_offset=expr.start_column,
|
col_offset=expr.start_column,
|
||||||
type=self.compile(expr.pop(0)),
|
type=exc,
|
||||||
|
exc=exc,
|
||||||
inst=None,
|
inst=None,
|
||||||
tback=None)
|
tback=None)
|
||||||
|
|
||||||
@builds("try")
|
@builds("try")
|
||||||
def compile_try_expression(self, expr):
|
def compile_try_expression(self, expr):
|
||||||
expr.pop(0) # try
|
expr.pop(0) # try
|
||||||
return ast.TryExcept(
|
|
||||||
|
if sys.version_info[0] >= 3 and sys.version_info[1] >= 3:
|
||||||
|
Try = ast.Try
|
||||||
|
else:
|
||||||
|
Try = ast.TryExcept
|
||||||
|
|
||||||
|
return Try(
|
||||||
lineno=expr.start_line,
|
lineno=expr.start_line,
|
||||||
col_offset=expr.start_column,
|
col_offset=expr.start_column,
|
||||||
body=self._code_branch(self.compile(expr.pop(0))),
|
body=self._code_branch(self.compile(expr.pop(0))),
|
||||||
handlers=[self.compile(s) for s in expr],
|
handlers=[self.compile(s) for s in expr],
|
||||||
|
finalbody=[],
|
||||||
orelse=[])
|
orelse=[])
|
||||||
|
|
||||||
@builds("catch")
|
@builds("catch")
|
||||||
|
@ -119,7 +119,7 @@
|
|||||||
(defn test-exceptions []
|
(defn test-exceptions []
|
||||||
"NATIVE: test Exceptions"
|
"NATIVE: test Exceptions"
|
||||||
(try
|
(try
|
||||||
(throw KeyError)
|
(throw (KeyError))
|
||||||
(catch IOError (assert (= 2 1)))
|
(catch IOError (assert (= 2 1)))
|
||||||
(catch KeyError (do
|
(catch KeyError (do
|
||||||
(+ 1 1)
|
(+ 1 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user