ebnsf 0.1.2

A CLI to generate railroad (syntax) diagrams from EBNF specs
Documentation
use clap::Parser;
use ebnsf::parse_ebnf;

use std::path::PathBuf;

#[derive(clap::Parser)]
struct Cli {
    /// File to read EBNF spec from
    input: String,

    /// Where to save the rendered SVG
    #[arg(short, long)]
    output: Option<String>,
}

fn main() {
    let cli = Cli::parse();

    let ebnf = std::fs::read_to_string(&cli.input).unwrap();

    let diagram = parse_ebnf(&ebnf).unwrap();

    let output = if let Some(path) = cli.output {
        PathBuf::from(path)
    } else {
        let mut path = PathBuf::from(cli.input);
        path.set_extension("svg");
        path
    };

    std::fs::write(&output, diagram.to_string().into_bytes()).unwrap();
}