//! 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);
        }
    }
}
