diff --git a/Cargo.toml b/Cargo.toml index 42f7c84..6173537 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,8 @@ name = "organic" path = "src/lib.rs" [[bin]] -name = "toy" +# This bin exists for development purposes only. The real target of this crate is the library. +name = "compare" path = "src/main.rs" [dependencies] diff --git a/Makefile b/Makefile index 0728dd8..5e8303c 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ debug: .PHONY: jaeger jaeger: -> docker run -d --rm --name toylanguagedocker -p 6831:6831/udp -p 6832:6832/udp -p 16686:16686 -p 14268:14268 jaegertracing/all-in-one:latest +> docker run -d --rm --name organicdocker -p 6831:6831/udp -p 6832:6832/udp -p 16686:16686 -p 14268:14268 jaegertracing/all-in-one:latest .PHONY: jaegerweb jaegerweb: @@ -63,4 +63,4 @@ jaegerweb: .PHONY: jaegerstop jaegerstop: -> docker stop toylanguagedocker +> docker stop organicdocker diff --git a/notes/exit_matcher_loop_notes.txt b/notes/exit_matcher_loop_notes.txt deleted file mode 100644 index 5e357ae..0000000 --- a/notes/exit_matcher_loop_notes.txt +++ /dev/null @@ -1,35 +0,0 @@ -Headings add exit matcher for heading - -Paragraphs add exit matcher for elements (but it should be sans paragraph) - - - - -* foo -* bar -* baz - -context tree -> () - -match * foo - -context tree -> exit(heading matcher) - -check exit -invoke heading matcher -check exit -invoke heading matcher -check exit -invoke heading matcher -adds second heading matcher exit - - -Ways around this: -- Always parse SOMETHING before checking for exit - - Doesn't always seem possible -- Disable exit matchers during exit check - - Seems like it would break syntax -- Have separate parsers for the beginning of the exit condition (for example, checking for just the headline instead of the full heading parser) - - Won't be possible with paragraphs ending at any other element -- Check exit matchers in parent parser - - Will this work? seems like it would just create larger loops diff --git a/src/init_tracing.rs b/src/init_tracing.rs index e82b1df..2eec913 100644 --- a/src/init_tracing.rs +++ b/src/init_tracing.rs @@ -14,7 +14,7 @@ pub fn init_telemetry() -> Result<(), Box> { opentelemetry::global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new()); let tracer = opentelemetry_jaeger::new_pipeline() - .with_service_name("toy_language") + .with_service_name("organic") .install_simple()?; let opentelemetry = tracing_opentelemetry::layer().with_tracer(tracer); diff --git a/src/main.rs b/src/main.rs index 59a2cd1..3ad6b6f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,51 @@ #![feature(round_char_boundary)] +use std::path::Path; + use ::organic::parser::document; +use organic::compare_document; +use organic::emacs_parse_org_document; +use organic::parser::sexp::sexp_with_padding; use crate::init_tracing::init_telemetry; use crate::init_tracing::shutdown_telemetry; mod init_tracing; -const TEST_DOC: &'static str = include_str!("../toy_language.txt"); - fn main() -> Result<(), Box> { init_telemetry()?; - let parsed = document(TEST_DOC); - println!("{}\n\n\n", TEST_DOC); - println!("{:#?}", parsed); + run_compare( + std::env::args() + .nth(1) + .expect("Pass a single file into this script."), + )?; shutdown_telemetry()?; Ok(()) } + +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(()) +} diff --git a/toy_language.txt b/toy_language.txt deleted file mode 100644 index 189d0e0..0000000 --- a/toy_language.txt +++ /dev/null @@ -1,3 +0,0 @@ -foo bar baz - -lorem ipsum