2013-03-06 00:16:04 +01:00
|
|
|
#!/usr/bin/env python
|
2013-04-09 21:23:50 +02:00
|
|
|
from __future__ import print_function
|
2014-03-18 09:08:20 +01:00
|
|
|
|
|
|
|
from hy.importer import import_file_to_ast, import_file_to_hst
|
2013-03-06 00:16:04 +01:00
|
|
|
|
2014-01-13 21:41:01 +01:00
|
|
|
import argparse
|
|
|
|
import sys
|
2013-04-10 22:52:28 +02:00
|
|
|
|
2013-04-28 02:52:37 +02:00
|
|
|
import astor.codegen
|
2013-03-06 00:16:04 +01:00
|
|
|
|
2013-05-16 15:34:14 +02:00
|
|
|
module_name = "<STDIN>"
|
2013-03-09 00:18:43 +01:00
|
|
|
|
2014-01-13 21:41:01 +01:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
prog="hy2py",
|
|
|
|
usage="%(prog)s [options] FILE",
|
|
|
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
|
|
parser.add_argument("--with-source", "-s", action="store_true",
|
|
|
|
help="Show the parsed source structure")
|
|
|
|
parser.add_argument("--with-ast", "-a", action="store_true",
|
|
|
|
help="Show the generated AST")
|
|
|
|
parser.add_argument("--without-python", "-np", action="store_true",
|
|
|
|
help="Do not show the python code generated from the AST")
|
|
|
|
parser.add_argument('args', nargs=argparse.REMAINDER, help=argparse.SUPPRESS)
|
|
|
|
|
|
|
|
options = parser.parse_args(sys.argv[1:])
|
|
|
|
|
|
|
|
if options.with_source:
|
|
|
|
hst = import_file_to_hst(options.args[0])
|
2014-03-18 09:08:20 +01:00
|
|
|
print(hst)
|
2014-01-13 21:41:01 +01:00
|
|
|
print()
|
|
|
|
print()
|
|
|
|
|
|
|
|
_ast = import_file_to_ast(options.args[0], module_name)
|
|
|
|
if options.with_ast:
|
2014-03-18 09:08:20 +01:00
|
|
|
print(astor.dump(_ast))
|
2014-01-13 21:41:01 +01:00
|
|
|
print()
|
|
|
|
print()
|
|
|
|
|
|
|
|
if not options.without_python:
|
2014-03-18 09:08:20 +01:00
|
|
|
print(astor.codegen.to_source(_ast))
|