#![feature(round_char_boundary)] use std::path::Path; #[cfg(feature = "compare")] use ::organic::parser::document; #[cfg(feature = "compare")] use organic::compare_document; #[cfg(feature = "compare")] use organic::emacs_parse_org_document; #[cfg(feature = "compare")] use organic::parser::sexp::sexp_with_padding; use crate::init_tracing::init_telemetry; use crate::init_tracing::shutdown_telemetry; mod init_tracing; #[cfg(not(feature = "tracing"))] fn main() -> Result<(), Box> { main_body() } #[cfg(feature = "tracing")] fn main() -> Result<(), Box> { let rt = tokio::runtime::Runtime::new()?; let result = rt.block_on(async { main_body() }); result } fn main_body() -> Result<(), Box> { init_telemetry()?; let compare_result = run_compare( std::env::args() .nth(1) .expect("Pass a single file into this script."), ); shutdown_telemetry()?; compare_result?; Ok(()) } #[cfg(feature = "compare")] fn run_compare>(todo_org_path: P) -> Result<(), Box> { let org_contents = std::fs::read_to_string(todo_org_path.as_ref()).expect("Read org file."); let (remaining, rust_parsed) = document(org_contents.as_str()).expect("Org Parse failure"); let org_sexp = emacs_parse_org_document(todo_org_path.as_ref()).expect("Use emacs to parse org file."); let (_remaining, parsed_sexp) = sexp_with_padding(org_sexp.as_str()).expect("Sexp Parse failure"); println!("{}\n\n\n", org_contents.as_str()); println!("{}", org_sexp); println!("{:#?}", rust_parsed); // We do the diffing after printing out both parsed forms in case the diffing panics let diff_result = compare_document(&parsed_sexp, &rust_parsed).expect("Compare parsed documents."); diff_result .print() .expect("Print document parse tree diff."); if diff_result.is_bad() { Err("Diff results do not match.")?; } if remaining != "" { Err(format!("There was unparsed text remaining: {}", remaining))?; } Ok(()) } #[cfg(not(feature = "compare"))] fn run_compare>(_todo_org_path: P) -> Result<(), Box> { println!("This program was built with compare disabled. Doing nothing."); Ok(()) }