7 releases

0.2.5 Mar 22, 2024
0.2.4 Mar 14, 2023
0.2.1 Feb 28, 2023
0.2.0 Feb 6, 2020
0.1.1 Feb 28, 2020

#429 in Parser implementations

Download history 46/week @ 2023-12-18 29/week @ 2023-12-25 61/week @ 2024-01-01 60/week @ 2024-01-08 44/week @ 2024-01-15 61/week @ 2024-01-22 61/week @ 2024-01-29 48/week @ 2024-02-05 86/week @ 2024-02-12 79/week @ 2024-02-19 98/week @ 2024-02-26 99/week @ 2024-03-04 117/week @ 2024-03-11 426/week @ 2024-03-18 611/week @ 2024-03-25 287/week @ 2024-04-01

1,451 downloads per month
Used in 2 crates

MPL-2.0 license

46KB
936 lines

Pest Formatter

Test Crate

Pest Formatter is a tool to format Pest grammar files.

Installation

cargo install pest_fmt

Usage

Then use the pestfmt command to format your .pest files.

$ pestfmt -h
A formatter tool for pest

Usage: 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

$ pestfmt .

It will find all .pest files in the current directory and format and overwrite them.

Output:

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.

cat file.pest | pestfmt --stdin

Usage as a library

Add pest_fmt into your Cargo.toml:

$ cargo add pest_fmt

Then use the Formatter struct to format pest grammar.

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

Dependencies

~9.5MB
~168K SLoC