Fix handling of whitespace.
This commit is contained in:
parent
751a3beffd
commit
5d7ca1b966
@ -2,3 +2,4 @@ mod error;
|
|||||||
mod parse;
|
mod parse;
|
||||||
mod sexp;
|
mod sexp;
|
||||||
pub use parse::emacs_parse_org_document;
|
pub use parse::emacs_parse_org_document;
|
||||||
|
pub use sexp::sexp;
|
||||||
|
@ -3,7 +3,10 @@ use nom::bytes::complete::tag;
|
|||||||
use nom::bytes::complete::take_till1;
|
use nom::bytes::complete::take_till1;
|
||||||
use nom::character::complete::multispace0;
|
use nom::character::complete::multispace0;
|
||||||
use nom::character::complete::multispace1;
|
use nom::character::complete::multispace1;
|
||||||
|
use nom::combinator::not;
|
||||||
|
use nom::combinator::peek;
|
||||||
use nom::multi::separated_list1;
|
use nom::multi::separated_list1;
|
||||||
|
use nom::sequence::delimited;
|
||||||
|
|
||||||
use super::error::Res;
|
use super::error::Res;
|
||||||
|
|
||||||
@ -29,13 +32,14 @@ fn token<'s>(input: &'s str) -> Res<&'s str, Token<'s>> {
|
|||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
fn list<'s>(input: &'s str) -> Res<&'s str, Token<'s>> {
|
fn list<'s>(input: &'s str) -> Res<&'s str, Token<'s>> {
|
||||||
let (remaining, opening_paren) = tag("(")(input)?;
|
let (remaining, opening_paren) = tag("(")(input)?;
|
||||||
let (remaining, children) = separated_list1(multispace1, token)(remaining)?;
|
let (remaining, children) = delimited(multispace0, separated_list1(multispace1, token), multispace0)(remaining)?;
|
||||||
let (remaining, closing_paren) = tag(")")(remaining)?;
|
let (remaining, closing_paren) = tag(")")(remaining)?;
|
||||||
Ok((remaining, Token::List(children)))
|
Ok((remaining, Token::List(children)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
fn atom<'s>(input: &'s str) -> Res<&'s str, Token<'s>> {
|
fn atom<'s>(input: &'s str) -> Res<&'s str, Token<'s>> {
|
||||||
|
not(peek(tag(")")))(input)?;
|
||||||
unquoted_atom(input)
|
unquoted_atom(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
34
src/init_tracing.rs
Normal file
34
src/init_tracing.rs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
|
pub fn init_telemetry() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let env_filter = EnvFilter::try_from_default_env().unwrap_or(EnvFilter::new("WARN"));
|
||||||
|
|
||||||
|
// let stdout = tracing_subscriber::fmt::Layer::new()
|
||||||
|
// .pretty()
|
||||||
|
// .with_file(true)
|
||||||
|
// .with_line_number(true)
|
||||||
|
// .with_thread_ids(false)
|
||||||
|
// .with_target(false);
|
||||||
|
|
||||||
|
opentelemetry::global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
|
||||||
|
let tracer = opentelemetry_jaeger::new_pipeline()
|
||||||
|
.with_service_name("toy_language")
|
||||||
|
.install_simple()?;
|
||||||
|
|
||||||
|
let opentelemetry = tracing_opentelemetry::layer().with_tracer(tracer);
|
||||||
|
|
||||||
|
tracing_subscriber::registry()
|
||||||
|
.with(env_filter)
|
||||||
|
.with(opentelemetry)
|
||||||
|
// .with(stdout)
|
||||||
|
.try_init()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn shutdown_telemetry() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
opentelemetry::global::shutdown_tracer_provider();
|
||||||
|
Ok(())
|
||||||
|
}
|
33
src/main.rs
33
src/main.rs
@ -1,9 +1,9 @@
|
|||||||
#![feature(round_char_boundary)]
|
#![feature(round_char_boundary)]
|
||||||
|
use crate::init_tracing::init_telemetry;
|
||||||
|
use crate::init_tracing::shutdown_telemetry;
|
||||||
use crate::parser::document;
|
use crate::parser::document;
|
||||||
use tracing_subscriber::EnvFilter;
|
mod init_tracing;
|
||||||
mod parser;
|
mod parser;
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
|
||||||
use tracing_subscriber::util::SubscriberInitExt;
|
|
||||||
|
|
||||||
const TEST_DOC: &'static str = include_str!("../toy_language.txt");
|
const TEST_DOC: &'static str = include_str!("../toy_language.txt");
|
||||||
|
|
||||||
@ -12,31 +12,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let parsed = document(TEST_DOC);
|
let parsed = document(TEST_DOC);
|
||||||
println!("{}\n\n\n", TEST_DOC);
|
println!("{}\n\n\n", TEST_DOC);
|
||||||
println!("{:#?}", parsed);
|
println!("{:#?}", parsed);
|
||||||
opentelemetry::global::shutdown_tracer_provider();
|
shutdown_telemetry()?;
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn init_telemetry() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let env_filter = EnvFilter::try_from_default_env().unwrap_or(EnvFilter::new("WARN"));
|
|
||||||
|
|
||||||
// let stdout = tracing_subscriber::fmt::Layer::new()
|
|
||||||
// .pretty()
|
|
||||||
// .with_file(true)
|
|
||||||
// .with_line_number(true)
|
|
||||||
// .with_thread_ids(false)
|
|
||||||
// .with_target(false);
|
|
||||||
|
|
||||||
opentelemetry::global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
|
|
||||||
let tracer = opentelemetry_jaeger::new_pipeline()
|
|
||||||
.with_service_name("toy_language")
|
|
||||||
.install_simple()?;
|
|
||||||
|
|
||||||
let opentelemetry = tracing_opentelemetry::layer().with_tracer(tracer);
|
|
||||||
|
|
||||||
tracing_subscriber::registry()
|
|
||||||
.with(env_filter)
|
|
||||||
.with(opentelemetry)
|
|
||||||
// .with(stdout)
|
|
||||||
.try_init()?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
#![feature(round_char_boundary)]
|
#![feature(round_char_boundary)]
|
||||||
#![feature(exit_status_error)]
|
#![feature(exit_status_error)]
|
||||||
|
use crate::init_tracing::init_telemetry;
|
||||||
|
use crate::init_tracing::shutdown_telemetry;
|
||||||
use compare::emacs_parse_org_document;
|
use compare::emacs_parse_org_document;
|
||||||
|
use compare::sexp;
|
||||||
mod compare;
|
mod compare;
|
||||||
|
mod init_tracing;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
emacs_parse_org_document("./org_mode_samples/footnote_definition/simple.org")?;
|
init_telemetry()?;
|
||||||
|
// emacs_parse_org_document("./org_mode_samples/footnote_definition/simple.org")?;
|
||||||
|
sexp(" (foo bar baz ) ")?;
|
||||||
|
shutdown_telemetry()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user