diff --git a/Cargo.toml b/Cargo.toml index 76745b7f..bc11dfc0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,6 @@ path = "src/main.rs" [dependencies] nom = "7.1.1" tracing = "0.1.37" -tracing-subscriber = "0.3.16" +tracing-subscriber = {version="0.3.16", features=["env-filter"]} [features] diff --git a/Makefile b/Makefile index aa2b8a36..6e63e0c3 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,10 @@ test: run: > cargo run +.PHONY: debug +debug: +> RUST_LOG=debug cargo run + .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 diff --git a/src/main.rs b/src/main.rs index 6906a5b5..2d4a3dcb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,26 +1,32 @@ #![feature(round_char_boundary)] use crate::parser::document; -use tracing::Level; use tracing_subscriber::fmt::format::FmtSpan; - +use tracing_subscriber::EnvFilter; mod parser; 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); + Ok(()) +} + +fn init_telemetry() -> Result<(), Box> { + let env_filter = EnvFilter::try_from_default_env().unwrap_or(EnvFilter::new("WARN")); let format = tracing_subscriber::fmt::format() + .pretty() .with_file(true) .with_line_number(true) .with_thread_ids(false) .with_target(false); let subscriber = tracing_subscriber::fmt() .event_format(format) - .with_max_level(Level::TRACE) .with_span_events(FmtSpan::ENTER | FmtSpan::EXIT) + .with_env_filter(env_filter) .finish(); tracing::subscriber::set_global_default(subscriber)?; - let parsed = document(TEST_DOC); - println!("{}\n\n\n", TEST_DOC); - println!("{:#?}", parsed); Ok(()) } diff --git a/src/parser/document.rs b/src/parser/document.rs index 160f5074..133ddb7b 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -74,6 +74,7 @@ impl<'s> Source<'s> for DocumentElement<'s> { } } +#[tracing::instrument(ret, level = "debug")] #[allow(dead_code)] pub fn document(input: &str) -> Res<&str, Document> { let initial_context: ContextTree<'_, '_> = ContextTree::new(); @@ -82,7 +83,8 @@ pub fn document(input: &str) -> Res<&str, Document> { let section_matcher = parser_with_context!(section)(&document_context); let heading_matcher = parser_with_context!(heading)(&document_context); let (remaining, zeroth_section) = opt(section_matcher)(input)?; - let (remaining, children) = many0(heading_matcher)(remaining)?; + // let (remaining, children) = many0(heading_matcher)(remaining)?; + let children = Vec::new(); let source = get_consumed(input, remaining); Ok(( remaining, @@ -94,6 +96,7 @@ pub fn document(input: &str) -> Res<&str, Document> { )) } +#[tracing::instrument(ret, level = "debug")] fn section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Section<'s>> { // TODO: The zeroth section is specialized so it probably needs its own parser let parser_context = context @@ -112,11 +115,13 @@ fn section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Sec Ok((remaining, Section { source, children })) } +#[tracing::instrument(ret, level = "debug")] fn section_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> { let headline_matcher = parser_with_context!(headline)(context); alt((recognize(headline_matcher), eof))(input) } +#[tracing::instrument(ret, level = "debug")] fn heading<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Heading<'s>> { not(|i| context.check_exit_matcher(i))(input)?; let (remaining, (star_count, _ws, title, _ws2)) = headline(context, input)?; @@ -141,6 +146,7 @@ fn heading<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Hea )) } +#[tracing::instrument(ret, level = "debug")] fn headline<'r, 's>( context: Context<'r, 's>, input: &'s str, @@ -162,6 +168,7 @@ fn headline<'r, 's>( Ok((remaining, (star_count, ws, title, ws2))) } +#[tracing::instrument(ret, level = "debug")] fn headline_end<'r, 's>(_context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> { alt((line_ending, eof))(input) } diff --git a/src/parser/util.rs b/src/parser/util.rs index b8a0e216..c4f57e5a 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -108,6 +108,7 @@ pub fn non_whitespace_character(input: &str) -> Res<&str, char> { } /// Check that we are at the start of a line +#[tracing::instrument(ret, level = "debug")] pub fn exit_matcher_parser<'r, 's>( context: Context<'r, 's>, input: &'s str, diff --git a/toy_language.txt b/toy_language.txt index fd2a6a59..de546e94 100644 --- a/toy_language.txt +++ b/toy_language.txt @@ -1,26 +1,4 @@ -prologue *goes here* I guess *bold -text* - -bold*wont* start *or stop*when there is text outside it - -I guess *regular - -text* - -[foo *bar] baz* car - - -*nesting *bold entrances* and* exits - -* Heading - -body of heading - -** Child heading -** Immediate second child heading - * Second top-level heading - foo bar 1. This is a list immediately after a paragraph 2. This is a second item in the list