2023-03-23 23:35:32 +00:00
|
|
|
#![feature(round_char_boundary)]
|
2023-08-10 22:46:19 +00:00
|
|
|
use std::path::Path;
|
|
|
|
|
2023-08-11 00:21:39 +00:00
|
|
|
#[cfg(feature = "compare")]
|
2023-04-23 01:45:18 +00:00
|
|
|
use ::organic::parser::document;
|
2023-08-11 00:21:39 +00:00
|
|
|
#[cfg(feature = "compare")]
|
2023-08-10 22:46:19 +00:00
|
|
|
use organic::compare_document;
|
2023-08-11 00:21:39 +00:00
|
|
|
#[cfg(feature = "compare")]
|
2023-08-10 22:46:19 +00:00
|
|
|
use organic::emacs_parse_org_document;
|
2023-08-11 00:21:39 +00:00
|
|
|
#[cfg(feature = "compare")]
|
2023-08-10 22:46:19 +00:00
|
|
|
use organic::parser::sexp::sexp_with_padding;
|
2023-08-15 03:33:38 +00:00
|
|
|
#[cfg(feature = "tracing")]
|
2023-08-15 02:06:22 +00:00
|
|
|
use tracing::span;
|
2023-04-23 01:45:18 +00:00
|
|
|
|
2023-04-11 19:08:46 +00:00
|
|
|
use crate::init_tracing::init_telemetry;
|
|
|
|
use crate::init_tracing::shutdown_telemetry;
|
|
|
|
mod init_tracing;
|
2022-07-16 03:26:49 +00:00
|
|
|
|
2023-08-11 01:22:06 +00:00
|
|
|
#[cfg(not(feature = "tracing"))]
|
2022-07-16 03:26:49 +00:00
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2023-08-11 01:22:06 +00:00
|
|
|
main_body()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "tracing")]
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
let rt = tokio::runtime::Runtime::new()?;
|
|
|
|
let result = rt.block_on(async { main_body() });
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
2023-03-27 19:08:29 +00:00
|
|
|
init_telemetry()?;
|
2023-08-15 02:06:22 +00:00
|
|
|
let compare_result = {
|
|
|
|
#[cfg(feature = "tracing")]
|
|
|
|
let span = span!(tracing::Level::DEBUG, "run_compare");
|
|
|
|
#[cfg(feature = "tracing")]
|
|
|
|
let _enter = span.enter();
|
|
|
|
|
|
|
|
run_compare(
|
|
|
|
std::env::args()
|
|
|
|
.nth(1)
|
|
|
|
.expect("Pass a single file into this script."),
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
2023-04-11 19:08:46 +00:00
|
|
|
shutdown_telemetry()?;
|
2023-08-14 21:12:01 +00:00
|
|
|
compare_result?;
|
2022-07-16 03:26:49 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2023-08-10 22:46:19 +00:00
|
|
|
|
2023-08-11 00:21:39 +00:00
|
|
|
#[cfg(feature = "compare")]
|
2023-08-10 22:46:19 +00:00
|
|
|
fn run_compare<P: AsRef<Path>>(todo_org_path: P) -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
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(())
|
|
|
|
}
|
2023-08-11 00:21:39 +00:00
|
|
|
|
|
|
|
#[cfg(not(feature = "compare"))]
|
|
|
|
fn run_compare<P: AsRef<Path>>(_todo_org_path: P) -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
println!("This program was built with compare disabled. Doing nothing.");
|
|
|
|
Ok(())
|
|
|
|
}
|