feat(examples): add grammar generation and pretty-printing utilities

Add new examples for generating sample .improv data based on the Pest
grammar and pretty-printing existing .improv files.

Co-Authored-By: fiddlerwoaroof/git-smart-commit (gemma-4-31B-it-UD-Q4_K_XL.gguf)
This commit is contained in:
Edward Langley
2026-04-13 21:30:19 -07:00
parent c48a5cd575
commit ed1ee7e23a
2 changed files with 340 additions and 0 deletions

25
examples/pretty-print.rs Normal file
View File

@ -0,0 +1,25 @@
//! Parse a `.improv` file from stdin and print the formatted result to stdout.
//!
//! Usage:
//! cargo run --example pretty-print < file.improv
//! cargo run --example gen-grammar -- file | cargo run --example pretty-print
use std::io::Read;
fn main() {
let mut input = String::new();
if let Err(e) = std::io::stdin().read_to_string(&mut input) {
eprintln!("Failed to read stdin: {e}");
std::process::exit(1);
}
match improvise::persistence::parse_md(&input) {
Ok(model) => {
print!("{}", improvise::persistence::format_md(&model));
}
Err(e) => {
eprintln!("Parse error: {e:#}");
std::process::exit(1);
}
}
}