Merge branch 'toy_cleanup'
Some checks are pending
rustfmt Build rustfmt has started
rust-test Build rust-test has started

This commit is contained in:
Tom Alexander 2023-08-10 18:53:08 -04:00
commit 3ee18072c2
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
6 changed files with 44 additions and 47 deletions

View File

@ -15,7 +15,8 @@ name = "organic"
path = "src/lib.rs" path = "src/lib.rs"
[[bin]] [[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" path = "src/main.rs"
[dependencies] [dependencies]

View File

@ -55,7 +55,7 @@ debug:
.PHONY: jaeger .PHONY: jaeger
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 .PHONY: jaegerweb
jaegerweb: jaegerweb:
@ -63,4 +63,4 @@ jaegerweb:
.PHONY: jaegerstop .PHONY: jaegerstop
jaegerstop: jaegerstop:
> docker stop toylanguagedocker > docker stop organicdocker

View File

@ -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

View File

@ -14,7 +14,7 @@ pub fn init_telemetry() -> Result<(), Box<dyn std::error::Error>> {
opentelemetry::global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new()); opentelemetry::global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
let tracer = opentelemetry_jaeger::new_pipeline() let tracer = opentelemetry_jaeger::new_pipeline()
.with_service_name("toy_language") .with_service_name("organic")
.install_simple()?; .install_simple()?;
let opentelemetry = tracing_opentelemetry::layer().with_tracer(tracer); let opentelemetry = tracing_opentelemetry::layer().with_tracer(tracer);

View File

@ -1,17 +1,51 @@
#![feature(round_char_boundary)] #![feature(round_char_boundary)]
use std::path::Path;
use ::organic::parser::document; 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::init_telemetry;
use crate::init_tracing::shutdown_telemetry; use crate::init_tracing::shutdown_telemetry;
mod init_tracing; mod init_tracing;
const TEST_DOC: &'static str = include_str!("../toy_language.txt");
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
init_telemetry()?; init_telemetry()?;
let parsed = document(TEST_DOC); run_compare(
println!("{}\n\n\n", TEST_DOC); std::env::args()
println!("{:#?}", parsed); .nth(1)
.expect("Pass a single file into this script."),
)?;
shutdown_telemetry()?; shutdown_telemetry()?;
Ok(()) Ok(())
} }
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(())
}

View File

@ -1,3 +0,0 @@
foo bar baz
lorem ipsum