Commit graph

10 commits

Author SHA1 Message Date
Luke Petre
6434ca8512
Remove tox references (#588) 2022-01-06 21:09:27 -05:00
Steven Troxler
601db54880
Add instructions to codegen test failures (#582)
* Add instructions to codegen test failures

* Run ufmt

* Fix lint errors, mention tox -e codegen
2022-01-05 12:24:31 -08:00
Zsolt Dollenstein
c44ff0500b
Fix license headers (#560)
* Facebook -> Meta

* remove year from doc copyright
2021-12-28 11:55:18 +00:00
Zsolt Dollenstein
c02de9b718
Implement a Python PEG parser in Rust (#566)
This massive PR implements an alternative Python parser that will allow LibCST to parse Python 3.10's new grammar features. The parser is implemented in Rust, but it's turned off by default through the `LIBCST_PARSER_TYPE` environment variable. Set it to `native` to enable. The PR also enables new CI steps that test just the Rust parser, as well as steps that produce binary wheels for a variety of CPython versions and platforms.

Note: this PR aims to be roughly feature-equivalent to the main branch, so it doesn't include new 3.10 syntax features. That will be addressed as a follow-up PR.

The new parser is implemented in the `native/` directory, and is organized into two rust crates: `libcst_derive` contains some macros to facilitate various features of CST nodes, and `libcst` contains the `parser` itself (including the Python grammar), a `tokenizer` implementation by @bgw, and a very basic representation of CST `nodes`. Parsing is done by
1. **tokenizing** the input utf-8 string (bytes are not supported at the Rust layer, they are converted to utf-8 strings by the python wrapper)
2. running the **PEG parser** on the tokenized input, which also captures certain anchor tokens in the resulting syntax tree
3. using the anchor tokens to **inflate** the syntax tree into a proper CST

Co-authored-by: Benjamin Woodruff <github@benjam.info>
2021-12-21 18:14:39 +00:00
jimmylai
c023fa7c4c
[typing] enable Pyre strict mode by default (#313)
Co-authored-by: Jimmy Lai <jimmylai@fb.com>
2020-06-12 18:24:18 -07:00
Jennifer Taylor
704fe2bc3a Codegen valid return types mapping for each CSTNode class. 2019-10-16 12:48:20 -07:00
Jennifer Taylor
ba471909c4 Generalize codegen cleanup step and apply it to all codegen.
I noticed that the typed visitors codegen was creating messy types such as Union[SingleType]. We have a clean-up for Union[SingleType] snuck into gen_matcher_classes. So, lets remove that snuck-in clean-up from gen_matcher_classes and apply it globally to all codegen. This makes its purpose a lot more obvious, while helping decouple necessary codegen from prettifying/simplifying transforms. It also cleans up typed visitors, so that's a bonus.
2019-10-11 12:29:23 -07:00
Jennifer Taylor
85417b957d Initial export of matchers into LibCST. 2019-09-27 11:39:11 -07:00
Jennifer Taylor
90e39ca4fa Add a tox environment for running codegen. 2019-08-28 13:28:29 -07:00
Jennifer Taylor
f9437f42b4 Add unit test to verify that codegen is clean.
We want to make sure that the generated function stubs stay in sync with
the node definitions. So, make a unit test that fails if codegen generates
a different file than the existing file, so that somebody modifying code
knows they need to re-run codegen.
2019-08-28 13:28:29 -07:00