From 66c71e7e40036e853d05327e3dbb522d16c9b2f1 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 10 Aug 2023 18:46:19 -0400 Subject: [PATCH 1/3] Switch the compiled bin to running a diff just like the automated tests. This is mostly so I can test a variety of org-mode documents without needing to integrate them into the org samples folder. --- src/main.rs | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 59a2cd1a..3ad6b6fe 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(()) +} From 023dd05267d61ffeddf514bf1af46d9b129bbe67 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 10 Aug 2023 18:52:02 -0400 Subject: [PATCH 2/3] Remove outdated notes. --- notes/exit_matcher_loop_notes.txt | 35 ------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 notes/exit_matcher_loop_notes.txt diff --git a/notes/exit_matcher_loop_notes.txt b/notes/exit_matcher_loop_notes.txt deleted file mode 100644 index 5e357ae7..00000000 --- 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 From 77de97703faabd07440ef2747ae9af71e87bcb3e Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 10 Aug 2023 18:51:16 -0400 Subject: [PATCH 3/3] Remove all the old references to "toy language" This is a relic from the early development days in this repo. When I first started this repo, it was a clean-slate playground to test ideas for solving the road blocks I hit with my previous attempt at an org-mode parser. To keep things simple, I originally only had a very basic set of syntax rules that only vaguely looked similar to org-mode. Once I had things figured out, I kept developing in this repo, morphing it into a full org-mode parser. A couple of references to those early days still remained, and this patch should get rid of the last of them. --- Cargo.toml | 3 ++- Makefile | 4 ++-- src/init_tracing.rs | 2 +- toy_language.txt | 3 --- 4 files changed, 5 insertions(+), 7 deletions(-) delete mode 100644 toy_language.txt diff --git a/Cargo.toml b/Cargo.toml index 42f7c840..61735378 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 0728dd86..5e8303c5 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/src/init_tracing.rs b/src/init_tracing.rs index e82b1dfb..2eec9139 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/toy_language.txt b/toy_language.txt deleted file mode 100644 index 189d0e03..00000000 --- a/toy_language.txt +++ /dev/null @@ -1,3 +0,0 @@ -foo bar baz - -lorem ipsum