Created
November 19, 2020 12:37
-
-
Save t2y/e5f8545fbee1bf563796af2e1063119d to your computer and use it in GitHub Desktop.
ast.unparse sample for hy ast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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