Skip to main content

human-oriented ast parser/unparser

Project description

package version from PyPI build status from Travis CI build status from AppVeyor grade from Codacy test coverage from Codecov license

Attempt at a human-oriented abstract syntax tree (AST) parser/unparser for Python 3.

This package provides new AST node types which inherit from nodes in typed_ast.ast3 module. Additionally, it provides implementation of parser and unparser for the extended ASTs.

Simple example of how to use this package:

from horast import parse, unparse

tree = parse("""a = 1  # a equals one after this""")
print(unparse(tree))
# this will print the code with original comment

More examples in examples.ipynb.

technical details

Parser is based on built-in tokenize module, as well as community packages asttokens and typed_ast.

Unparser is essentially an extension of Unparser class from static_typing package.

Nodes provided and handled by horast are listed below.

Comment

Full line as well as end-of-line comments are parsed/unparsed correctly when they are outside of multi-line expressions.

Currently, handling of comments within multi-line expressions is implemented only partially.

Docstring

To do.

Directive

This node will not appear in AST when Python code is parsed, and if inserted into AST manually, it will be rendered as comment.

This node is not meant to enable preprocessing of Python, at least for now.

Currently, this node is meant to work towards AST compatibility between Python and other langauges, to aide code generation from Python AST into code in other langauges (as seen in *transpyle* project).

requirements

CPython 3.5 or later.

Python libraries as specified in requirements.txt.

Building and running tests additionally requires packages listed in test_requirements.txt.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

horast-0.3.1.tar.gz (23.9 kB view hashes)

Uploaded Source

Built Distribution

horast-0.3.1-py3-none-any.whl (16.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page