Legend:
Library
Module
Module type
Parameter
Class
Class type
This module contains all parsing APIs, i.e. functions that transfrom plain strings into syntactical constructs. These APIs will always hand back a Result.t where if the parsing fails, a Parser.Error.t gets returned.
Under the hood, this library actually compiles and calls into the actual CPython parser code (with PyCF_TYPE_COMMENTS flag enabled), and then it walk through the CPython AST and translate them into OCaml structures via C bindings. This is how 100% fidelity with the official CPython implementation is achieved -- we are actually relying on exactly the same parser implementation that CPython uses. This approach has some notable implications:
The parsing APIs are stateful as one need to intialize/finalize CPython runtime before invoking its parser. The low-level details are abstracted away with the
Parser.Context module, but the fact that no parsing can be done prior to obtaining a
Parser.Context.t still holds.
As of the latest release, I have yet to find an easy way for the parser to handle Unicode identifier names. Unicode characters in string literals are fine, but Unicode identifier name is something that a barely-initialized CPython runtime cannot handle even with utf-8 mode enabled.
This module contains a type that represents parsing errors.
val with_context : ?on_init_failure:(unit ->'a)->(Context.t->'a)->'a
with_context ?on_init_failure f first creates a value c of type Context.t and then invoke f on c. It is guaranteed that the created context c will be destroyed in the end regardless of whether f raises an exception or not.
If the creation of c fails, on_init_failure () will be invoked, and f will not be called. By default, if not explicitly overriden then on_init_failure would simply raise a Failure.
This module provides parsing APIs for downstream clients that are written in tagless-final style. See PyreAst.TaglessFinal for more explanation about this style.
This module provides parsing APIs for downstream clients that are written in the traditional "initial" style which expects a concrete ADT representation for abstract syntax trees.