package pyre-ast

  1. Overview
  2. Docs
Full-fidelity Python parser in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

pyre-ast-0.1.8.tbz
sha256=b5a77edb62222661f3b1209ffc194ddfe7c6c5b7dc082a2495f6f4dbf8f62db4
sha512=813faed918d12fa01f556da57eb2307d29634dbe810241669d20031c3aba9f8cc70c3f35504d60032b8e76c20629bbe7cf3dcc668e41a3567c9a8f1cffe42b83

Description

pyre-ast is an OCaml library to parse Python source files into abstract syntax trees. Under the hood, it relies on the CPython parser to do the parsing work and therefore the result is always 100% compatible with the official CPython implementation.

Published: 22 Dec 2021

README

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.12.0
$ opam install . --deps-only --with-test
$ dune build @install  # Build the library
$ dune test            # Run tests

Dependencies (7)

  1. ppx_make >= "0.2.1"
  2. ppx_deriving >= "5.2.1"
  3. ppx_hash >= "v0.14.0"
  4. ppx_compare >= "v0.14.0"
  5. ppx_sexp_conv >= "v0.14.0"
  6. base >= "v0.14.1"
  7. dune >= "2.8"

Dev Dependencies (4)

  1. odoc with-doc
  2. cmdliner with-test & >= "1.0.0"
  3. sexplib with-test & >= "v0.14.0"
  4. stdio with-test & >= "v0.14.0"

Used by (1)

  1. opine

Conflicts

None

OCaml

Innovation. Community. Security.