use quote::quote;
use std::io::{self, Read};
use thag_common::{auto_help, help_system::check_help_and_exit};
fn read_stdin() -> Result<String, io::Error> {
let mut buffer = String::new();
io::stdin().lock().read_to_string(&mut buffer)?;
Ok(buffer)
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let help = auto_help!();
check_help_and_exit(&help);
let content = read_stdin().expect("Problem reading input");
eprintln!("[{content:#?}]");
match syn::parse_str::<syn::File>(&content) {
Ok(file) => {
println!("{file:#?}");
eprintln!("[{}]", quote!(#file));
}
Err(_) => match syn::parse_str::<syn::Expr>(&format!("{{ {content} }}")) {
Ok(expr) => {
println!("{expr:#?}");
eprintln!("[{}]", quote!(#expr));
}
Err(err) => return Err(err.into()),
},
}
Ok(())
}