Skip to content

Instantly share code, notes, and snippets.

@t2y
Created November 19, 2020 12:37
Show Gist options
  • Save t2y/e5f8545fbee1bf563796af2e1063119d to your computer and use it in GitHub Desktop.
Save t2y/e5f8545fbee1bf563796af2e1063119d to your computer and use it in GitHub Desktop.
ast.unparse sample for hy ast
(py39) $ python unparse_hy_ast.py
def add(hyx_xXcommaX, y):
return hyx_xXcommaX + y
print(add(3, 5))
(py39) $ python -c "$(python unparse_hy_ast.py)"
8
import ast
from hy.lex import hy_parse
from hy.compiler import hy_compile
hy_source = """
(defn add [x, y]
(+ x, y))
(print (add 3, 5))
"""
def main():
hy_tree = hy_parse(hy_source)
py_ast = hy_compile(hy_tree, '__main__')
print(ast.unparse(py_ast))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment