A libary for generating (and manipulating) abstract syntax trees (AST) based on ASDL descriptions.
This is in contrast to most parser generators (Antlr, Pest, etc), which almost exclusively generate parse trees.
Parse Tree | AST |
---|---|
As you can see, the AST excludes things . Things like paranthesized are also dropped, so grouping is inferred ()
See this stackoverflow answer for more details.
ASDL is a way to specify the layout of your ASTs automatically.
It is most notably used by CPython, to specify the official python ast.
See this blog post for more details on what ASDL is (and why it's still useful). It is written by the Oil Shell people.
This library provides two things:
- A way to automatically generate an AST from an ASDL descripiton (
astlib-meta
)- Unfrotunately, this currently requires
python
(see issue #1) - Seperate from the main crate (and can be run independently)
- Unfrotunately, this currently requires
astlib
is the runtime, seperate from the codgen. It incldues several utilites to analyse and manipulate ASTs, including:- Printing to lisp-style s-expressions
- Basic traits
The generated ASTs only have two required dependencies:
- The
astlib
crate - The
derivative
crate (for excludingSpan
s from generatedEq
implementations)
The library lalso has a number of optional features, some of which are on by default
lisp
for printing lisp trees (on by default)builtins
to enable a simple builtinConstant
andIdent
- TODO: This is currently a required feature.
codemap
for better (and faster)Spans
(off by default)- The alternative (and default impl) is essentially
Span { start: usize, end: usize}
- The alternative (and default impl) is essentially
serde
support for generated ASTs- By default spans are excluded from the serialized representation
Right now, the actual code generation is based on the scripts that CPython uses.
As such, actually converting ASDL -> AST requires Python.
To be clear, this is only a build dependency and it can be run ahead of time. It is sperated into its own crate astlib-meta
.
The only dependency of the python scripts is click
.
In the future, I plan to move the implementation into Rust (See github issue #1).
Ideally we can be self-hosting :)