Instrument the code.

This commit is contained in:
Tom Alexander 2023-03-27 15:08:29 -04:00
parent 5db4e07c99
commit a77d2655bd
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
6 changed files with 26 additions and 30 deletions

View File

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

View File

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

View File

@ -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<dyn std::error::Error>> {
init_telemetry()?;
let parsed = document(TEST_DOC);
println!("{}\n\n\n", TEST_DOC);
println!("{:#?}", parsed);
Ok(())
}
fn init_telemetry() -> Result<(), Box<dyn std::error::Error>> {
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(())
}

View File

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

View File

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

View File

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