Skip to content

pyre-ast is an OCaml library to parse Python files. The library features its full-fidelity to the official Python spec, as well as its adoption of tagless-final style.

License

Notifications You must be signed in to change notification settings

grievejia/pyre-ast

Repository files navigation

pyre-ast

pyre-ast is an OCaml library to parse Python files.

The library features its full-fidelity to the official Python spec. Apart from a few technical edge cases, as long as a given file can be parsed by the CPython interpreter, pyre-ast will be able to parse the file without any problem. Furthermore, abstract syntax trees obtained from pyre-ast is guaranteed to 100% match the results obtained by Python's own ast.parse API, down to every AST node and every line and column number.

Another notable feature of this library is that it represents the Python syntax using the tagless-final style. This style typically offers more flexibility and extensibility for the downstream consumers of the syntax, and allow them to build up their analysis without explicitly constructing a syntax tree. On the other hand, this library does offer a tranditional "concrete" syntax tree structure as well, for developers who are less familiar with the tagless-final approach and more familiar with standard algebraic data type representation.

Installation

It is recommended to use opam for package management. To install pyre-ast with opam, you can run:

opam install pyre-ast

Usage

It is recommended to use dune as your build system. To use pyre-ast in your dune project, you can add pyre-ast to the libraries stanza in your dune file. For example,

(library
  (name mylib)
  (libraries pyre-ast))

Documentation of this library can be found here.

Development

It is recommended to use a local switch for development:

$ git clone https://github.com/grievejia/pyre-ast.git
$ cd pyre-ast
$ opam switch create ./ 4.14.0 --deps-only --with-test
$ dune build @install  # Build the library
$ dune test            # Run tests

About

pyre-ast is an OCaml library to parse Python files. The library features its full-fidelity to the official Python spec, as well as its adoption of tagless-final style.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published