Files
sfera/rust/crates/bsl-parser/src/main.rs
T
2026-05-16 19:03:49 +03:00

34 lines
1020 B
Rust

use std::env;
use std::fs;
use std::io::{self, Read};
use bsl_parser::parse_module;
fn main() {
let args: Vec<String> = env::args().collect();
let source_path = args.get(1).map(String::as_str).unwrap_or("-");
let source = match args.get(1) {
Some(path) => fs::read_to_string(path).unwrap_or_else(|error| {
eprintln!("failed to read {path}: {error}");
std::process::exit(2);
}),
None => {
let mut buffer = String::new();
io::stdin()
.read_to_string(&mut buffer)
.unwrap_or_else(|error| {
eprintln!("failed to read stdin: {error}");
std::process::exit(2);
});
buffer
}
};
let unit = parse_module(source_path, &source);
serde_json::to_writer_pretty(io::stdout(), &unit).unwrap_or_else(|error| {
eprintln!("failed to serialize parse result: {error}");
std::process::exit(2);
});
println!();
}