Compare commits
1 Commits
master
...
017_inline
Author | SHA1 | Date | |
---|---|---|---|
abead3d94b |
@ -21,6 +21,7 @@ from hy.macros import require, load_macros, macroexpand, tag_macroexpand
|
|||||||
import hy.core
|
import hy.core
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import textwrap
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import traceback
|
import traceback
|
||||||
import importlib
|
import importlib
|
||||||
@ -1669,6 +1670,22 @@ class HyASTCompiler(object):
|
|||||||
if ast_str(root) == "eval_and_compile"
|
if ast_str(root) == "eval_and_compile"
|
||||||
else Result())
|
else Result())
|
||||||
|
|
||||||
|
@special(["py", "pys"], [STR])
|
||||||
|
def compile_inline_python(self, expr, root, code):
|
||||||
|
exec_mode = root == HySymbol("pys")
|
||||||
|
|
||||||
|
try:
|
||||||
|
o = ast.parse(
|
||||||
|
textwrap.dedent(code) if exec_mode else code,
|
||||||
|
self.filename,
|
||||||
|
'exec' if exec_mode else 'eval').body
|
||||||
|
except (SyntaxError, ValueError if PY36 else TypeError) as e:
|
||||||
|
raise self._syntax_error(
|
||||||
|
expr,
|
||||||
|
"Python parse error in '{}': {}".format(root, e))
|
||||||
|
|
||||||
|
return Result(stmts=o) if exec_mode else o
|
||||||
|
|
||||||
@builds_model(HyExpression)
|
@builds_model(HyExpression)
|
||||||
def compile_expression(self, expr):
|
def compile_expression(self, expr):
|
||||||
# Perform macro expansions
|
# Perform macro expansions
|
||||||
|
Loading…
Reference in New Issue
Block a user