mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Add basic docs for the parser crate (#11199)
## Summary This PR adds a basic README for the `ruff_python_parser` crate and updates the CONTRIBUTING docs with the fuzzer and benchmark section. Additionally, it also updates some inline documentation within the parser crate and splits the `parse_program` function into `parse_single_expression` and `parse_module` which will be called by matching against the `Mode`. This PR doesn't go into too much internal detail around the parser logic due to the following reasons: 1. Where should the docs go? Should it be as a module docs in `lib.rs` or in README? 2. The parser is still evolving and could include a lot of refactors with the future work (feedback loop and improved error recovery and resilience) --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
0ed7af35ec
commit
04a922866a
7 changed files with 199 additions and 67 deletions
|
@ -52,3 +52,49 @@ Then, run the Parser test suite with the following command:
|
|||
```sh
|
||||
cargo test --package ruff_python_parser
|
||||
```
|
||||
|
||||
### Python-based fuzzer
|
||||
|
||||
The Ruff project includes a Python-based fuzzer that can be used to run the parser on
|
||||
randomly generated (but syntactically valid) Python source code files.
|
||||
|
||||
To run the fuzzer, first install the required dependencies:
|
||||
|
||||
```sh
|
||||
uv pip install -r scripts/fuzz-parser/requirements.txt
|
||||
```
|
||||
|
||||
Then, run the fuzzer with the following command:
|
||||
|
||||
```sh
|
||||
python scripts/fuzz-parser/fuzz.py
|
||||
```
|
||||
|
||||
Refer to the [fuzz.py](https://github.com/astral-sh/ruff/blob/main/scripts/fuzz-parser/fuzz.py)
|
||||
script for more information or use the `--help` flag to see the available options.
|
||||
|
||||
#### CI
|
||||
|
||||
The fuzzer is run as part of the CI pipeline. The purpose of running the fuzzer in the CI is to
|
||||
catch any regresssions introduced by any new changes to the parser. This is why the fuzzer is run on
|
||||
the same set of seeds on every run.
|
||||
|
||||
## Benchmarks
|
||||
|
||||
The `ruff_benchmark` crate can benchmark both the lexer and the parser.
|
||||
|
||||
To run the lexer benchmarks, use the following command:
|
||||
|
||||
```sh
|
||||
cargo bench --package ruff_benchmark --bench lexer
|
||||
```
|
||||
|
||||
And to run the parser benchmarks, use the following command:
|
||||
|
||||
```sh
|
||||
cargo bench --package ruff_benchmark --bench parser
|
||||
```
|
||||
|
||||
Refer to the [Benchmarking and
|
||||
Profiling](https://docs.astral.sh/ruff/contributing/#benchmark-driven-development) section in the
|
||||
contributing guide for more information.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue