Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pest-parser/pest-fmt
https://github.com/pest-parser/pest-fmt
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/pest-parser/pest-fmt
- Owner: pest-parser
- License: mpl-2.0
- Created: 2019-08-08T12:08:49.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-08T01:22:57.000Z (7 months ago)
- Last Synced: 2024-05-01T14:49:22.357Z (6 months ago)
- Language: Rust
- Size: 117 KB
- Stars: 22
- Watchers: 8
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-pest - pest-fmt - It can help to format (Tooling / IDE Support)
README
# Pest Formatter
[![Test](https://github.com/pest-parser/pest-fmt/actions/workflows/test.yml/badge.svg)](https://github.com/pest-parser/pest-fmt/actions/workflows/test.yml) [![Crate](https://img.shields.io/crates/v/pest_fmt?color=1t&label=Crate)](https://crates.io/crates/pest_fmt)
Pest Formatter is a tool to format [Pest](https://pest.rs) grammar files.
## Installation
```bash
cargo install pest_fmt
```## Usage
Then use the `pestfmt` command to format your `.pest` files.
```bash
$ pestfmt -h
A formatter tool for pestUsage: pestfmt [OPTIONS] [FILE]...
Arguments:
[FILE]... The file or path to format [default: .]Options:
-s, --stdin
-h, --help Print help
-V, --version Print version
```### Format pest files
```bash
$ pestfmt .
```It will find all `.pest` files in the current directory and format and overwrite them.
Output:
```bash
Pest Formatter
-------------------------------------
2 files formatted.
```### Format from stdin
You can use `--stdin` option to format Pest source code from stdin, it will read from stdin and write to stdout.
```bash
cat file.pest | pestfmt --stdin
```### Usage as a library
Add `pest_fmt` into your `Cargo.toml`:
```bash
$ cargo add pest_fmt
```Then use the `Formatter` struct to format pest grammar.
```rs
use pest_fmt::Formatter;let mut fmt = Formatter::new("a={ASCII_DIGIT}");
let out = fmt.format().unwrap();
println!("{out}");
// a = { ASCII_DIGIT }
```## Development Tool Integration
### VS Code
https://github.com/pest-parser/pest-ide-tools
## Benchmark
Based on MacBook Pro (Apple M1 2020)
```
format (json.pest) time: [89.403 µs 89.632 µs 89.878 µs]
format (grammar.pest) time: [1.6018 ms 1.6054 ms 1.6105 ms]
```## License
Mozilla Public License 2.0