From 66d10a7a1b31b7e50f23b3ead402aa507d7ac31f Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 2 Sep 2023 18:19:52 -0400 Subject: [PATCH 01/24] Started switching over to a stack-based context tree with global settings. This change should hopefully allow for matchers to have captured borrowed values, it should eliminate the use of heap-allocated reference counting on the context nodes, and it adds in a global settings struct for passing around values that do not change during parsing. --- src/parser/list.rs | 205 ++++++++-------------------------- src/parser/mod.rs | 12 +- src/parser/parser_context.rs | 210 +++++++++++++++++++---------------- 3 files changed, 171 insertions(+), 256 deletions(-) diff --git a/src/parser/list.rs b/src/parser/list.rs index 3266ca0..27bc998 100644 --- a/src/parser/list.rs +++ b/src/parser/list.rs @@ -1,183 +1,66 @@ use std::fmt::Debug; -use std::rc::Rc; - -#[derive(Debug)] -pub struct List { - head: Option>>, -} - -impl Clone for List { - fn clone(&self) -> Self { - List { - head: self.head.clone(), - } - } -} #[derive(Debug, Clone)] -pub struct Node { +pub struct List<'parent, T> { data: T, - parent: Option>>, + parent: Link<'parent, T>, } -impl Node { +type Link<'parent, T> = Option<&'parent List<'parent, T>>; + +impl<'parent, T> List<'parent, T> { + pub fn new(first_item: T) -> Self { + Self { + data: first_item, + parent: None, + } + } + pub fn get_data(&self) -> &T { &self.data } + + pub fn get_parent(&'parent self) -> Link<'parent, T> { + self.parent + } + + pub fn iter(&self) -> Iter<'_, T> { + Iter { next: Some(self) } + } } -impl List { - pub fn new() -> Self { - List { head: None } - } +pub trait ListType<'parent, T> { + fn push(&'parent self, item: T) -> List<'parent, T>; +} - pub fn branch_from(trunk: &Rc>) -> Self { - List { - head: Some(trunk.clone()), - } - } - - pub fn push_front(&self, data: T) -> List { - List { - head: Some(Rc::new(Node { - data: data, - parent: self.head.clone(), - })), - } - } - - pub fn pop_front(&mut self) -> (Option, List) { - match self.head.take() { - None => (None, List::new()), - Some(popped_node) => { - let extracted_node = match Rc::try_unwrap(popped_node) { - Ok(node) => node, - Err(_) => panic!("try_unwrap failed on Rc in pop_front on List."), - }; - ( - Some(extracted_node.data), - List { - head: extracted_node.parent, - }, - ) - } - } - } - - #[allow(dead_code)] - pub fn without_front(&self) -> List { - List { - head: self.head.as_ref().map(|node| node.parent.clone()).flatten(), - } - } - - #[allow(dead_code)] - pub fn get_data(&self) -> Option<&T> { - self.head.as_ref().map(|rc_node| &rc_node.data) - } - - #[allow(dead_code)] - pub fn is_empty(&self) -> bool { - self.head.is_none() - } - - pub fn ptr_eq(&self, other: &List) -> bool { - match (self.head.as_ref(), other.head.as_ref()) { - (None, None) => true, - (None, Some(_)) | (Some(_), None) => false, - (Some(me), Some(them)) => Rc::ptr_eq(me, them), - } - } - - pub fn iter(&self) -> impl Iterator>> { - NodeIter { - position: &self.head, - } - } - - #[allow(dead_code)] - pub fn iter_until<'a>(&'a self, other: &'a List) -> impl Iterator>> { - NodeIterUntil { - position: &self.head, - stop: &other.head, - } - } - - #[allow(dead_code)] - pub fn into_iter_until<'a>(self, other: &'a List) -> impl Iterator + 'a { - NodeIntoIterUntil { - position: self, - stop: &other, +impl<'parent, T> ListType<'parent, T> for List<'parent, T> { + fn push(&'parent self, item: T) -> Self { + Self { + data: item, + parent: Some(self), } } } -pub struct NodeIter<'a, T> { - position: &'a Option>>, +impl<'parent, T> ListType<'parent, T> for Link<'parent, T> { + fn push(&'parent self, item: T) -> List<'parent, T> { + List { + data: item, + parent: *self, + } + } } -impl<'a, T> Iterator for NodeIter<'a, T> { - type Item = &'a Rc>; +pub struct Iter<'a, T> { + next: Link<'a, T>, +} + +impl<'a, T> Iterator for Iter<'a, T> { + type Item = &'a T; fn next(&mut self) -> Option { - let (return_value, next_position) = match &self.position { - None => return None, - Some(rc_node) => { - let next_position = &rc_node.parent; - let return_value = rc_node; - (return_value, next_position) - } - }; - self.position = next_position; - Some(return_value) - } -} - -pub struct NodeIterUntil<'a, T> { - position: &'a Option>>, - stop: &'a Option>>, -} - -impl<'a, T> Iterator for NodeIterUntil<'a, T> { - type Item = &'a Rc>; - - fn next(&mut self) -> Option { - match (self.position, self.stop) { - (_, None) => {} - (None, _) => {} - (Some(this_rc), Some(stop_rc)) => { - if Rc::ptr_eq(this_rc, stop_rc) { - return None; - } - } - }; - let (return_value, next_position) = match &self.position { - None => return None, - Some(rc_node) => { - let next_position = &rc_node.parent; - let return_value = rc_node; - (return_value, next_position) - } - }; - self.position = next_position; - Some(return_value) - } -} - -pub struct NodeIntoIterUntil<'a, T> { - position: List, - stop: &'a List, -} - -impl<'a, T> Iterator for NodeIntoIterUntil<'a, T> { - type Item = T; - - fn next(&mut self) -> Option { - if self.position.ptr_eq(self.stop) { - return None; - } - let (popped_element, new_position) = self.position.pop_front(); - self.position = new_position; - popped_element + let ret = self.next.map(|link| link.get_data()); + self.next = self.next.map(|link| link.get_parent()).flatten(); + ret } } diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 639af9a..abd42ab 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -110,4 +110,14 @@ pub use object::Timestamp; pub use object::Underline; pub use object::Verbatim; pub use source::Source; -type Context<'r, 's> = &'r parser_context::ContextTree<'r, 's>; + +use self::org_source::OrgSource; +use self::parser_context::Context; +use crate::error::Res; + +type RefContext<'r, 's> = &'r Context<'r, 's>; +trait ContextMatcher = + for<'r, 's> Fn(RefContext<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>; +type DynContextMatcher<'c> = dyn ContextMatcher + 'c; +trait Matcher = for<'s> Fn(OrgSource<'s>) -> Res, OrgSource<'s>>; +type DynMatcher<'c> = dyn Matcher + 'c; diff --git a/src/parser/parser_context.rs b/src/parser/parser_context.rs index f4e72d5..670e99d 100644 --- a/src/parser/parser_context.rs +++ b/src/parser/parser_context.rs @@ -1,110 +1,96 @@ -use std::rc::Rc; - -use nom::combinator::eof; -use nom::IResult; - use super::list::List; -use super::list::Node; -use super::org_source::OrgSource; -use super::Context; +use super::DynContextMatcher; use super::Object; -use crate::error::CustomError; -use crate::error::MyError; -use crate::error::Res; use crate::parser::exiting::ExitClass; +use crate::parser::list::ListType; -type Matcher = - dyn for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>; +// type Matcher = +// dyn for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>; -#[derive(Debug, Clone)] -pub struct ContextTree<'r, 's> { - tree: List>, -} +// #[derive(Debug, Clone)] +// pub struct ContextTree<'r, 's> { +// tree: List>, +// } -impl<'r, 's> ContextTree<'r, 's> { - pub fn new() -> Self { - ContextTree { tree: List::new() } - } +// impl<'r, 's> ContextTree<'r, 's> { +// pub fn new() -> Self { +// ContextTree { tree: List::new() } +// } - pub fn branch_from(trunk: &Rc>>) -> Self { - ContextTree { - tree: List::branch_from(trunk), - } - } +// pub fn branch_from(trunk: &Rc>>) -> Self { +// ContextTree { +// tree: List::branch_from(trunk), +// } +// } - #[allow(dead_code)] - pub fn ptr_eq<'x, 'y>(&self, other: &ContextTree<'x, 'y>) -> bool { - self.tree.ptr_eq(&other.tree) - } +// #[allow(dead_code)] +// pub fn ptr_eq<'x, 'y>(&self, other: &ContextTree<'x, 'y>) -> bool { +// self.tree.ptr_eq(&other.tree) +// } - pub fn with_additional_node(&self, data: ContextElement<'r, 's>) -> ContextTree<'r, 's> { - let new_list = self.tree.push_front(data); - ContextTree { tree: new_list } - } +// pub fn with_additional_node(&self, data: ContextElement<'r, 's>) -> ContextTree<'r, 's> { +// let new_list = self.tree.push_front(data); +// ContextTree { tree: new_list } +// } - pub fn iter(&self) -> impl Iterator>>> { - self.tree.iter() - } +// pub fn iter(&self) -> impl Iterator>>> { +// self.tree.iter() +// } - #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] - pub fn check_exit_matcher( - &'r self, - i: OrgSource<'s>, - ) -> IResult, OrgSource<'s>, CustomError>> { - // Special check for EOF. We don't just make this a document-level exit matcher since the IgnoreParent ChainBehavior could cause early exit matchers to not run. - let at_end_of_file = eof(i); - if at_end_of_file.is_ok() { - return at_end_of_file; - } +// #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +// pub fn check_exit_matcher( +// &'r self, +// i: OrgSource<'s>, +// ) -> IResult, OrgSource<'s>, CustomError>> { +// // Special check for EOF. We don't just make this a document-level exit matcher since the IgnoreParent ChainBehavior could cause early exit matchers to not run. +// let at_end_of_file = eof(i); +// if at_end_of_file.is_ok() { +// return at_end_of_file; +// } - // let blocked_context = - // self.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - // exit_matcher: ChainBehavior::IgnoreParent(Some(&always_fail)), - // })); +// let mut current_class_filter = ExitClass::Gamma; +// for current_node in self.iter() { +// let context_element = current_node.get_data(); +// match context_element { +// ContextElement::ExitMatcherNode(exit_matcher) => { +// if exit_matcher.class as u32 <= current_class_filter as u32 { +// current_class_filter = exit_matcher.class; +// let local_context = ContextTree::branch_from(current_node); +// let local_result = (exit_matcher.exit_matcher)(&local_context, i); +// if local_result.is_ok() { +// return local_result; +// } +// } +// } +// _ => {} +// }; +// } +// // TODO: Make this a specific error instead of just a generic MyError +// return Err(nom::Err::Error(CustomError::MyError(MyError( +// "NoExit".into(), +// )))); +// } - let mut current_class_filter = ExitClass::Gamma; - for current_node in self.iter() { - let context_element = current_node.get_data(); - match context_element { - ContextElement::ExitMatcherNode(exit_matcher) => { - if exit_matcher.class as u32 <= current_class_filter as u32 { - current_class_filter = exit_matcher.class; - let local_context = ContextTree::branch_from(current_node); - let local_result = (exit_matcher.exit_matcher)(&local_context, i); - if local_result.is_ok() { - return local_result; - } - } - } - _ => {} - }; - } - // TODO: Make this a specific error instead of just a generic MyError - return Err(nom::Err::Error(CustomError::MyError(MyError( - "NoExit".into(), - )))); - } +// /// Indicates if elements should consume the whitespace after them. +// /// +// /// Defaults to true. +// pub fn should_consume_trailing_whitespace(&self) -> bool { +// self._should_consume_trailing_whitespace().unwrap_or(true) +// } - /// Indicates if elements should consume the whitespace after them. - /// - /// Defaults to true. - pub fn should_consume_trailing_whitespace(&self) -> bool { - self._should_consume_trailing_whitespace().unwrap_or(true) - } - - fn _should_consume_trailing_whitespace(&self) -> Option { - for current_node in self.iter() { - let context_element = current_node.get_data(); - match context_element { - ContextElement::ConsumeTrailingWhitespace(should) => { - return Some(*should); - } - _ => {} - } - } - None - } -} +// fn _should_consume_trailing_whitespace(&self) -> Option { +// for current_node in self.iter() { +// let context_element = current_node.get_data(); +// match context_element { +// ContextElement::ConsumeTrailingWhitespace(should) => { +// return Some(*should); +// } +// _ => {} +// } +// } +// None +// } +// } #[derive(Debug)] pub enum ContextElement<'r, 's> { @@ -126,7 +112,8 @@ pub enum ContextElement<'r, 's> { } pub struct ExitMatcherNode<'r> { - pub exit_matcher: &'r Matcher, + // TODO: Should this be "&'r DynContextMatcher<'c>" ? + pub exit_matcher: &'r DynContextMatcher<'r>, pub class: ExitClass, } @@ -137,3 +124,38 @@ impl<'r> std::fmt::Debug for ExitMatcherNode<'r> { formatter.finish() } } + +pub struct GlobalSettings<'s> { + placeholder: Option<&'s str>, +} + +impl<'s> GlobalSettings<'s> { + pub fn new() -> Self { + GlobalSettings { placeholder: None } + } +} + +pub struct Context<'r, 's> { + global_settings: &'s GlobalSettings<'s>, + tree: List<'r, ContextElement<'r, 's>>, +} + +impl<'r, 's> Context<'r, 's> { + pub fn new( + global_settings: &'s GlobalSettings<'s>, + tree: List<'r, ContextElement<'r, 's>>, + ) -> Self { + Context { + global_settings, + tree, + } + } + + pub fn push(&self, data: ContextElement<'r, 's>) -> Self { + let new_tree = self.tree.push(data); + Self { + global_settings: self.global_settings, + tree: new_tree, + } + } +} From 54825538e4c3112b92e68944ed33e828cceceefd Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 2 Sep 2023 18:21:43 -0400 Subject: [PATCH 02/24] fixup --- src/parser/parser_context.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/parser/parser_context.rs b/src/parser/parser_context.rs index 670e99d..35e3c57 100644 --- a/src/parser/parser_context.rs +++ b/src/parser/parser_context.rs @@ -125,6 +125,7 @@ impl<'r> std::fmt::Debug for ExitMatcherNode<'r> { } } +#[derive(Debug)] pub struct GlobalSettings<'s> { placeholder: Option<&'s str>, } @@ -135,6 +136,7 @@ impl<'s> GlobalSettings<'s> { } } +#[derive(Debug)] pub struct Context<'r, 's> { global_settings: &'s GlobalSettings<'s>, tree: List<'r, ContextElement<'r, 's>>, From 25b8c80d4ee82133892cc0c06171b60eef60857e Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 2 Sep 2023 18:40:01 -0400 Subject: [PATCH 03/24] Add default constructors. --- src/lib.rs | 1 + src/parser/document.rs | 4 ++-- src/parser/parser_context.rs | 42 +++++++++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 513e5c9..70249dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![feature(round_char_boundary)] #![feature(exit_status_error)] +#![feature(trait_alias)] #[cfg(feature = "compare")] mod compare; diff --git a/src/parser/document.rs b/src/parser/document.rs index 760c6dc..1fc0dbd 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -18,6 +18,7 @@ use nom::multi::separated_list1; use nom::sequence::tuple; use super::element::Element; +use super::list::List; use super::object::Object; use super::org_source::convert_error; use super::org_source::OrgSource; @@ -35,7 +36,6 @@ use crate::parser::element_parser::element; use crate::parser::exiting::ExitClass; use crate::parser::object_parser::standard_set_object; use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ContextTree; use crate::parser::parser_context::ExitMatcherNode; use crate::parser::planning::planning; use crate::parser::property_drawer::property_drawer; @@ -102,7 +102,7 @@ impl<'s> Source<'s> for Heading<'s> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[allow(dead_code)] pub fn document(input: &str) -> Res<&str, Document> { - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let initial_context = Context::default(); let wrapped_input = OrgSource::new(input); let (remaining, document) = _document(&initial_context, wrapped_input) .map(|(rem, out)| (Into::<&str>::into(rem), out)) diff --git a/src/parser/parser_context.rs b/src/parser/parser_context.rs index 35e3c57..1dce6e9 100644 --- a/src/parser/parser_context.rs +++ b/src/parser/parser_context.rs @@ -1,6 +1,10 @@ +use nom::combinator::eof; + use super::list::List; +use super::org_source::OrgSource; use super::DynContextMatcher; use super::Object; +use crate::error::Res; use crate::parser::exiting::ExitClass; use crate::parser::list::ListType; @@ -136,6 +140,12 @@ impl<'s> GlobalSettings<'s> { } } +impl<'s> Default for GlobalSettings<'s> { + fn default() -> Self { + GlobalSettings::new() + } +} + #[derive(Debug)] pub struct Context<'r, 's> { global_settings: &'s GlobalSettings<'s>, @@ -147,12 +157,22 @@ impl<'r, 's> Context<'r, 's> { global_settings: &'s GlobalSettings<'s>, tree: List<'r, ContextElement<'r, 's>>, ) -> Self { - Context { + Self { global_settings, tree, } } + pub fn document_context(global_settings: &'s GlobalSettings<'s>) -> Self { + Context::new( + global_settings, + List::new(ContextElement::ExitMatcherNode(ExitMatcherNode { + exit_matcher: &document_end, + class: ExitClass::Document, + })), + ) + } + pub fn push(&self, data: ContextElement<'r, 's>) -> Self { let new_tree = self.tree.push(data); Self { @@ -161,3 +181,23 @@ impl<'r, 's> Context<'r, 's> { } } } + +impl<'r, 's> Default for Context<'r, 's> { + fn default() -> Self { + Context::new( + GlobalSettings::default(), + List::new(ContextElement::ExitMatcherNode(ExitMatcherNode { + exit_matcher: &document_end, + class: ExitClass::Document, + })), + ) + } +} + +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +fn document_end<'r, 's>( + _context: Context<'r, 's>, + input: OrgSource<'s>, +) -> Res, OrgSource<'s>> { + eof(input) +} From b47029fdbb7e84d282f264f05161625768707f1e Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 2 Sep 2023 18:46:45 -0400 Subject: [PATCH 04/24] Starting to separate the context and parsed tokens into their own modules. --- src/{parser => context}/exiting.rs | 0 src/{parser => context}/list.rs | 0 src/context/mod.rs | 11 +++++++++++ src/{parser => context}/parser_context.rs | 0 src/{parser => context}/parser_with_context.rs | 0 src/lib.rs | 2 ++ src/parser/mod.rs | 10 ---------- src/types/mod.rs | 0 8 files changed, 13 insertions(+), 10 deletions(-) rename src/{parser => context}/exiting.rs (100%) rename src/{parser => context}/list.rs (100%) create mode 100644 src/context/mod.rs rename src/{parser => context}/parser_context.rs (100%) rename src/{parser => context}/parser_with_context.rs (100%) create mode 100644 src/types/mod.rs diff --git a/src/parser/exiting.rs b/src/context/exiting.rs similarity index 100% rename from src/parser/exiting.rs rename to src/context/exiting.rs diff --git a/src/parser/list.rs b/src/context/list.rs similarity index 100% rename from src/parser/list.rs rename to src/context/list.rs diff --git a/src/context/mod.rs b/src/context/mod.rs new file mode 100644 index 0000000..3f33a26 --- /dev/null +++ b/src/context/mod.rs @@ -0,0 +1,11 @@ +mod exiting; +mod list; +mod parser_context; +mod parser_with_context; + +type RefContext<'r, 's> = &'r Context<'r, 's>; +trait ContextMatcher = + for<'r, 's> Fn(RefContext<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>; +type DynContextMatcher<'c> = dyn ContextMatcher + 'c; +trait Matcher = for<'s> Fn(OrgSource<'s>) -> Res, OrgSource<'s>>; +type DynMatcher<'c> = dyn Matcher + 'c; diff --git a/src/parser/parser_context.rs b/src/context/parser_context.rs similarity index 100% rename from src/parser/parser_context.rs rename to src/context/parser_context.rs diff --git a/src/parser/parser_with_context.rs b/src/context/parser_with_context.rs similarity index 100% rename from src/parser/parser_with_context.rs rename to src/context/parser_with_context.rs diff --git a/src/lib.rs b/src/lib.rs index 70249dd..4c2021c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,5 +15,7 @@ pub use compare::get_emacs_version; #[cfg(feature = "compare")] pub use compare::get_org_mode_version; +mod context; mod error; pub mod parser; +mod types; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index abd42ab..6844477 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -26,14 +26,11 @@ mod latex_fragment; mod lesser_block; mod lesser_element; mod line_break; -mod list; mod object; mod object_parser; mod org_macro; mod org_source; mod paragraph; -mod parser_context; -mod parser_with_context; mod plain_link; mod plain_list; mod plain_text; @@ -114,10 +111,3 @@ pub use source::Source; use self::org_source::OrgSource; use self::parser_context::Context; use crate::error::Res; - -type RefContext<'r, 's> = &'r Context<'r, 's>; -trait ContextMatcher = - for<'r, 's> Fn(RefContext<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>; -type DynContextMatcher<'c> = dyn ContextMatcher + 'c; -trait Matcher = for<'s> Fn(OrgSource<'s>) -> Res, OrgSource<'s>>; -type DynMatcher<'c> = dyn Matcher + 'c; diff --git a/src/types/mod.rs b/src/types/mod.rs new file mode 100644 index 0000000..e69de29 From eabffe5eccd7ad9194b4bdf7543dbaae8da7e19f Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 2 Sep 2023 19:08:01 -0400 Subject: [PATCH 05/24] Move over the rest of the types. --- src/lib.rs | 2 +- src/parser/angle_link.rs | 5 -- src/parser/citation.rs | 5 -- src/parser/citation_reference.rs | 5 -- src/parser/clock.rs | 2 - src/parser/comment.rs | 3 -- src/parser/diary_sexp.rs | 1 - src/parser/document.rs | 64 ---------------------- src/parser/drawer.rs | 6 --- src/parser/dynamic_block.rs | 6 --- src/parser/element_parser.rs | 3 -- src/parser/entity.rs | 1 - src/parser/export_snippet.rs | 5 -- src/parser/fixed_width_area.rs | 2 - src/parser/footnote_definition.rs | 5 -- src/parser/footnote_reference.rs | 5 -- src/parser/greater_block.rs | 6 --- src/parser/horizontal_rule.rs | 1 - src/parser/inline_babel_call.rs | 5 -- src/parser/inline_source_block.rs | 5 -- src/parser/keyword.rs | 1 - src/parser/latex_environment.rs | 5 -- src/parser/latex_fragment.rs | 2 - src/parser/lesser_block.rs | 5 -- src/parser/line_break.rs | 1 - src/parser/mod.rs | 68 ------------------------ src/parser/object_parser.rs | 1 - src/parser/org_macro.rs | 1 - src/parser/org_source.rs | 2 +- src/parser/paragraph.rs | 4 -- src/parser/plain_link.rs | 4 -- src/parser/plain_list.rs | 5 -- src/parser/plain_text.rs | 3 -- src/parser/property_drawer.rs | 5 -- src/parser/radio_link.rs | 6 --- src/parser/regular_link.rs | 6 --- src/parser/statistics_cookie.rs | 1 - src/parser/subscript_and_superscript.rs | 6 --- src/parser/table.rs | 6 --- src/parser/target.rs | 5 -- src/parser/text_markup.rs | 5 -- src/parser/timestamp.rs | 6 --- src/parser/token.rs | 4 -- src/parser/util.rs | 2 - src/types/document.rs | 56 +++++++++++++++++++ src/{parser => types}/element.rs | 2 - src/{parser => types}/greater_element.rs | 1 - src/{parser => types}/lesser_element.rs | 1 - src/types/mod.rs | 65 ++++++++++++++++++++++ src/{parser => types}/object.rs | 2 - src/{parser => types}/source.rs | 0 51 files changed, 123 insertions(+), 295 deletions(-) create mode 100644 src/types/document.rs rename src/{parser => types}/element.rs (98%) rename src/{parser => types}/greater_element.rs (98%) rename src/{parser => types}/lesser_element.rs (99%) rename src/{parser => types}/object.rs (99%) rename src/{parser => types}/source.rs (100%) diff --git a/src/lib.rs b/src/lib.rs index 4c2021c..c481b7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,4 +18,4 @@ pub use compare::get_org_mode_version; mod context; mod error; pub mod parser; -mod types; +pub mod types; diff --git a/src/parser/angle_link.rs b/src/parser/angle_link.rs index 423e17a..800ba05 100644 --- a/src/parser/angle_link.rs +++ b/src/parser/angle_link.rs @@ -6,12 +6,7 @@ use nom::multi::many_till; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; use crate::error::Res; -use crate::parser::exiting::ExitClass; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::plain_link::protocol; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; diff --git a/src/parser/citation.rs b/src/parser/citation.rs index c06813b..05636b8 100644 --- a/src/parser/citation.rs +++ b/src/parser/citation.rs @@ -14,17 +14,12 @@ use super::citation_reference::must_balance_bracket; use super::org_source::BracketDepth; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; use crate::error::CustomError; use crate::error::Res; use crate::parser::citation_reference::citation_reference; use crate::parser::citation_reference::citation_reference_key; -use crate::parser::exiting::ExitClass; use crate::parser::object::Citation; use crate::parser::object_parser::standard_set_object; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::Object; diff --git a/src/parser/citation_reference.rs b/src/parser/citation_reference.rs index 0024fc3..dbad243 100644 --- a/src/parser/citation_reference.rs +++ b/src/parser/citation_reference.rs @@ -12,16 +12,11 @@ use nom::sequence::tuple; use super::org_source::BracketDepth; use super::org_source::OrgSource; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::exiting::ExitClass; use crate::parser::object::CitationReference; use crate::parser::object_parser::minimal_set_object; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::WORD_CONSTITUENT_CHARACTERS; diff --git a/src/parser/clock.rs b/src/parser/clock.rs index 7731a0c..7731f23 100644 --- a/src/parser/clock.rs +++ b/src/parser/clock.rs @@ -12,9 +12,7 @@ use nom::combinator::verify; use nom::sequence::tuple; use super::org_source::OrgSource; -use super::Context; use crate::error::Res; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; use crate::parser::Clock; diff --git a/src/parser/comment.rs b/src/parser/comment.rs index d336721..12d346b 100644 --- a/src/parser/comment.rs +++ b/src/parser/comment.rs @@ -13,12 +13,9 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::get_consumed; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::exit_matcher_parser; use crate::parser::util::immediate_in_section; use crate::parser::util::start_of_line; diff --git a/src/parser/diary_sexp.rs b/src/parser/diary_sexp.rs index 691f990..3b186e2 100644 --- a/src/parser/diary_sexp.rs +++ b/src/parser/diary_sexp.rs @@ -11,7 +11,6 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::sexp::sexp; -use super::Context; use crate::error::Res; use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; diff --git a/src/parser/document.rs b/src/parser/document.rs index 1fc0dbd..0de809a 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -18,87 +18,23 @@ use nom::multi::separated_list1; use nom::sequence::tuple; use super::element::Element; -use super::list::List; use super::object::Object; use super::org_source::convert_error; use super::org_source::OrgSource; -use super::parser_with_context::parser_with_context; -use super::source::Source; use super::token::AllTokensIterator; use super::token::Token; use super::util::exit_matcher_parser; use super::util::get_consumed; use super::util::start_of_line; -use super::Context; use crate::error::Res; use crate::parser::comment::comment; use crate::parser::element_parser::element; -use crate::parser::exiting::ExitClass; use crate::parser::object_parser::standard_set_object; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; use crate::parser::planning::planning; use crate::parser::property_drawer::property_drawer; use crate::parser::util::blank_line; use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting; -#[derive(Debug)] -pub struct Document<'s> { - pub source: &'s str, - pub zeroth_section: Option>, - pub children: Vec>, -} - -#[derive(Debug)] -pub struct Heading<'s> { - pub source: &'s str, - pub stars: usize, - pub todo_keyword: Option<&'s str>, - // TODO: add todo-type enum - pub title: Vec>, - pub tags: Vec<&'s str>, - pub children: Vec>, -} - -#[derive(Debug)] -pub struct Section<'s> { - pub source: &'s str, - pub children: Vec>, -} - -#[derive(Debug)] -pub enum DocumentElement<'s> { - Heading(Heading<'s>), - Section(Section<'s>), -} - -impl<'s> Source<'s> for Document<'s> { - fn get_source(&'s self) -> &'s str { - self.source - } -} - -impl<'s> Source<'s> for DocumentElement<'s> { - fn get_source(&'s self) -> &'s str { - match self { - DocumentElement::Heading(obj) => obj.source, - DocumentElement::Section(obj) => obj.source, - } - } -} - -impl<'s> Source<'s> for Section<'s> { - fn get_source(&'s self) -> &'s str { - self.source - } -} - -impl<'s> Source<'s> for Heading<'s> { - fn get_source(&'s self) -> &'s str { - self.source - } -} - #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[allow(dead_code)] pub fn document(input: &str) -> Res<&str, Document> { diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index 213cc5e..c927a0b 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -11,16 +11,10 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::org_source::OrgSource; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::element_parser::element; -use crate::parser::exiting::ExitClass; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; -use crate::parser::source::SetSource; use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; diff --git a/src/parser/dynamic_block.rs b/src/parser/dynamic_block.rs index 679a701..178abb0 100644 --- a/src/parser/dynamic_block.rs +++ b/src/parser/dynamic_block.rs @@ -12,18 +12,12 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::org_source::OrgSource; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::element_parser::element; -use crate::parser::exiting::ExitClass; use crate::parser::greater_element::DynamicBlock; use crate::parser::lesser_element::Paragraph; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; -use crate::parser::source::SetSource; use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index f9451ca..3d083d6 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -24,14 +24,11 @@ use super::org_source::OrgSource; use super::paragraph::paragraph; use super::plain_list::detect_plain_list; use super::plain_list::plain_list; -use super::source::SetSource; use super::util::get_consumed; use super::util::maybe_consume_trailing_whitespace_if_not_exiting; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::table::org_mode_table; pub const fn element( diff --git a/src/parser/entity.rs b/src/parser/entity.rs index 4683e1c..a01e24c 100644 --- a/src/parser/entity.rs +++ b/src/parser/entity.rs @@ -8,7 +8,6 @@ use nom::combinator::recognize; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; diff --git a/src/parser/export_snippet.rs b/src/parser/export_snippet.rs index 85ef51b..b967ed6 100644 --- a/src/parser/export_snippet.rs +++ b/src/parser/export_snippet.rs @@ -9,12 +9,7 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; use crate::error::Res; -use crate::parser::exiting::ExitClass; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::ExportSnippet; diff --git a/src/parser/fixed_width_area.rs b/src/parser/fixed_width_area.rs index 3660069..5822b8c 100644 --- a/src/parser/fixed_width_area.rs +++ b/src/parser/fixed_width_area.rs @@ -12,9 +12,7 @@ use nom::sequence::preceded; use nom::sequence::tuple; use super::org_source::OrgSource; -use super::Context; use crate::error::Res; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 310620d..92bc23a 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -12,16 +12,11 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::WORD_CONSTITUENT_CHARACTERS; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::element_parser::element; -use crate::parser::exiting::ExitClass; use crate::parser::greater_element::FootnoteDefinition; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; diff --git a/src/parser/footnote_reference.rs b/src/parser/footnote_reference.rs index d82f514..0af0825 100644 --- a/src/parser/footnote_reference.rs +++ b/src/parser/footnote_reference.rs @@ -6,17 +6,12 @@ use nom::multi::many_till; use super::org_source::BracketDepth; use super::org_source::OrgSource; -use super::parser_context::ContextElement; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::exiting::ExitClass; use crate::parser::footnote_definition::label; use crate::parser::object_parser::standard_set_object; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::FootnoteReference; diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 99ff850..125d1b3 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -13,17 +13,11 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::in_section; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::element_parser::element; -use crate::parser::exiting::ExitClass; use crate::parser::greater_element::GreaterBlock; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; -use crate::parser::source::SetSource; use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; diff --git a/src/parser/horizontal_rule.rs b/src/parser/horizontal_rule.rs index acf4775..451fae0 100644 --- a/src/parser/horizontal_rule.rs +++ b/src/parser/horizontal_rule.rs @@ -9,7 +9,6 @@ use nom::multi::many1_count; use nom::sequence::tuple; use super::org_source::OrgSource; -use super::Context; use crate::error::Res; use crate::parser::util::start_of_line; use crate::parser::HorizontalRule; diff --git a/src/parser/inline_babel_call.rs b/src/parser/inline_babel_call.rs index 6f3479e..9409e60 100644 --- a/src/parser/inline_babel_call.rs +++ b/src/parser/inline_babel_call.rs @@ -12,14 +12,9 @@ use nom::multi::many_till; use super::org_source::BracketDepth; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::exiting::ExitClass; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::InlineBabelCall; diff --git a/src/parser/inline_source_block.rs b/src/parser/inline_source_block.rs index e61bea0..28a8cc3 100644 --- a/src/parser/inline_source_block.rs +++ b/src/parser/inline_source_block.rs @@ -14,14 +14,9 @@ use tracing::span; use super::org_source::BracketDepth; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::exiting::ExitClass; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::InlineSourceBlock; diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index 6e32be1..e2afc4a 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -16,7 +16,6 @@ use nom::sequence::tuple; use super::org_source::BracketDepth; use super::org_source::OrgSource; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; diff --git a/src/parser/latex_environment.rs b/src/parser/latex_environment.rs index 4697e9d..750424f 100644 --- a/src/parser/latex_environment.rs +++ b/src/parser/latex_environment.rs @@ -13,12 +13,7 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::get_consumed; -use super::Context; use crate::error::Res; -use crate::parser::exiting::ExitClass; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::exit_matcher_parser; use crate::parser::util::start_of_line; use crate::parser::LatexEnvironment; diff --git a/src/parser/latex_fragment.rs b/src/parser/latex_fragment.rs index 4be6a0e..a964a7d 100644 --- a/src/parser/latex_fragment.rs +++ b/src/parser/latex_fragment.rs @@ -14,11 +14,9 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::LatexFragment; diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index 9615727..4191830 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -12,9 +12,7 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::org_source::OrgSource; -use super::Context; use crate::error::Res; -use crate::parser::exiting::ExitClass; use crate::parser::lesser_element::CommentBlock; use crate::parser::lesser_element::ExampleBlock; use crate::parser::lesser_element::ExportBlock; @@ -23,9 +21,6 @@ use crate::parser::lesser_element::VerseBlock; use crate::parser::object::Object; use crate::parser::object::PlainText; use crate::parser::object_parser::standard_set_object; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; diff --git a/src/parser/line_break.rs b/src/parser/line_break.rs index c38f3e0..caa3416 100644 --- a/src/parser/line_break.rs +++ b/src/parser/line_break.rs @@ -5,7 +5,6 @@ use nom::combinator::recognize; use nom::multi::many0; use super::org_source::OrgSource; -use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 6844477..b4452bc 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -7,16 +7,13 @@ mod diary_sexp; mod document; mod drawer; mod dynamic_block; -mod element; mod element_parser; mod entity; -mod exiting; mod export_snippet; mod fixed_width_area; mod footnote_definition; mod footnote_reference; mod greater_block; -mod greater_element; mod horizontal_rule; mod inline_babel_call; mod inline_source_block; @@ -24,9 +21,7 @@ mod keyword; mod latex_environment; mod latex_fragment; mod lesser_block; -mod lesser_element; mod line_break; -mod object; mod object_parser; mod org_macro; mod org_source; @@ -39,7 +34,6 @@ mod property_drawer; mod radio_link; mod regular_link; pub mod sexp; -mod source; mod statistics_cookie; mod subscript_and_superscript; mod table; @@ -49,65 +43,3 @@ mod timestamp; mod token; mod util; pub use document::document; -pub use document::Document; -pub use document::DocumentElement; -pub use document::Heading; -pub use document::Section; -pub use element::Element; -pub use greater_element::Drawer; -pub use greater_element::DynamicBlock; -pub use greater_element::FootnoteDefinition; -pub use greater_element::GreaterBlock; -pub use greater_element::PlainList; -pub use greater_element::PlainListItem; -pub use greater_element::PropertyDrawer; -pub use greater_element::Table; -pub use greater_element::TableRow; -pub use lesser_element::Clock; -pub use lesser_element::Comment; -pub use lesser_element::CommentBlock; -pub use lesser_element::DiarySexp; -pub use lesser_element::ExampleBlock; -pub use lesser_element::ExportBlock; -pub use lesser_element::FixedWidthArea; -pub use lesser_element::HorizontalRule; -pub use lesser_element::Keyword; -pub use lesser_element::LatexEnvironment; -pub use lesser_element::Paragraph; -pub use lesser_element::Planning; -pub use lesser_element::SrcBlock; -pub use lesser_element::TableCell; -pub use lesser_element::VerseBlock; -pub use object::AngleLink; -pub use object::Bold; -pub use object::Citation; -pub use object::CitationReference; -pub use object::Code; -pub use object::Entity; -pub use object::ExportSnippet; -pub use object::FootnoteReference; -pub use object::InlineBabelCall; -pub use object::InlineSourceBlock; -pub use object::Italic; -pub use object::LatexFragment; -pub use object::LineBreak; -pub use object::Object; -pub use object::OrgMacro; -pub use object::PlainLink; -pub use object::PlainText; -pub use object::RadioLink; -pub use object::RadioTarget; -pub use object::RegularLink; -pub use object::StatisticsCookie; -pub use object::StrikeThrough; -pub use object::Subscript; -pub use object::Superscript; -pub use object::Target; -pub use object::Timestamp; -pub use object::Underline; -pub use object::Verbatim; -pub use source::Source; - -use self::org_source::OrgSource; -use self::parser_context::Context; -use crate::error::Res; diff --git a/src/parser/object_parser.rs b/src/parser/object_parser.rs index 18faf11..7926b25 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -2,7 +2,6 @@ use nom::branch::alt; use nom::combinator::map; use super::org_source::OrgSource; -use super::parser_with_context::parser_with_context; use super::plain_text::plain_text; use super::regular_link::regular_link; use super::Context; diff --git a/src/parser/org_macro.rs b/src/parser/org_macro.rs index 65a86c4..ba67f4c 100644 --- a/src/parser/org_macro.rs +++ b/src/parser/org_macro.rs @@ -13,7 +13,6 @@ use super::Context; use crate::error::CustomError; use crate::error::Res; use crate::parser::object::OrgMacro; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; diff --git a/src/parser/org_source.rs b/src/parser/org_source.rs index 231cb10..dc2bf0c 100644 --- a/src/parser/org_source.rs +++ b/src/parser/org_source.rs @@ -27,7 +27,7 @@ pub struct OrgSource<'s> { impl<'s> std::fmt::Debug for OrgSource<'s> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_tuple("OrgSource") + f.debug_tuple("Org") .field(&Into::<&str>::into(self)) .finish() } diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index 9cfda4d..82be7b4 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -13,11 +13,7 @@ use super::util::blank_line; use super::util::get_consumed; use super::Context; use crate::error::Res; -use crate::parser::exiting::ExitClass; use crate::parser::object_parser::standard_set_object; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::exit_matcher_parser; use crate::parser::util::start_of_line; diff --git a/src/parser/plain_link.rs b/src/parser/plain_link.rs index 387f788..11e054b 100644 --- a/src/parser/plain_link.rs +++ b/src/parser/plain_link.rs @@ -15,11 +15,7 @@ use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::exiting::ExitClass; use crate::parser::object::PlainLink; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::WORD_CONSTITUENT_CHARACTERS; diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 8773008..d4827b5 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -18,9 +18,7 @@ use nom::sequence::tuple; use super::greater_element::PlainList; use super::greater_element::PlainListItem; -use super::object_parser::standard_set_object; use super::org_source::OrgSource; -use super::parser_with_context::parser_with_context; use super::util::non_whitespace_character; use super::Context; use super::Object; @@ -28,9 +26,6 @@ use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::element_parser::element; -use crate::parser::exiting::ExitClass; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; diff --git a/src/parser/plain_text.rs b/src/parser/plain_text.rs index 7d0423d..5a49faa 100644 --- a/src/parser/plain_text.rs +++ b/src/parser/plain_text.rs @@ -13,9 +13,6 @@ use super::radio_link::RematchObject; use super::Context; use super::Object; use crate::error::Res; -use crate::parser::object_parser::any_object_except_plain_text; -use crate::parser::parser_with_context::parser_with_context; -use crate::parser::util::exit_matcher_parser; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn plain_text<'r, 's>( diff --git a/src/parser/property_drawer.rs b/src/parser/property_drawer.rs index 8e73ba3..928c00b 100644 --- a/src/parser/property_drawer.rs +++ b/src/parser/property_drawer.rs @@ -18,13 +18,8 @@ use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::exiting::ExitClass; use crate::parser::greater_element::NodeProperty; use crate::parser::greater_element::PropertyDrawer; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; -use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::immediate_in_section; use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting; diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index bbe8f07..cb0a4e1 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -12,12 +12,6 @@ use super::Object; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::exiting::ExitClass; -use crate::parser::object_parser::minimal_set_object; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; -use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::RadioLink; use crate::parser::RadioTarget; diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index 9a36d09..7776209 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -7,18 +7,12 @@ use nom::combinator::verify; use nom::multi::many_till; use super::org_source::OrgSource; -use super::parser_with_context::parser_with_context; use super::util::get_consumed; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; use super::Context; use super::Object; use super::RegularLink; use crate::error::Res; -use crate::parser::exiting::ExitClass; -use crate::parser::object_parser::regular_link_description_object_set; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::util::exit_matcher_parser; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn regular_link<'r, 's>( diff --git a/src/parser/statistics_cookie.rs b/src/parser/statistics_cookie.rs index cae0de3..dc98a0b 100644 --- a/src/parser/statistics_cookie.rs +++ b/src/parser/statistics_cookie.rs @@ -7,7 +7,6 @@ use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; use super::Context; use crate::error::Res; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::StatisticsCookie; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] diff --git a/src/parser/subscript_and_superscript.rs b/src/parser/subscript_and_superscript.rs index 91d4274..6f10ad2 100644 --- a/src/parser/subscript_and_superscript.rs +++ b/src/parser/subscript_and_superscript.rs @@ -18,12 +18,6 @@ use super::Object; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::exiting::ExitClass; -use crate::parser::object_parser::standard_set_object; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; -use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::Subscript; use crate::parser::Superscript; diff --git a/src/parser/table.rs b/src/parser/table.rs index eb45ea8..188f7ff 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -12,17 +12,11 @@ use nom::multi::many1; use nom::multi::many_till; use nom::sequence::tuple; -use super::object_parser::table_cell_set_object; use super::org_source::OrgSource; use super::Context; use crate::error::Res; -use crate::parser::exiting::ExitClass; use crate::parser::greater_element::TableRow; use crate::parser::lesser_element::TableCell; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; -use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; use crate::parser::Table; diff --git a/src/parser/target.rs b/src/parser/target.rs index fd6b040..597db08 100644 --- a/src/parser/target.rs +++ b/src/parser/target.rs @@ -12,11 +12,6 @@ use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::exiting::ExitClass; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; -use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::Target; diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index 8ad438c..b6f5285 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -22,11 +22,6 @@ use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::exiting::ExitClass; -use crate::parser::object_parser::standard_set_object; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; use crate::parser::radio_link::rematch_target; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; diff --git a/src/parser/timestamp.rs b/src/parser/timestamp.rs index 55a6be1..3eff2e3 100644 --- a/src/parser/timestamp.rs +++ b/src/parser/timestamp.rs @@ -14,12 +14,6 @@ use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; use super::Context; use crate::error::Res; -use crate::parser::exiting::ExitClass; -use crate::parser::parser_context::ContextElement; -use crate::parser::parser_context::ContextTree; -use crate::parser::parser_context::ExitMatcherNode; -use crate::parser::parser_with_context::parser_with_context; -use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::Timestamp; diff --git a/src/parser/token.rs b/src/parser/token.rs index cc62562..bbf6d8e 100644 --- a/src/parser/token.rs +++ b/src/parser/token.rs @@ -1,14 +1,10 @@ use std::collections::VecDeque; -use super::Document; use super::Element; -use super::Heading; use super::Object; use super::PlainListItem; -use super::Section; use super::TableCell; use super::TableRow; -use crate::parser::DocumentElement; pub enum Token<'r, 's> { Document(&'r Document<'s>), diff --git a/src/parser/util.rs b/src/parser/util.rs index e59eadd..7f8529c 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -14,12 +14,10 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::org_source::OrgSource; -use super::parser_context::ContextElement; use super::Context; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::parser_with_context::parser_with_context; pub const WORD_CONSTITUENT_CHARACTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; diff --git a/src/types/document.rs b/src/types/document.rs new file mode 100644 index 0000000..fd08dc3 --- /dev/null +++ b/src/types/document.rs @@ -0,0 +1,56 @@ +#[derive(Debug)] +pub struct Document<'s> { + pub source: &'s str, + pub zeroth_section: Option>, + pub children: Vec>, +} + +#[derive(Debug)] +pub struct Heading<'s> { + pub source: &'s str, + pub stars: usize, + pub todo_keyword: Option<&'s str>, + // TODO: add todo-type enum + pub title: Vec>, + pub tags: Vec<&'s str>, + pub children: Vec>, +} + +#[derive(Debug)] +pub struct Section<'s> { + pub source: &'s str, + pub children: Vec>, +} + +#[derive(Debug)] +pub enum DocumentElement<'s> { + Heading(Heading<'s>), + Section(Section<'s>), +} + +impl<'s> Source<'s> for Document<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> Source<'s> for DocumentElement<'s> { + fn get_source(&'s self) -> &'s str { + match self { + DocumentElement::Heading(obj) => obj.source, + DocumentElement::Section(obj) => obj.source, + } + } +} + +impl<'s> Source<'s> for Section<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> Source<'s> for Heading<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} diff --git a/src/parser/element.rs b/src/types/element.rs similarity index 98% rename from src/parser/element.rs rename to src/types/element.rs index 9795ec6..5155189 100644 --- a/src/parser/element.rs +++ b/src/types/element.rs @@ -18,8 +18,6 @@ use super::lesser_element::Paragraph; use super::lesser_element::Planning; use super::lesser_element::SrcBlock; use super::lesser_element::VerseBlock; -use super::source::SetSource; -use super::source::Source; use super::Drawer; #[derive(Debug)] diff --git a/src/parser/greater_element.rs b/src/types/greater_element.rs similarity index 98% rename from src/parser/greater_element.rs rename to src/types/greater_element.rs index 5a46284..2a6b1f6 100644 --- a/src/parser/greater_element.rs +++ b/src/types/greater_element.rs @@ -1,6 +1,5 @@ use super::element::Element; use super::lesser_element::TableCell; -use super::source::Source; use super::Object; #[derive(Debug)] diff --git a/src/parser/lesser_element.rs b/src/types/lesser_element.rs similarity index 99% rename from src/parser/lesser_element.rs rename to src/types/lesser_element.rs index cac3adf..f87278d 100644 --- a/src/parser/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -1,5 +1,4 @@ use super::object::Object; -use super::source::Source; use super::PlainText; #[derive(Debug)] diff --git a/src/types/mod.rs b/src/types/mod.rs index e69de29..9d2f200 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -0,0 +1,65 @@ +mod document; +mod element; +mod greater_element; +mod lesser_element; +mod object; +mod source; +pub use document::Document; +pub use document::DocumentElement; +pub use document::Heading; +pub use document::Section; +pub use element::Element; +pub use greater_element::Drawer; +pub use greater_element::DynamicBlock; +pub use greater_element::FootnoteDefinition; +pub use greater_element::GreaterBlock; +pub use greater_element::PlainList; +pub use greater_element::PlainListItem; +pub use greater_element::PropertyDrawer; +pub use greater_element::Table; +pub use greater_element::TableRow; +pub use lesser_element::Clock; +pub use lesser_element::Comment; +pub use lesser_element::CommentBlock; +pub use lesser_element::DiarySexp; +pub use lesser_element::ExampleBlock; +pub use lesser_element::ExportBlock; +pub use lesser_element::FixedWidthArea; +pub use lesser_element::HorizontalRule; +pub use lesser_element::Keyword; +pub use lesser_element::LatexEnvironment; +pub use lesser_element::Paragraph; +pub use lesser_element::Planning; +pub use lesser_element::SrcBlock; +pub use lesser_element::TableCell; +pub use lesser_element::VerseBlock; +pub use object::AngleLink; +pub use object::Bold; +pub use object::Citation; +pub use object::CitationReference; +pub use object::Code; +pub use object::Entity; +pub use object::ExportSnippet; +pub use object::FootnoteReference; +pub use object::InlineBabelCall; +pub use object::InlineSourceBlock; +pub use object::Italic; +pub use object::LatexFragment; +pub use object::LineBreak; +pub use object::Object; +pub use object::OrgMacro; +pub use object::PlainLink; +pub use object::PlainText; +pub use object::RadioLink; +pub use object::RadioTarget; +pub use object::RegularLink; +pub use object::StatisticsCookie; +pub use object::StrikeThrough; +pub use object::Subscript; +pub use object::Superscript; +pub use object::Target; +pub use object::Timestamp; +pub use object::Underline; +pub use object::Verbatim; +pub use source::SetSource; +pub use source::Source; diff --git a/src/parser/object.rs b/src/types/object.rs similarity index 99% rename from src/parser/object.rs rename to src/types/object.rs index 9064a6f..1234c67 100644 --- a/src/parser/object.rs +++ b/src/types/object.rs @@ -1,5 +1,3 @@ -use super::source::Source; - #[derive(Debug, PartialEq)] pub enum Object<'s> { Bold(Bold<'s>), diff --git a/src/parser/source.rs b/src/types/source.rs similarity index 100% rename from src/parser/source.rs rename to src/types/source.rs From 12ad3b09f0b04a68f5c3a41d1d2d46b1484d1186 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 2 Sep 2023 19:15:47 -0400 Subject: [PATCH 06/24] Fixing imports. --- src/context/mod.rs | 4 ++++ src/parser/mod.rs | 1 + src/types/document.rs | 2 ++ src/types/greater_element.rs | 1 + src/types/lesser_element.rs | 1 + src/types/object.rs | 2 ++ 6 files changed, 11 insertions(+) diff --git a/src/context/mod.rs b/src/context/mod.rs index 3f33a26..175f67e 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -1,3 +1,7 @@ +use self::parser_context::Context; +use crate::error::Res; +use crate::parser::OrgSource; + mod exiting; mod list; mod parser_context; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index b4452bc..bc3648d 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -43,3 +43,4 @@ mod timestamp; mod token; mod util; pub use document::document; +pub use org_source::OrgSource; diff --git a/src/types/document.rs b/src/types/document.rs index fd08dc3..faafbc2 100644 --- a/src/types/document.rs +++ b/src/types/document.rs @@ -1,3 +1,5 @@ +use super::Source; + #[derive(Debug)] pub struct Document<'s> { pub source: &'s str, diff --git a/src/types/greater_element.rs b/src/types/greater_element.rs index 2a6b1f6..2aed91e 100644 --- a/src/types/greater_element.rs +++ b/src/types/greater_element.rs @@ -1,6 +1,7 @@ use super::element::Element; use super::lesser_element::TableCell; use super::Object; +use super::Source; #[derive(Debug)] pub struct PlainList<'s> { diff --git a/src/types/lesser_element.rs b/src/types/lesser_element.rs index f87278d..33f6529 100644 --- a/src/types/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -1,5 +1,6 @@ use super::object::Object; use super::PlainText; +use super::Source; #[derive(Debug)] pub struct Paragraph<'s> { diff --git a/src/types/object.rs b/src/types/object.rs index 1234c67..7e5da11 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -1,3 +1,5 @@ +use super::Source; + #[derive(Debug, PartialEq)] pub enum Object<'s> { Bold(Bold<'s>), From 564104f1e86d17094d4120e74da779e3d449df5c Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 2 Sep 2023 19:16:44 -0400 Subject: [PATCH 07/24] Switch to RefContext. --- src/parser/angle_link.rs | 6 ++-- src/parser/citation.rs | 10 +++---- src/parser/citation_reference.rs | 12 ++++---- src/parser/clock.rs | 6 ++-- src/parser/comment.rs | 4 +-- src/parser/diary_sexp.rs | 2 +- src/parser/document.rs | 14 ++++----- src/parser/drawer.rs | 4 +-- src/parser/dynamic_block.rs | 4 +-- src/parser/element_parser.rs | 4 +-- src/parser/entity.rs | 4 +-- src/parser/export_snippet.rs | 8 ++--- src/parser/fixed_width_area.rs | 4 +-- src/parser/footnote_definition.rs | 4 +-- src/parser/footnote_reference.rs | 10 +++---- src/parser/greater_block.rs | 4 +-- src/parser/horizontal_rule.rs | 2 +- src/parser/inline_babel_call.rs | 14 ++++----- src/parser/inline_source_block.rs | 14 ++++----- src/parser/keyword.rs | 4 +-- src/parser/latex_environment.rs | 6 ++-- src/parser/latex_fragment.rs | 26 ++++++++-------- src/parser/lesser_block.rs | 14 ++++----- src/parser/line_break.rs | 4 +-- src/parser/object_parser.rs | 10 +++---- src/parser/org_macro.rs | 8 ++--- src/parser/paragraph.rs | 4 +-- src/parser/plain_link.rs | 12 ++++---- src/parser/plain_list.rs | 16 +++++----- src/parser/plain_text.rs | 6 ++-- src/parser/planning.rs | 2 +- src/parser/property_drawer.rs | 10 +++---- src/parser/radio_link.rs | 10 +++---- src/parser/regular_link.rs | 12 ++++---- src/parser/statistics_cookie.rs | 6 ++-- src/parser/subscript_and_superscript.rs | 20 ++++++------- src/parser/table.rs | 14 ++++----- src/parser/target.rs | 4 +-- src/parser/text_markup.rs | 28 ++++++++--------- src/parser/timestamp.rs | 40 ++++++++++++------------- src/parser/util.rs | 14 ++++----- 41 files changed, 200 insertions(+), 200 deletions(-) diff --git a/src/parser/angle_link.rs b/src/parser/angle_link.rs index 800ba05..519fa03 100644 --- a/src/parser/angle_link.rs +++ b/src/parser/angle_link.rs @@ -14,7 +14,7 @@ use crate::parser::AngleLink; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn angle_link<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, AngleLink<'s>> { let (remaining, _) = tag("<")(input)?; @@ -37,7 +37,7 @@ pub fn angle_link<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn path_angle<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = @@ -54,7 +54,7 @@ fn path_angle<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn path_angle_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { tag(">")(input) diff --git a/src/parser/citation.rs b/src/parser/citation.rs index 05636b8..3919e7a 100644 --- a/src/parser/citation.rs +++ b/src/parser/citation.rs @@ -26,7 +26,7 @@ use crate::parser::Object; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn citation<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Citation<'s>> { // TODO: Despite being a standard object, citations cannot exist inside the global prefix/suffix for other citations because citations must contain something that matches @key which is forbidden inside the global prefix/suffix. This TODO is to evaluate if its worth putting in an explicit check for this (which can be easily accomplished by checking the output of `get_bracket_depth()`). I suspect its not worth it because I expect, outside of intentionally crafted inputs, this parser will exit immediately inside a citation since it is unlikely to find the "[cite" substring inside a citation global prefix/suffix. @@ -78,7 +78,7 @@ fn variant<'r, 's>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn global_prefix<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = global_prefix_end(input.get_bracket_depth()); @@ -108,7 +108,7 @@ fn global_prefix_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _global_prefix_end<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { @@ -131,7 +131,7 @@ fn _global_prefix_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn global_suffix<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = global_suffix_end(input.get_bracket_depth()); @@ -160,7 +160,7 @@ fn global_suffix_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _global_suffix_end<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/citation_reference.rs b/src/parser/citation_reference.rs index dbad243..bd4e832 100644 --- a/src/parser/citation_reference.rs +++ b/src/parser/citation_reference.rs @@ -24,7 +24,7 @@ use crate::parser::Object; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn citation_reference<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, CitationReference<'s>> { let (remaining, _prefix) = @@ -44,7 +44,7 @@ pub fn citation_reference<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn citation_reference_key<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, source) = recognize(tuple(( @@ -64,7 +64,7 @@ pub fn citation_reference_key<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn key_prefix<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = key_prefix_end(input.get_bracket_depth()); @@ -85,7 +85,7 @@ fn key_prefix<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn key_suffix<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = key_suffix_end(input.get_bracket_depth()); @@ -114,7 +114,7 @@ fn key_prefix_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _key_prefix_end<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { @@ -145,7 +145,7 @@ fn key_suffix_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _key_suffix_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/clock.rs b/src/parser/clock.rs index 7731f23..759f54f 100644 --- a/src/parser/clock.rs +++ b/src/parser/clock.rs @@ -19,7 +19,7 @@ use crate::parser::Clock; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn clock<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Clock<'s>> { start_of_line(input)?; @@ -43,7 +43,7 @@ pub fn clock<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inactive_timestamp_range_duration<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( @@ -65,7 +65,7 @@ fn inactive_timestamp_range_duration<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inactive_timestamp<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( diff --git a/src/parser/comment.rs b/src/parser/comment.rs index 12d346b..a2e74d6 100644 --- a/src/parser/comment.rs +++ b/src/parser/comment.rs @@ -23,7 +23,7 @@ use crate::parser::Comment; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn comment<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Comment<'s>> { if immediate_in_section(context, "comment") { @@ -49,7 +49,7 @@ pub fn comment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn comment_line<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; diff --git a/src/parser/diary_sexp.rs b/src/parser/diary_sexp.rs index 3b186e2..67fbc5f 100644 --- a/src/parser/diary_sexp.rs +++ b/src/parser/diary_sexp.rs @@ -18,7 +18,7 @@ use crate::parser::DiarySexp; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn diary_sexp<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, DiarySexp<'s>> { start_of_line(input)?; diff --git a/src/parser/document.rs b/src/parser/document.rs index 0de809a..d5b6c1f 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -71,7 +71,7 @@ pub fn document(input: &str) -> Res<&str, Document> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _document<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Document<'s>> { let zeroth_section_matcher = parser_with_context!(zeroth_section)(context); @@ -92,7 +92,7 @@ fn _document<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn zeroth_section<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Section<'s>> { // TODO: The zeroth section is specialized so it probably needs its own parser @@ -146,7 +146,7 @@ fn zeroth_section<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn section<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, mut input: OrgSource<'s>, ) -> Res, Section<'s>> { // TODO: The zeroth section is specialized so it probably needs its own parser @@ -196,7 +196,7 @@ fn section<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn section_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(detect_headline)(input) @@ -210,7 +210,7 @@ const fn heading( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _heading<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, parent_stars: usize, ) -> Res, Heading<'s>> { @@ -257,7 +257,7 @@ fn detect_headline<'s>(input: OrgSource<'s>) -> Res, ()> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn headline<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, parent_stars: usize, ) -> Res< @@ -312,7 +312,7 @@ fn headline<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn headline_title_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index c927a0b..c5b7646 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -27,7 +27,7 @@ use crate::parser::Paragraph; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn drawer<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Drawer<'s>> { if immediate_in_section(context, "drawer") { @@ -93,7 +93,7 @@ fn name<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn drawer_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; diff --git a/src/parser/dynamic_block.rs b/src/parser/dynamic_block.rs index 178abb0..c9ecc57 100644 --- a/src/parser/dynamic_block.rs +++ b/src/parser/dynamic_block.rs @@ -27,7 +27,7 @@ use crate::parser::Element; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn dynamic_block<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, DynamicBlock<'s>> { // TODO: Do I need to differentiate between different dynamic block types. @@ -101,7 +101,7 @@ fn parameters<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn dynamic_block_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index 3d083d6..8d40274 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -39,7 +39,7 @@ pub const fn element( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _element<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, can_be_paragraph: bool, ) -> Res, Element<'s>> { @@ -121,7 +121,7 @@ pub const fn detect_element( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _detect_element<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, can_be_paragraph: bool, ) -> Res, ()> { diff --git a/src/parser/entity.rs b/src/parser/entity.rs index a01e24c..b9420d1 100644 --- a/src/parser/entity.rs +++ b/src/parser/entity.rs @@ -433,7 +433,7 @@ const ORG_ENTITIES: [&'static str; 413] = [ #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn entity<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Entity<'s>> { let (remaining, _) = tag("\\")(input)?; @@ -454,7 +454,7 @@ pub fn entity<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn name<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // TODO: This should be defined by org-entities and optionally org-entities-user diff --git a/src/parser/export_snippet.rs b/src/parser/export_snippet.rs index b967ed6..839a1aa 100644 --- a/src/parser/export_snippet.rs +++ b/src/parser/export_snippet.rs @@ -16,7 +16,7 @@ use crate::parser::ExportSnippet; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn export_snippet<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, ExportSnippet<'s>> { let (remaining, _) = tag("@@")(input)?; @@ -46,7 +46,7 @@ pub fn export_snippet<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn backend<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, backend_name) = @@ -57,7 +57,7 @@ fn backend<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn contents<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, source) = recognize(verify( @@ -69,7 +69,7 @@ fn contents<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn export_snippet_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { tag("@@")(input) diff --git a/src/parser/fixed_width_area.rs b/src/parser/fixed_width_area.rs index 5822b8c..4d29795 100644 --- a/src/parser/fixed_width_area.rs +++ b/src/parser/fixed_width_area.rs @@ -20,7 +20,7 @@ use crate::parser::FixedWidthArea; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn fixed_width_area<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, FixedWidthArea<'s>> { let fixed_width_area_line_matcher = parser_with_context!(fixed_width_area_line)(context); @@ -40,7 +40,7 @@ pub fn fixed_width_area<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn fixed_width_area_line<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 92bc23a..24eff27 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -26,7 +26,7 @@ use crate::parser::util::start_of_line; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn footnote_definition<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteDefinition<'s>> { if immediate_in_section(context, "footnote definition") { @@ -72,7 +72,7 @@ pub fn label<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn footnote_definition_end<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, source) = alt(( diff --git a/src/parser/footnote_reference.rs b/src/parser/footnote_reference.rs index 0af0825..27c2a2c 100644 --- a/src/parser/footnote_reference.rs +++ b/src/parser/footnote_reference.rs @@ -18,7 +18,7 @@ use crate::parser::FootnoteReference; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn footnote_reference<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteReference<'s>> { alt(( @@ -30,7 +30,7 @@ pub fn footnote_reference<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn anonymous_footnote<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteReference<'s>> { let (remaining, _) = tag_no_case("[fn::")(input)?; @@ -64,7 +64,7 @@ fn anonymous_footnote<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inline_footnote<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteReference<'s>> { let (remaining, _) = tag_no_case("[fn:")(input)?; @@ -100,7 +100,7 @@ fn inline_footnote<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn footnote_reference_only<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteReference<'s>> { let (remaining, _) = tag_no_case("[fn:")(input)?; @@ -129,7 +129,7 @@ fn footnote_definition_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _footnote_definition_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 125d1b3..4cc6113 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -27,7 +27,7 @@ use crate::parser::Paragraph; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn greater_block<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, GreaterBlock<'s>> { // TODO: Do I need to differentiate between different greater block types. @@ -124,7 +124,7 @@ fn greater_block_end<'x>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _greater_block_end<'r, 's, 'x>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, name: &'x str, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/horizontal_rule.rs b/src/parser/horizontal_rule.rs index 451fae0..f5ed6ca 100644 --- a/src/parser/horizontal_rule.rs +++ b/src/parser/horizontal_rule.rs @@ -15,7 +15,7 @@ use crate::parser::HorizontalRule; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn horizontal_rule<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, HorizontalRule<'s>> { start_of_line(input)?; diff --git a/src/parser/inline_babel_call.rs b/src/parser/inline_babel_call.rs index 9409e60..5300bf4 100644 --- a/src/parser/inline_babel_call.rs +++ b/src/parser/inline_babel_call.rs @@ -21,7 +21,7 @@ use crate::parser::InlineBabelCall; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn inline_babel_call<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, InlineBabelCall<'s>> { let (remaining, _) = tag_no_case("call_")(input)?; @@ -42,7 +42,7 @@ pub fn inline_babel_call<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn name<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = @@ -59,7 +59,7 @@ fn name<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn name_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(one_of("[("))(input) @@ -67,7 +67,7 @@ fn name_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn header<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("[")(input)?; @@ -97,7 +97,7 @@ fn header_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _header_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { @@ -117,7 +117,7 @@ fn _header_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn argument<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("(")(input)?; @@ -147,7 +147,7 @@ fn argument_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _argument_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, starting_parenthesis_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/inline_source_block.rs b/src/parser/inline_source_block.rs index 28a8cc3..941dc87 100644 --- a/src/parser/inline_source_block.rs +++ b/src/parser/inline_source_block.rs @@ -23,7 +23,7 @@ use crate::parser::InlineSourceBlock; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn inline_source_block<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, InlineSourceBlock<'s>> { let (remaining, _) = tag_no_case("src_")(input)?; @@ -43,7 +43,7 @@ pub fn inline_source_block<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn lang<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = @@ -60,7 +60,7 @@ fn lang<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn lang_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(one_of("[{"))(input) @@ -68,7 +68,7 @@ fn lang_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn header<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("[")(input)?; @@ -98,7 +98,7 @@ fn header_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _header_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { @@ -118,7 +118,7 @@ fn _header_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn body<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("{")(input)?; @@ -156,7 +156,7 @@ fn body_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _body_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, starting_brace_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index e2afc4a..99053d9 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -30,7 +30,7 @@ const ORG_ELEMENT_DUAL_KEYWORDS: [&'static str; 2] = ["caption", "results"]; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn keyword<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Keyword<'s>> { start_of_line(input)?; @@ -55,7 +55,7 @@ pub fn keyword<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn affiliated_keyword<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Keyword<'s>> { start_of_line(input)?; diff --git a/src/parser/latex_environment.rs b/src/parser/latex_environment.rs index 750424f..4a71ef6 100644 --- a/src/parser/latex_environment.rs +++ b/src/parser/latex_environment.rs @@ -20,7 +20,7 @@ use crate::parser::LatexEnvironment; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn latex_environment<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, LatexEnvironment<'s>> { start_of_line(input)?; @@ -67,7 +67,7 @@ pub fn contents< F: Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>, >( end_matcher: F, - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, source) = recognize(many_till( @@ -92,7 +92,7 @@ fn latex_environment_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _latex_environment_end<'r, 's, 'x>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, current_name_lower: &'x str, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/latex_fragment.rs b/src/parser/latex_fragment.rs index a964a7d..a4b54f9 100644 --- a/src/parser/latex_fragment.rs +++ b/src/parser/latex_fragment.rs @@ -23,7 +23,7 @@ use crate::parser::LatexFragment; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn latex_fragment<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, LatexFragment<'s>> { let (remaining, _) = alt(( @@ -47,7 +47,7 @@ pub fn latex_fragment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn raw_latex_fragment<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("\\")(input)?; @@ -60,7 +60,7 @@ fn raw_latex_fragment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn name<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alpha1(input) @@ -68,7 +68,7 @@ fn name<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn brackets<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, body) = alt(( @@ -100,7 +100,7 @@ fn brackets<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn escaped_parenthesis_fragment<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("\\(")(input)?; @@ -119,7 +119,7 @@ fn escaped_parenthesis_fragment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn escaped_bracket_fragment<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("\\[")(input)?; @@ -138,7 +138,7 @@ fn escaped_bracket_fragment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn double_dollar_fragment<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // TODO: The documentation on the dollar sign versions is incomplete. Test to figure out what the real requirements are. For example, can this span more than 3 lines and can this contain a single $ since its terminated by $$? @@ -158,7 +158,7 @@ fn double_dollar_fragment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn dollar_char_fragment<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (_, _) = pre(context, input)?; @@ -172,7 +172,7 @@ fn dollar_char_fragment<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn pre<'r, 's>(_context: Context<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +pub fn pre<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { let preceding_character = input.get_preceding_character(); if let Some('$') = preceding_character { return Err(nom::Err::Error(CustomError::MyError(MyError( @@ -183,7 +183,7 @@ pub fn pre<'r, 's>(_context: Context<'r, 's>, input: OrgSource<'s>) -> Res(_context: Context<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +pub fn post<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { // TODO: What about eof? Test to find out. // TODO: Figure out which punctuation characters should be included. @@ -193,7 +193,7 @@ pub fn post<'r, 's>(_context: Context<'r, 's>, input: OrgSource<'s>) -> Res( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (_, _) = pre(context, input)?; @@ -219,7 +219,7 @@ fn bordered_dollar_fragment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn open_border<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(verify(none_of(".,;$"), |c| !c.is_whitespace()))(input) @@ -227,7 +227,7 @@ pub fn open_border<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn close_border<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, ()> { let preceding_character = input.get_preceding_character(); diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index 4191830..eb241cc 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -29,7 +29,7 @@ use crate::parser::util::text_until_exit; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn verse_block<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, VerseBlock<'s>> { let (remaining, name) = lesser_block_begin("verse")(context, input)?; @@ -80,7 +80,7 @@ pub fn verse_block<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn comment_block<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, CommentBlock<'s>> { let (remaining, name) = lesser_block_begin("comment")(context, input)?; @@ -116,7 +116,7 @@ pub fn comment_block<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn example_block<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, ExampleBlock<'s>> { let (remaining, _name) = lesser_block_begin("example")(context, input)?; @@ -152,7 +152,7 @@ pub fn example_block<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn export_block<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, ExportBlock<'s>> { let (remaining, name) = lesser_block_begin("export")(context, input)?; @@ -189,7 +189,7 @@ pub fn export_block<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn src_block<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, SrcBlock<'s>> { let (remaining, name) = lesser_block_begin("src")(context, input)?; @@ -245,7 +245,7 @@ fn lesser_block_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _lesser_block_end<'r, 's, 'x>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, current_name_lower: &'x str, ) -> Res, OrgSource<'s>> { @@ -272,7 +272,7 @@ const fn lesser_block_begin( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _lesser_block_begin<'r, 's, 'x>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, current_name_lower: &'x str, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/line_break.rs b/src/parser/line_break.rs index caa3416..33a68a7 100644 --- a/src/parser/line_break.rs +++ b/src/parser/line_break.rs @@ -13,7 +13,7 @@ use crate::parser::LineBreak; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn line_break<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, LineBreak<'s>> { let (remaining, _) = pre(context, input)?; @@ -30,7 +30,7 @@ pub fn line_break<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn pre<'r, 's>(_context: Context<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +fn pre<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { let preceding_character = input.get_preceding_character(); match preceding_character { // If None, we are at the start of the file diff --git a/src/parser/object_parser.rs b/src/parser/object_parser.rs index 7926b25..b314af1 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -29,7 +29,7 @@ use crate::parser::timestamp::timestamp; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn standard_set_object<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, object) = alt(( @@ -87,7 +87,7 @@ pub fn standard_set_object<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn minimal_set_object<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, object) = alt(( @@ -109,7 +109,7 @@ pub fn minimal_set_object<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn any_object_except_plain_text<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, object) = alt(( @@ -166,7 +166,7 @@ pub fn any_object_except_plain_text<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn regular_link_description_object_set<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { // TODO: It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]] @@ -195,7 +195,7 @@ pub fn regular_link_description_object_set<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn table_cell_set_object<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, object) = alt(( diff --git a/src/parser/org_macro.rs b/src/parser/org_macro.rs index ba67f4c..70e8447 100644 --- a/src/parser/org_macro.rs +++ b/src/parser/org_macro.rs @@ -18,7 +18,7 @@ use crate::parser::util::get_consumed; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn org_macro<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgMacro<'s>> { let (remaining, _) = tag("{{{")(input)?; @@ -45,7 +45,7 @@ pub fn org_macro<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn org_macro_name<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = verify(anychar, |c| c.is_alphabetic())(input)?; @@ -58,7 +58,7 @@ fn org_macro_name<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn org_macro_args<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let (remaining, _) = tag("(")(input)?; @@ -71,7 +71,7 @@ fn org_macro_args<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn org_macro_arg<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let mut remaining = input; diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index 82be7b4..59f4bb5 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -19,7 +19,7 @@ use crate::parser::util::start_of_line; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn paragraph<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Paragraph<'s>> { let parser_context = @@ -50,7 +50,7 @@ pub fn paragraph<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn paragraph_end<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let non_paragraph_element_matcher = parser_with_context!(detect_element(false))(context); diff --git a/src/parser/plain_link.rs b/src/parser/plain_link.rs index 11e054b..bf7880a 100644 --- a/src/parser/plain_link.rs +++ b/src/parser/plain_link.rs @@ -49,7 +49,7 @@ const ORG_LINK_PARAMETERS: [&'static str; 23] = [ #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn plain_link<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, PlainLink<'s>> { let (remaining, _) = pre(context, input)?; @@ -69,7 +69,7 @@ pub fn plain_link<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn pre<'r, 's>(_context: Context<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +fn pre<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { let preceding_character = input.get_preceding_character(); match preceding_character { // If None, we are at the start of the file which is fine @@ -86,14 +86,14 @@ fn pre<'r, 's>(_context: Context<'r, 's>, input: OrgSource<'s>) -> Res(_context: Context<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +fn post<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { let (remaining, _) = alt((eof, recognize(none_of(WORD_CONSTITUENT_CHARACTERS))))(input)?; Ok((remaining, ())) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn protocol<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // TODO: This should be defined by org-link-parameters @@ -114,7 +114,7 @@ pub fn protocol<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn path_plain<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // TODO: "optionally containing parenthesis-wrapped non-whitespace non-bracket substrings up to a depth of two. The string must end with either a non-punctation non-whitespace character, a forwards slash, or a parenthesis-wrapped substring" @@ -136,7 +136,7 @@ fn path_plain<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn path_plain_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(many_till( diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index d4827b5..929d273 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -56,7 +56,7 @@ pub fn detect_plain_list<'s>(input: OrgSource<'s>) -> Res, ()> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn plain_list<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, PlainList<'s>> { let parser_context = context @@ -125,7 +125,7 @@ pub fn plain_list<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn plain_list_item<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, PlainListItem<'s>> { start_of_line(input)?; @@ -236,7 +236,7 @@ fn counter<'s>(i: OrgSource<'s>) -> Res, OrgSource<'s>> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn plain_list_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( @@ -261,7 +261,7 @@ const fn plain_list_item_end( tracing::instrument(ret, level = "debug", skip(line_indented_lte_matcher)) )] fn _plain_list_item_end<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, line_indented_lte_matcher: impl for<'rr, 'ss> Fn( Context<'rr, 'ss>, @@ -283,7 +283,7 @@ const fn line_indented_lte( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _line_indented_lte<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, indent_level: usize, ) -> Res, OrgSource<'s>> { @@ -298,7 +298,7 @@ fn _line_indented_lte<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn item_tag<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let parser_context = @@ -319,7 +319,7 @@ fn item_tag<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn item_tag_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(alt(( @@ -331,7 +331,7 @@ fn item_tag_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn item_tag_post_gap<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { verify( diff --git a/src/parser/plain_text.rs b/src/parser/plain_text.rs index 5a49faa..916f0fa 100644 --- a/src/parser/plain_text.rs +++ b/src/parser/plain_text.rs @@ -16,7 +16,7 @@ use crate::error::Res; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn plain_text<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, PlainText<'s>> { let (remaining, source) = recognize(verify( @@ -40,7 +40,7 @@ pub fn plain_text<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn plain_text_end<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(parser_with_context!(any_object_except_plain_text)(context))(input) @@ -50,7 +50,7 @@ impl<'x> RematchObject<'x> for PlainText<'x> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn rematch_object<'r, 's>( &'x self, - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { map(tag(self.source), |s| { diff --git a/src/parser/planning.rs b/src/parser/planning.rs index e6ea8e3..8d1ae8c 100644 --- a/src/parser/planning.rs +++ b/src/parser/planning.rs @@ -18,7 +18,7 @@ use crate::parser::util::start_of_line; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn planning<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Planning<'s>> { start_of_line(input)?; diff --git a/src/parser/property_drawer.rs b/src/parser/property_drawer.rs index 928c00b..b5affb7 100644 --- a/src/parser/property_drawer.rs +++ b/src/parser/property_drawer.rs @@ -27,7 +27,7 @@ use crate::parser::util::start_of_line; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn property_drawer<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, PropertyDrawer<'s>> { if immediate_in_section(context, "property-drawer") { @@ -75,7 +75,7 @@ pub fn property_drawer<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn property_drawer_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( @@ -89,7 +89,7 @@ fn property_drawer_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn node_property<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, NodeProperty<'s>> { let (remaining, (_start_of_line, _leading_whitespace, _open_colon, _name, _close_colon)) = @@ -132,7 +132,7 @@ fn node_property<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn node_property_name<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = @@ -157,7 +157,7 @@ fn node_property_name<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn node_property_name_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt((tag("+:"), tag(":")))(input) diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index cb0a4e1..de78303 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -18,7 +18,7 @@ use crate::parser::RadioTarget; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn radio_link<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, RadioLink<'s>> { let radio_targets = context @@ -49,7 +49,7 @@ pub fn radio_link<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn rematch_target<'x, 'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, target: &'x Vec>, input: OrgSource<'s>, ) -> Res, Vec>> { @@ -80,7 +80,7 @@ pub fn rematch_target<'x, 'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn radio_target<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, RadioTarget<'s>> { let (remaining, _opening) = tag("<<<")(input)?; @@ -113,7 +113,7 @@ pub fn radio_target<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn radio_target_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt((tag("<"), tag(">"), line_ending))(input) @@ -122,7 +122,7 @@ fn radio_target_end<'r, 's>( pub trait RematchObject<'x> { fn rematch_object<'r, 's>( &'x self, - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>>; } diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index 7776209..b64ebf3 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -16,7 +16,7 @@ use crate::error::Res; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn regular_link<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, RegularLink<'s>> { alt(( @@ -27,7 +27,7 @@ pub fn regular_link<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn regular_link_without_description<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, RegularLink<'s>> { let (remaining, _opening_bracket) = tag("[[")(input)?; @@ -46,7 +46,7 @@ pub fn regular_link_without_description<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn regular_link_with_description<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, RegularLink<'s>> { let (remaining, _opening_bracket) = tag("[[")(input)?; @@ -67,7 +67,7 @@ pub fn regular_link_with_description<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn pathreg<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, path) = escaped( @@ -83,7 +83,7 @@ pub fn pathreg<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn description<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let parser_context = @@ -104,7 +104,7 @@ pub fn description<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn description_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { tag("]]")(input) diff --git a/src/parser/statistics_cookie.rs b/src/parser/statistics_cookie.rs index dc98a0b..180dd49 100644 --- a/src/parser/statistics_cookie.rs +++ b/src/parser/statistics_cookie.rs @@ -11,7 +11,7 @@ use crate::parser::StatisticsCookie; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn statistics_cookie<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, StatisticsCookie<'s>> { alt(( @@ -22,7 +22,7 @@ pub fn statistics_cookie<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn percent_statistics_cookie<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, StatisticsCookie<'s>> { let (remaining, source) = @@ -39,7 +39,7 @@ pub fn percent_statistics_cookie<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn fraction_statistics_cookie<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, StatisticsCookie<'s>> { let (remaining, source) = recognize(tuple(( diff --git a/src/parser/subscript_and_superscript.rs b/src/parser/subscript_and_superscript.rs index 6f10ad2..e5233f8 100644 --- a/src/parser/subscript_and_superscript.rs +++ b/src/parser/subscript_and_superscript.rs @@ -24,7 +24,7 @@ use crate::parser::Superscript; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn subscript<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Subscript<'s>> { // We check for the underscore first before checking the pre-character as a minor optimization to avoid walking up the context tree to find the document root unnecessarily. @@ -44,7 +44,7 @@ pub fn subscript<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn superscript<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Superscript<'s>> { // We check for the circumflex first before checking the pre-character as a minor optimization to avoid walking up the context tree to find the document root unnecessarily. @@ -63,7 +63,7 @@ pub fn superscript<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn pre<'r, 's>(_context: Context<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +fn pre<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { let preceding_character = input.get_preceding_character(); match preceding_character { Some(c) if !c.is_whitespace() => {} @@ -84,7 +84,7 @@ enum ScriptBody<'s> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn script_body<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, ScriptBody<'s>> { alt(( @@ -102,7 +102,7 @@ fn script_body<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn script_asterisk<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { tag("*")(input) @@ -110,7 +110,7 @@ fn script_asterisk<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn script_alphanum<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _sign) = opt(recognize(one_of("+-")))(input)?; @@ -124,7 +124,7 @@ fn script_alphanum<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn script_alphanum_character<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(verify(anychar, |c| { @@ -134,7 +134,7 @@ fn script_alphanum_character<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn end_script_alphanum_character<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, final_char) = recognize(verify(anychar, |c| c.is_alphanumeric()))(input)?; @@ -146,7 +146,7 @@ fn end_script_alphanum_character<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn script_with_braces<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let (remaining, _) = tag("{")(input)?; @@ -176,7 +176,7 @@ fn script_with_braces_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _script_with_braces_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, starting_brace_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/table.rs b/src/parser/table.rs index 188f7ff..121f421 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -26,7 +26,7 @@ use crate::parser::Table; /// This is not the table.el style. #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn org_mode_table<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Table<'s>> { start_of_line(input)?; @@ -60,7 +60,7 @@ pub fn org_mode_table<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn table_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; @@ -69,7 +69,7 @@ fn table_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn org_mode_table_row<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, TableRow<'s>> { alt(( @@ -80,7 +80,7 @@ pub fn org_mode_table_row<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn org_mode_table_row_rule<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, TableRow<'s>> { start_of_line(input)?; @@ -97,7 +97,7 @@ pub fn org_mode_table_row_rule<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn org_mode_table_row_regular<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, TableRow<'s>> { start_of_line(input)?; @@ -117,7 +117,7 @@ pub fn org_mode_table_row_regular<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn org_mode_table_cell<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, TableCell<'s>> { let parser_context = @@ -150,7 +150,7 @@ pub fn org_mode_table_cell<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn org_mode_table_cell_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple((space0, alt((tag("|"), peek(line_ending))))))(input) diff --git a/src/parser/target.rs b/src/parser/target.rs index 597db08..ddbc1f5 100644 --- a/src/parser/target.rs +++ b/src/parser/target.rs @@ -17,7 +17,7 @@ use crate::parser::Target; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn target<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Target<'s>> { let (remaining, _) = tag("<<")(input)?; @@ -58,7 +58,7 @@ pub fn target<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn target_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(one_of("<>\n"))(input) diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index b6f5285..d80b4fd 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -36,7 +36,7 @@ use crate::parser::Verbatim; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn text_markup<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { alt(( @@ -54,7 +54,7 @@ pub fn text_markup<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn bold<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Bold<'s>> { let text_markup_object_specialized = text_markup_object("*"); @@ -71,7 +71,7 @@ pub fn bold<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn italic<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Italic<'s>> { let text_markup_object_specialized = text_markup_object("/"); @@ -88,7 +88,7 @@ pub fn italic<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn underline<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Underline<'s>> { let text_markup_object_specialized = text_markup_object("_"); @@ -105,7 +105,7 @@ pub fn underline<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn strike_through<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, StrikeThrough<'s>> { let text_markup_object_specialized = text_markup_object("+"); @@ -122,7 +122,7 @@ pub fn strike_through<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn verbatim<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Verbatim<'s>> { let text_markup_string_specialized = text_markup_string("="); @@ -139,7 +139,7 @@ pub fn verbatim<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn code<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Code<'s>> { let text_markup_string_specialized = text_markup_string("~"); @@ -165,7 +165,7 @@ fn text_markup_object( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _text_markup_object<'r, 's, 'x>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, marker_symbol: &'x str, ) -> Res, Vec>> { @@ -216,7 +216,7 @@ fn text_markup_string( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _text_markup_string<'r, 's, 'x>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, marker_symbol: &'x str, ) -> Res, OrgSource<'s>> { @@ -257,7 +257,7 @@ fn _text_markup_string<'r, 's, 'x>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn pre<'r, 's>(_context: Context<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +pub fn pre<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { let preceding_character = input.get_preceding_character(); match preceding_character { // If None, we are at the start of the file which is technically the beginning of a line. @@ -274,7 +274,7 @@ pub fn pre<'r, 's>(_context: Context<'r, 's>, input: OrgSource<'s>) -> Res(_context: Context<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +pub fn post<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { let (remaining, _) = alt((recognize(one_of(" \r\n\t-.,;:!?')}[\"")), line_ending))(input)?; Ok((remaining, ())) } @@ -290,7 +290,7 @@ fn text_markup_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _text_markup_end<'r, 's, 'x>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, marker_symbol: &'x str, ) -> Res, OrgSource<'s>> { @@ -307,7 +307,7 @@ impl<'x> RematchObject<'x> for Bold<'x> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn rematch_object<'r, 's>( &'x self, - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, children) = @@ -325,7 +325,7 @@ impl<'x> RematchObject<'x> for Bold<'x> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _rematch_text_markup_object<'r, 's, 'x>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, marker_symbol: &'static str, original_match_children: &'x Vec>, diff --git a/src/parser/timestamp.rs b/src/parser/timestamp.rs index 3eff2e3..dd719cb 100644 --- a/src/parser/timestamp.rs +++ b/src/parser/timestamp.rs @@ -19,7 +19,7 @@ use crate::parser::Timestamp; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn timestamp<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { // TODO: This would be more efficient if we didn't throw away the parse result of the first half of an active/inactive date range timestamp if the parse fails (as in, the first thing active_date_range_timestamp parses is a active_timestamp but then we throw that away if it doesn't turn out to be a full active_date_range_timestamp despite the active_timestamp parse being completely valid). I am going with the simplest/cleanest approach for the first implementation. @@ -37,7 +37,7 @@ pub fn timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn diary_timestamp<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("<%%(")(input)?; @@ -57,7 +57,7 @@ fn diary_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn sexp<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = @@ -79,7 +79,7 @@ fn sexp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn sexp_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt((tag(")>"), recognize(one_of(">\n"))))(input) @@ -87,7 +87,7 @@ fn sexp_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn active_timestamp<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("<")(input)?; @@ -121,7 +121,7 @@ fn active_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inactive_timestamp<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("[")(input)?; @@ -155,7 +155,7 @@ fn inactive_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn active_date_range_timestamp<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _first_timestamp) = active_timestamp(context, input)?; @@ -177,7 +177,7 @@ fn active_date_range_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn active_time_range_timestamp<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("<")(input)?; @@ -218,7 +218,7 @@ fn active_time_range_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inactive_date_range_timestamp<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _first_timestamp) = inactive_timestamp(context, input)?; @@ -240,7 +240,7 @@ fn inactive_date_range_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inactive_time_range_timestamp<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("[")(input)?; @@ -281,7 +281,7 @@ fn inactive_time_range_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn date<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _year) = verify(digit1, |year: &OrgSource<'_>| year.len() == 4)(input)?; @@ -299,7 +299,7 @@ fn date<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn dayname<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = @@ -321,7 +321,7 @@ fn dayname<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn dayname_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(verify(anychar, |c| { @@ -331,7 +331,7 @@ fn dayname_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn time<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _hour) = verify(digit1, |hour: &OrgSource<'_>| { @@ -347,7 +347,7 @@ fn time<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn time_rest<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, body) = recognize(verify( @@ -360,7 +360,7 @@ fn time_rest<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn active_time_rest_end<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt(( @@ -375,7 +375,7 @@ fn active_time_rest_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inactive_time_rest_end<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt(( @@ -390,7 +390,7 @@ fn inactive_time_rest_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn time_range_rest_end<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // We pop off the most recent context element to get a context tree with just the active/inactive_time_rest_end exit matcher (removing this function from the exit matcher chain) because the 2nd time in the range does not end when a "-TIME" pattern is found. @@ -403,7 +403,7 @@ fn time_range_rest_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn repeater<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // + for cumulative type @@ -419,7 +419,7 @@ fn repeater<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn warning_delay<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // - for all type diff --git a/src/parser/util.rs b/src/parser/util.rs index 7f8529c..d2d66b8 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -24,7 +24,7 @@ pub const WORD_CONSTITUENT_CHARACTERS: &str = /// Check if we are below a section of the given section type regardless of depth #[allow(dead_code)] -pub fn in_section<'r, 's, 'x>(context: Context<'r, 's>, section_name: &'x str) -> bool { +pub fn in_section<'r, 's, 'x>(context: RefContext<'r, 's>, section_name: &'x str) -> bool { for thing in context.iter() { match thing.get_data() { ContextElement::Context(name) if *name == section_name => return true, @@ -35,7 +35,7 @@ pub fn in_section<'r, 's, 'x>(context: Context<'r, 's>, section_name: &'x str) - } /// Checks if we are currently an immediate child of the given section type -pub fn immediate_in_section<'r, 's, 'x>(context: Context<'r, 's>, section_name: &'x str) -> bool { +pub fn immediate_in_section<'r, 's, 'x>(context: RefContext<'r, 's>, section_name: &'x str) -> bool { for thing in context.iter() { match thing.get_data() { ContextElement::Context(name) if *name == section_name => return true, @@ -68,7 +68,7 @@ pub fn element_trailing_whitespace<'s>(input: OrgSource<'s>) -> Res( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Option>> { if exit_matcher_parser(context, input).is_err() { @@ -80,7 +80,7 @@ pub fn maybe_consume_object_trailing_whitespace_if_not_exiting<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn maybe_consume_trailing_whitespace_if_not_exiting<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Option>> { if context.should_consume_trailing_whitespace() && exit_matcher_parser(context, input).is_err() @@ -93,7 +93,7 @@ pub fn maybe_consume_trailing_whitespace_if_not_exiting<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn maybe_consume_trailing_whitespace<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, Option>> { if context.should_consume_trailing_whitespace() { @@ -142,7 +142,7 @@ pub fn non_whitespace_character(input: OrgSource<'_>) -> Res, char /// Check that we are at the start of a line #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn exit_matcher_parser<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { peek(|i| context.check_exit_matcher(i))(input) @@ -150,7 +150,7 @@ pub fn exit_matcher_parser<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn text_until_exit<'r, 's>( - context: Context<'r, 's>, + context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(verify( From 22e9bc991f230d3facfcab8743fd1e16334bc393 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 2 Sep 2023 19:28:33 -0400 Subject: [PATCH 08/24] Fixing up compiler errors. --- src/context/mod.rs | 7 ++++++- src/context/parser_context.rs | 21 ++++----------------- src/parser/timestamp.rs | 9 +++++++-- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/context/mod.rs b/src/context/mod.rs index 175f67e..6738246 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -7,9 +7,14 @@ mod list; mod parser_context; mod parser_with_context; -type RefContext<'r, 's> = &'r Context<'r, 's>; +pub type RefContext<'r, 's> = &'r Context<'r, 's>; trait ContextMatcher = for<'r, 's> Fn(RefContext<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>; type DynContextMatcher<'c> = dyn ContextMatcher + 'c; trait Matcher = for<'s> Fn(OrgSource<'s>) -> Res, OrgSource<'s>>; type DynMatcher<'c> = dyn Matcher + 'c; + +pub use exiting::ExitClass; +pub use parser_context::ContextElement; +pub use parser_context::ExitMatcherNode; +pub(crate) use parser_with_context::parser_with_context; diff --git a/src/context/parser_context.rs b/src/context/parser_context.rs index 1dce6e9..99f3b24 100644 --- a/src/context/parser_context.rs +++ b/src/context/parser_context.rs @@ -1,12 +1,11 @@ use nom::combinator::eof; +use super::exiting::ExitClass; use super::list::List; -use super::org_source::OrgSource; use super::DynContextMatcher; -use super::Object; use crate::error::Res; -use crate::parser::exiting::ExitClass; -use crate::parser::list::ListType; +use crate::parser::OrgSource; +use crate::types::Object; // type Matcher = // dyn for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>; @@ -173,7 +172,7 @@ impl<'r, 's> Context<'r, 's> { ) } - pub fn push(&self, data: ContextElement<'r, 's>) -> Self { + pub fn with_additional_node(&self, data: ContextElement<'r, 's>) -> Self { let new_tree = self.tree.push(data); Self { global_settings: self.global_settings, @@ -182,18 +181,6 @@ impl<'r, 's> Context<'r, 's> { } } -impl<'r, 's> Default for Context<'r, 's> { - fn default() -> Self { - Context::new( - GlobalSettings::default(), - List::new(ContextElement::ExitMatcherNode(ExitMatcherNode { - exit_matcher: &document_end, - class: ExitClass::Document, - })), - ) - } -} - #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn document_end<'r, 's>( _context: Context<'r, 's>, diff --git a/src/parser/timestamp.rs b/src/parser/timestamp.rs index dd719cb..d924330 100644 --- a/src/parser/timestamp.rs +++ b/src/parser/timestamp.rs @@ -11,11 +11,16 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::org_source::OrgSource; +use super::util::exit_matcher_parser; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::Res; use crate::parser::util::get_consumed; -use crate::parser::Timestamp; +use crate::types::Timestamp; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn timestamp<'r, 's>( From 0d728510d7e92107ddd5c283001fe73a72498ee0 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 2 Sep 2023 20:46:17 -0400 Subject: [PATCH 09/24] Implement iterator for context. --- src/context/global_settings.rs | 16 ++++++++ src/context/list.rs | 18 +++++++++ src/context/mod.rs | 1 + src/context/parser_context.rs | 74 +++++++++++++++++++++------------- src/parser/timestamp.rs | 5 +-- src/parser/token.rs | 14 ++++--- src/parser/util.rs | 9 ++++- src/types/document.rs | 2 + src/types/element.rs | 2 + 9 files changed, 102 insertions(+), 39 deletions(-) create mode 100644 src/context/global_settings.rs diff --git a/src/context/global_settings.rs b/src/context/global_settings.rs new file mode 100644 index 0000000..a3ad30e --- /dev/null +++ b/src/context/global_settings.rs @@ -0,0 +1,16 @@ +#[derive(Debug)] +pub struct GlobalSettings<'s> { + placeholder: Option<&'s str>, +} + +impl<'s> GlobalSettings<'s> { + pub fn new() -> Self { + GlobalSettings { placeholder: None } + } +} + +impl<'s> Default for GlobalSettings<'s> { + fn default() -> Self { + GlobalSettings::new() + } +} diff --git a/src/context/list.rs b/src/context/list.rs index 27bc998..c0c021f 100644 --- a/src/context/list.rs +++ b/src/context/list.rs @@ -27,6 +27,10 @@ impl<'parent, T> List<'parent, T> { pub fn iter(&self) -> Iter<'_, T> { Iter { next: Some(self) } } + + pub fn iter_list(&self) -> IterList<'_, T> { + Iter { next: Some(self) } + } } pub trait ListType<'parent, T> { @@ -64,3 +68,17 @@ impl<'a, T> Iterator for Iter<'a, T> { ret } } + +pub struct IterList<'a, T> { + next: Link<'a, T>, +} + +impl<'a, T> Iterator for IterList<'a, T> { + type Item = &'a List<'a, T>; + + fn next(&mut self) -> Option { + let ret = self.next; + self.next = self.next.map(|this| this.get_parent()).flatten(); + ret + } +} diff --git a/src/context/mod.rs b/src/context/mod.rs index 6738246..b1a7e6f 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -3,6 +3,7 @@ use crate::error::Res; use crate::parser::OrgSource; mod exiting; +mod global_settings; mod list; mod parser_context; mod parser_with_context; diff --git a/src/context/parser_context.rs b/src/context/parser_context.rs index 99f3b24..b8cdf60 100644 --- a/src/context/parser_context.rs +++ b/src/context/parser_context.rs @@ -1,6 +1,7 @@ use nom::combinator::eof; use super::exiting::ExitClass; +use super::global_settings::GlobalSettings; use super::list::List; use super::DynContextMatcher; use crate::error::Res; @@ -128,33 +129,16 @@ impl<'r> std::fmt::Debug for ExitMatcherNode<'r> { } } -#[derive(Debug)] -pub struct GlobalSettings<'s> { - placeholder: Option<&'s str>, -} - -impl<'s> GlobalSettings<'s> { - pub fn new() -> Self { - GlobalSettings { placeholder: None } - } -} - -impl<'s> Default for GlobalSettings<'s> { - fn default() -> Self { - GlobalSettings::new() - } -} - #[derive(Debug)] pub struct Context<'r, 's> { global_settings: &'s GlobalSettings<'s>, - tree: List<'r, ContextElement<'r, 's>>, + tree: &'r List<'r, ContextElement<'r, 's>>, } impl<'r, 's> Context<'r, 's> { pub fn new( global_settings: &'s GlobalSettings<'s>, - tree: List<'r, ContextElement<'r, 's>>, + tree: &'r List<'r, ContextElement<'r, 's>>, ) -> Self { Self { global_settings, @@ -162,16 +146,6 @@ impl<'r, 's> Context<'r, 's> { } } - pub fn document_context(global_settings: &'s GlobalSettings<'s>) -> Self { - Context::new( - global_settings, - List::new(ContextElement::ExitMatcherNode(ExitMatcherNode { - exit_matcher: &document_end, - class: ExitClass::Document, - })), - ) - } - pub fn with_additional_node(&self, data: ContextElement<'r, 's>) -> Self { let new_tree = self.tree.push(data); Self { @@ -179,6 +153,24 @@ impl<'r, 's> Context<'r, 's> { tree: new_tree, } } + + pub fn iter(&self) -> super::list::Iter<'r, ContextElement<'r, 's>> { + self.tree.iter() + } + + pub fn iter_context(&self) -> Iter<'r, 's> { + Iter { + next: self.tree.iter_list(), + global_settings: self.global_settings, + } + } + + pub fn get_parent(&self) -> Option { + self.tree.get_parent().map(|parent_tree| Self { + global_settings: self.global_settings, + tree: parent_tree, + }) + } } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -188,3 +180,27 @@ fn document_end<'r, 's>( ) -> Res, OrgSource<'s>> { eof(input) } + +pub struct Iter<'r, 's> { + global_settings: &'s GlobalSettings<'s>, + next: super::list::IterList<'r, ContextElement<'r, 's>>, +} + +impl<'r, 's> Iterator for Iter<'r, 's> { + type Item = Context<'r, 's>; + + fn next(&mut self) -> Option { + let next_tree = self.next.next(); + let ret = next_tree.map(|parent_tree| Context::new(self.global_settings, parent_tree)); + ret + } +} + +impl<'r, 's> ContextElement<'r, 's> { + pub fn document_context() -> Self { + Self::ExitMatcherNode(ExitMatcherNode { + exit_matcher: &document_end, + class: ExitClass::Document, + }) + } +} diff --git a/src/parser/timestamp.rs b/src/parser/timestamp.rs index d924330..fa1e408 100644 --- a/src/parser/timestamp.rs +++ b/src/parser/timestamp.rs @@ -399,10 +399,9 @@ fn time_range_rest_end<'r, 's>( input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // We pop off the most recent context element to get a context tree with just the active/inactive_time_rest_end exit matcher (removing this function from the exit matcher chain) because the 2nd time in the range does not end when a "-TIME" pattern is found. - let parent_node = context.iter().next().expect("Two context elements are added to the tree when adding this exit matcher, so it should be impossible for this to return None."); - let parent_tree = ContextTree::branch_from(parent_node); + let parent_node = context.get_parent().expect("Two context elements are added to the tree when adding this exit matcher, so it should be impossible for this to return None."); let exit_contents = - recognize(tuple((tag("-"), parser_with_context!(time)(&parent_tree))))(input); + recognize(tuple((tag("-"), parser_with_context!(time)(&parent_node))))(input); exit_contents } diff --git a/src/parser/token.rs b/src/parser/token.rs index bbf6d8e..ea9ea8f 100644 --- a/src/parser/token.rs +++ b/src/parser/token.rs @@ -1,10 +1,14 @@ use std::collections::VecDeque; -use super::Element; -use super::Object; -use super::PlainListItem; -use super::TableCell; -use super::TableRow; +use crate::types::Document; +use crate::types::DocumentElement; +use crate::types::Element; +use crate::types::Heading; +use crate::types::Object; +use crate::types::PlainListItem; +use crate::types::Section; +use crate::types::TableCell; +use crate::types::TableRow; pub enum Token<'r, 's> { Document(&'r Document<'s>), diff --git a/src/parser/util.rs b/src/parser/util.rs index d2d66b8..92a35ec 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -14,7 +14,9 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::org_source::OrgSource; -use super::Context; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; @@ -35,7 +37,10 @@ pub fn in_section<'r, 's, 'x>(context: RefContext<'r, 's>, section_name: &'x str } /// Checks if we are currently an immediate child of the given section type -pub fn immediate_in_section<'r, 's, 'x>(context: RefContext<'r, 's>, section_name: &'x str) -> bool { +pub fn immediate_in_section<'r, 's, 'x>( + context: RefContext<'r, 's>, + section_name: &'x str, +) -> bool { for thing in context.iter() { match thing.get_data() { ContextElement::Context(name) if *name == section_name => return true, diff --git a/src/types/document.rs b/src/types/document.rs index faafbc2..957d7b9 100644 --- a/src/types/document.rs +++ b/src/types/document.rs @@ -1,3 +1,5 @@ +use super::Element; +use super::Object; use super::Source; #[derive(Debug)] diff --git a/src/types/element.rs b/src/types/element.rs index 5155189..c279657 100644 --- a/src/types/element.rs +++ b/src/types/element.rs @@ -19,6 +19,8 @@ use super::lesser_element::Planning; use super::lesser_element::SrcBlock; use super::lesser_element::VerseBlock; use super::Drawer; +use super::SetSource; +use super::Source; #[derive(Debug)] pub enum Element<'s> { From c309d14776888122fbec136eb23a6e14a8a52606 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 2 Sep 2023 20:52:02 -0400 Subject: [PATCH 10/24] Fix a reference to RefContext. --- src/context/list.rs | 2 +- src/context/parser_context.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/context/list.rs b/src/context/list.rs index c0c021f..405329c 100644 --- a/src/context/list.rs +++ b/src/context/list.rs @@ -29,7 +29,7 @@ impl<'parent, T> List<'parent, T> { } pub fn iter_list(&self) -> IterList<'_, T> { - Iter { next: Some(self) } + IterList { next: Some(self) } } } diff --git a/src/context/parser_context.rs b/src/context/parser_context.rs index b8cdf60..2e49f28 100644 --- a/src/context/parser_context.rs +++ b/src/context/parser_context.rs @@ -3,7 +3,9 @@ use nom::combinator::eof; use super::exiting::ExitClass; use super::global_settings::GlobalSettings; use super::list::List; +use super::list::ListType; use super::DynContextMatcher; +use super::RefContext; use crate::error::Res; use crate::parser::OrgSource; use crate::types::Object; @@ -175,7 +177,7 @@ impl<'r, 's> Context<'r, 's> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn document_end<'r, 's>( - _context: Context<'r, 's>, + _context: RefContext<'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { eof(input) From ba57eb16fddda8c836ce2e9e3e30801d95274e78 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 2 Sep 2023 22:44:21 -0400 Subject: [PATCH 11/24] Fix using references for context elements. --- src/context/list.rs | 17 +---------------- src/context/mod.rs | 12 +++++++----- src/context/parser_context.rs | 31 ++++++++++++++----------------- 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/context/list.rs b/src/context/list.rs index 405329c..98ee212 100644 --- a/src/context/list.rs +++ b/src/context/list.rs @@ -31,14 +31,8 @@ impl<'parent, T> List<'parent, T> { pub fn iter_list(&self) -> IterList<'_, T> { IterList { next: Some(self) } } -} -pub trait ListType<'parent, T> { - fn push(&'parent self, item: T) -> List<'parent, T>; -} - -impl<'parent, T> ListType<'parent, T> for List<'parent, T> { - fn push(&'parent self, item: T) -> Self { + pub fn push(&'parent self, item: T) -> Self { Self { data: item, parent: Some(self), @@ -46,15 +40,6 @@ impl<'parent, T> ListType<'parent, T> for List<'parent, T> { } } -impl<'parent, T> ListType<'parent, T> for Link<'parent, T> { - fn push(&'parent self, item: T) -> List<'parent, T> { - List { - data: item, - parent: *self, - } - } -} - pub struct Iter<'a, T> { next: Link<'a, T>, } diff --git a/src/context/mod.rs b/src/context/mod.rs index b1a7e6f..54e75e7 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -1,4 +1,3 @@ -use self::parser_context::Context; use crate::error::Res; use crate::parser::OrgSource; @@ -8,14 +7,17 @@ mod list; mod parser_context; mod parser_with_context; -pub type RefContext<'r, 's> = &'r Context<'r, 's>; -trait ContextMatcher = - for<'r, 's> Fn(RefContext<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>; +pub type RefContext<'b, 'r, 's> = &'b Context<'r, 's>; +pub trait ContextMatcher = + for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>; type DynContextMatcher<'c> = dyn ContextMatcher + 'c; -trait Matcher = for<'s> Fn(OrgSource<'s>) -> Res, OrgSource<'s>>; +pub trait Matcher = for<'s> Fn(OrgSource<'s>) -> Res, OrgSource<'s>>; type DynMatcher<'c> = dyn Matcher + 'c; pub use exiting::ExitClass; +pub use global_settings::GlobalSettings; +pub use list::List; +pub use parser_context::Context; pub use parser_context::ContextElement; pub use parser_context::ExitMatcherNode; pub(crate) use parser_with_context::parser_with_context; diff --git a/src/context/parser_context.rs b/src/context/parser_context.rs index 2e49f28..098f4da 100644 --- a/src/context/parser_context.rs +++ b/src/context/parser_context.rs @@ -3,7 +3,6 @@ use nom::combinator::eof; use super::exiting::ExitClass; use super::global_settings::GlobalSettings; use super::list::List; -use super::list::ListType; use super::DynContextMatcher; use super::RefContext; use crate::error::Res; @@ -134,13 +133,13 @@ impl<'r> std::fmt::Debug for ExitMatcherNode<'r> { #[derive(Debug)] pub struct Context<'r, 's> { global_settings: &'s GlobalSettings<'s>, - tree: &'r List<'r, ContextElement<'r, 's>>, + tree: List<'r, &'r ContextElement<'r, 's>>, } impl<'r, 's> Context<'r, 's> { pub fn new( global_settings: &'s GlobalSettings<'s>, - tree: &'r List<'r, ContextElement<'r, 's>>, + tree: List<'r, &'r ContextElement<'r, 's>>, ) -> Self { Self { global_settings, @@ -148,36 +147,33 @@ impl<'r, 's> Context<'r, 's> { } } - pub fn with_additional_node(&self, data: ContextElement<'r, 's>) -> Self { - let new_tree = self.tree.push(data); - Self { - global_settings: self.global_settings, - tree: new_tree, - } + pub fn with_additional_node(&'r self, new_element: &'r ContextElement<'r, 's>) -> Self { + let new_tree = self.tree.push(new_element); + Self::new(self.global_settings, new_tree) } - pub fn iter(&self) -> super::list::Iter<'r, ContextElement<'r, 's>> { + pub fn iter(&'r self) -> super::list::Iter<'r, &'r ContextElement<'r, 's>> { self.tree.iter() } - pub fn iter_context(&self) -> Iter<'r, 's> { + pub fn iter_context(&'r self) -> Iter<'r, 's> { Iter { next: self.tree.iter_list(), global_settings: self.global_settings, } } - pub fn get_parent(&self) -> Option { + pub fn get_parent(&'r self) -> Option { self.tree.get_parent().map(|parent_tree| Self { global_settings: self.global_settings, - tree: parent_tree, + tree: parent_tree.clone(), }) } } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn document_end<'r, 's>( - _context: RefContext<'r, 's>, +fn document_end<'b, 'r, 's>( + _context: RefContext<'b, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { eof(input) @@ -185,7 +181,7 @@ fn document_end<'r, 's>( pub struct Iter<'r, 's> { global_settings: &'s GlobalSettings<'s>, - next: super::list::IterList<'r, ContextElement<'r, 's>>, + next: super::list::IterList<'r, &'r ContextElement<'r, 's>>, } impl<'r, 's> Iterator for Iter<'r, 's> { @@ -193,7 +189,8 @@ impl<'r, 's> Iterator for Iter<'r, 's> { fn next(&mut self) -> Option { let next_tree = self.next.next(); - let ret = next_tree.map(|parent_tree| Context::new(self.global_settings, parent_tree)); + let ret = + next_tree.map(|parent_tree| Context::new(self.global_settings, parent_tree.clone())); ret } } From 74a6101de7020467ccdc8ab1e6c5ac1a70438fcf Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 2 Sep 2023 22:45:46 -0400 Subject: [PATCH 12/24] Update RefContext to three lifetimes. --- src/parser/angle_link.rs | 6 ++-- src/parser/citation.rs | 10 +++---- src/parser/citation_reference.rs | 12 ++++---- src/parser/clock.rs | 6 ++-- src/parser/comment.rs | 4 +-- src/parser/diary_sexp.rs | 2 +- src/parser/document.rs | 14 ++++----- src/parser/drawer.rs | 4 +-- src/parser/dynamic_block.rs | 4 +-- src/parser/element_parser.rs | 4 +-- src/parser/entity.rs | 4 +-- src/parser/export_snippet.rs | 8 ++--- src/parser/fixed_width_area.rs | 4 +-- src/parser/footnote_definition.rs | 4 +-- src/parser/footnote_reference.rs | 10 +++---- src/parser/greater_block.rs | 4 +-- src/parser/horizontal_rule.rs | 2 +- src/parser/inline_babel_call.rs | 14 ++++----- src/parser/inline_source_block.rs | 14 ++++----- src/parser/keyword.rs | 4 +-- src/parser/latex_environment.rs | 6 ++-- src/parser/latex_fragment.rs | 26 ++++++++-------- src/parser/lesser_block.rs | 14 ++++----- src/parser/line_break.rs | 4 +-- src/parser/object_parser.rs | 10 +++---- src/parser/org_macro.rs | 8 ++--- src/parser/paragraph.rs | 4 +-- src/parser/plain_link.rs | 12 ++++---- src/parser/plain_list.rs | 16 +++++----- src/parser/plain_text.rs | 6 ++-- src/parser/planning.rs | 2 +- src/parser/property_drawer.rs | 10 +++---- src/parser/radio_link.rs | 10 +++---- src/parser/regular_link.rs | 12 ++++---- src/parser/statistics_cookie.rs | 6 ++-- src/parser/subscript_and_superscript.rs | 20 ++++++------- src/parser/table.rs | 14 ++++----- src/parser/target.rs | 4 +-- src/parser/text_markup.rs | 28 ++++++++--------- src/parser/timestamp.rs | 40 ++++++++++++------------- src/parser/util.rs | 14 ++++----- 41 files changed, 200 insertions(+), 200 deletions(-) diff --git a/src/parser/angle_link.rs b/src/parser/angle_link.rs index 519fa03..da25d49 100644 --- a/src/parser/angle_link.rs +++ b/src/parser/angle_link.rs @@ -14,7 +14,7 @@ use crate::parser::AngleLink; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn angle_link<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, AngleLink<'s>> { let (remaining, _) = tag("<")(input)?; @@ -37,7 +37,7 @@ pub fn angle_link<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn path_angle<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = @@ -54,7 +54,7 @@ fn path_angle<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn path_angle_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { tag(">")(input) diff --git a/src/parser/citation.rs b/src/parser/citation.rs index 3919e7a..babbae8 100644 --- a/src/parser/citation.rs +++ b/src/parser/citation.rs @@ -26,7 +26,7 @@ use crate::parser::Object; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn citation<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Citation<'s>> { // TODO: Despite being a standard object, citations cannot exist inside the global prefix/suffix for other citations because citations must contain something that matches @key which is forbidden inside the global prefix/suffix. This TODO is to evaluate if its worth putting in an explicit check for this (which can be easily accomplished by checking the output of `get_bracket_depth()`). I suspect its not worth it because I expect, outside of intentionally crafted inputs, this parser will exit immediately inside a citation since it is unlikely to find the "[cite" substring inside a citation global prefix/suffix. @@ -78,7 +78,7 @@ fn variant<'r, 's>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn global_prefix<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = global_prefix_end(input.get_bracket_depth()); @@ -108,7 +108,7 @@ fn global_prefix_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _global_prefix_end<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { @@ -131,7 +131,7 @@ fn _global_prefix_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn global_suffix<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = global_suffix_end(input.get_bracket_depth()); @@ -160,7 +160,7 @@ fn global_suffix_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _global_suffix_end<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/citation_reference.rs b/src/parser/citation_reference.rs index bd4e832..8b3c5b1 100644 --- a/src/parser/citation_reference.rs +++ b/src/parser/citation_reference.rs @@ -24,7 +24,7 @@ use crate::parser::Object; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn citation_reference<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, CitationReference<'s>> { let (remaining, _prefix) = @@ -44,7 +44,7 @@ pub fn citation_reference<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn citation_reference_key<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, source) = recognize(tuple(( @@ -64,7 +64,7 @@ pub fn citation_reference_key<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn key_prefix<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = key_prefix_end(input.get_bracket_depth()); @@ -85,7 +85,7 @@ fn key_prefix<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn key_suffix<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = key_suffix_end(input.get_bracket_depth()); @@ -114,7 +114,7 @@ fn key_prefix_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _key_prefix_end<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { @@ -145,7 +145,7 @@ fn key_suffix_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _key_suffix_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/clock.rs b/src/parser/clock.rs index 759f54f..31af225 100644 --- a/src/parser/clock.rs +++ b/src/parser/clock.rs @@ -19,7 +19,7 @@ use crate::parser::Clock; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn clock<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Clock<'s>> { start_of_line(input)?; @@ -43,7 +43,7 @@ pub fn clock<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inactive_timestamp_range_duration<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( @@ -65,7 +65,7 @@ fn inactive_timestamp_range_duration<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inactive_timestamp<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( diff --git a/src/parser/comment.rs b/src/parser/comment.rs index a2e74d6..931ab97 100644 --- a/src/parser/comment.rs +++ b/src/parser/comment.rs @@ -23,7 +23,7 @@ use crate::parser::Comment; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn comment<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Comment<'s>> { if immediate_in_section(context, "comment") { @@ -49,7 +49,7 @@ pub fn comment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn comment_line<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; diff --git a/src/parser/diary_sexp.rs b/src/parser/diary_sexp.rs index 67fbc5f..9fb724e 100644 --- a/src/parser/diary_sexp.rs +++ b/src/parser/diary_sexp.rs @@ -18,7 +18,7 @@ use crate::parser::DiarySexp; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn diary_sexp<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, DiarySexp<'s>> { start_of_line(input)?; diff --git a/src/parser/document.rs b/src/parser/document.rs index d5b6c1f..68db3da 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -71,7 +71,7 @@ pub fn document(input: &str) -> Res<&str, Document> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _document<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Document<'s>> { let zeroth_section_matcher = parser_with_context!(zeroth_section)(context); @@ -92,7 +92,7 @@ fn _document<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn zeroth_section<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Section<'s>> { // TODO: The zeroth section is specialized so it probably needs its own parser @@ -146,7 +146,7 @@ fn zeroth_section<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn section<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, mut input: OrgSource<'s>, ) -> Res, Section<'s>> { // TODO: The zeroth section is specialized so it probably needs its own parser @@ -196,7 +196,7 @@ fn section<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn section_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(detect_headline)(input) @@ -210,7 +210,7 @@ const fn heading( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _heading<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, parent_stars: usize, ) -> Res, Heading<'s>> { @@ -257,7 +257,7 @@ fn detect_headline<'s>(input: OrgSource<'s>) -> Res, ()> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn headline<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, parent_stars: usize, ) -> Res< @@ -312,7 +312,7 @@ fn headline<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn headline_title_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index c5b7646..f794a3f 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -27,7 +27,7 @@ use crate::parser::Paragraph; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn drawer<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Drawer<'s>> { if immediate_in_section(context, "drawer") { @@ -93,7 +93,7 @@ fn name<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn drawer_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; diff --git a/src/parser/dynamic_block.rs b/src/parser/dynamic_block.rs index c9ecc57..7625fde 100644 --- a/src/parser/dynamic_block.rs +++ b/src/parser/dynamic_block.rs @@ -27,7 +27,7 @@ use crate::parser::Element; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn dynamic_block<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, DynamicBlock<'s>> { // TODO: Do I need to differentiate between different dynamic block types. @@ -101,7 +101,7 @@ fn parameters<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn dynamic_block_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index 8d40274..18ec00b 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -39,7 +39,7 @@ pub const fn element( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _element<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, can_be_paragraph: bool, ) -> Res, Element<'s>> { @@ -121,7 +121,7 @@ pub const fn detect_element( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _detect_element<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, can_be_paragraph: bool, ) -> Res, ()> { diff --git a/src/parser/entity.rs b/src/parser/entity.rs index b9420d1..dd29793 100644 --- a/src/parser/entity.rs +++ b/src/parser/entity.rs @@ -433,7 +433,7 @@ const ORG_ENTITIES: [&'static str; 413] = [ #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn entity<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Entity<'s>> { let (remaining, _) = tag("\\")(input)?; @@ -454,7 +454,7 @@ pub fn entity<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn name<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // TODO: This should be defined by org-entities and optionally org-entities-user diff --git a/src/parser/export_snippet.rs b/src/parser/export_snippet.rs index 839a1aa..a294ab7 100644 --- a/src/parser/export_snippet.rs +++ b/src/parser/export_snippet.rs @@ -16,7 +16,7 @@ use crate::parser::ExportSnippet; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn export_snippet<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, ExportSnippet<'s>> { let (remaining, _) = tag("@@")(input)?; @@ -46,7 +46,7 @@ pub fn export_snippet<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn backend<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, backend_name) = @@ -57,7 +57,7 @@ fn backend<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn contents<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, source) = recognize(verify( @@ -69,7 +69,7 @@ fn contents<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn export_snippet_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { tag("@@")(input) diff --git a/src/parser/fixed_width_area.rs b/src/parser/fixed_width_area.rs index 4d29795..6a44d5b 100644 --- a/src/parser/fixed_width_area.rs +++ b/src/parser/fixed_width_area.rs @@ -20,7 +20,7 @@ use crate::parser::FixedWidthArea; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn fixed_width_area<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, FixedWidthArea<'s>> { let fixed_width_area_line_matcher = parser_with_context!(fixed_width_area_line)(context); @@ -40,7 +40,7 @@ pub fn fixed_width_area<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn fixed_width_area_line<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 24eff27..0bd1089 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -26,7 +26,7 @@ use crate::parser::util::start_of_line; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn footnote_definition<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteDefinition<'s>> { if immediate_in_section(context, "footnote definition") { @@ -72,7 +72,7 @@ pub fn label<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn footnote_definition_end<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, source) = alt(( diff --git a/src/parser/footnote_reference.rs b/src/parser/footnote_reference.rs index 27c2a2c..20462c3 100644 --- a/src/parser/footnote_reference.rs +++ b/src/parser/footnote_reference.rs @@ -18,7 +18,7 @@ use crate::parser::FootnoteReference; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn footnote_reference<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteReference<'s>> { alt(( @@ -30,7 +30,7 @@ pub fn footnote_reference<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn anonymous_footnote<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteReference<'s>> { let (remaining, _) = tag_no_case("[fn::")(input)?; @@ -64,7 +64,7 @@ fn anonymous_footnote<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inline_footnote<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteReference<'s>> { let (remaining, _) = tag_no_case("[fn:")(input)?; @@ -100,7 +100,7 @@ fn inline_footnote<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn footnote_reference_only<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteReference<'s>> { let (remaining, _) = tag_no_case("[fn:")(input)?; @@ -129,7 +129,7 @@ fn footnote_definition_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _footnote_definition_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 4cc6113..22a5018 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -27,7 +27,7 @@ use crate::parser::Paragraph; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn greater_block<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, GreaterBlock<'s>> { // TODO: Do I need to differentiate between different greater block types. @@ -124,7 +124,7 @@ fn greater_block_end<'x>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _greater_block_end<'r, 's, 'x>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, name: &'x str, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/horizontal_rule.rs b/src/parser/horizontal_rule.rs index f5ed6ca..1429a91 100644 --- a/src/parser/horizontal_rule.rs +++ b/src/parser/horizontal_rule.rs @@ -15,7 +15,7 @@ use crate::parser::HorizontalRule; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn horizontal_rule<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, HorizontalRule<'s>> { start_of_line(input)?; diff --git a/src/parser/inline_babel_call.rs b/src/parser/inline_babel_call.rs index 5300bf4..e059f50 100644 --- a/src/parser/inline_babel_call.rs +++ b/src/parser/inline_babel_call.rs @@ -21,7 +21,7 @@ use crate::parser::InlineBabelCall; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn inline_babel_call<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, InlineBabelCall<'s>> { let (remaining, _) = tag_no_case("call_")(input)?; @@ -42,7 +42,7 @@ pub fn inline_babel_call<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn name<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = @@ -59,7 +59,7 @@ fn name<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn name_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(one_of("[("))(input) @@ -67,7 +67,7 @@ fn name_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn header<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("[")(input)?; @@ -97,7 +97,7 @@ fn header_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _header_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { @@ -117,7 +117,7 @@ fn _header_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn argument<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("(")(input)?; @@ -147,7 +147,7 @@ fn argument_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _argument_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, starting_parenthesis_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/inline_source_block.rs b/src/parser/inline_source_block.rs index 941dc87..132163f 100644 --- a/src/parser/inline_source_block.rs +++ b/src/parser/inline_source_block.rs @@ -23,7 +23,7 @@ use crate::parser::InlineSourceBlock; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn inline_source_block<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, InlineSourceBlock<'s>> { let (remaining, _) = tag_no_case("src_")(input)?; @@ -43,7 +43,7 @@ pub fn inline_source_block<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn lang<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = @@ -60,7 +60,7 @@ fn lang<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn lang_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(one_of("[{"))(input) @@ -68,7 +68,7 @@ fn lang_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn header<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("[")(input)?; @@ -98,7 +98,7 @@ fn header_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _header_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { @@ -118,7 +118,7 @@ fn _header_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn body<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("{")(input)?; @@ -156,7 +156,7 @@ fn body_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _body_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, starting_brace_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index 99053d9..a3be43a 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -30,7 +30,7 @@ const ORG_ELEMENT_DUAL_KEYWORDS: [&'static str; 2] = ["caption", "results"]; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn keyword<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Keyword<'s>> { start_of_line(input)?; @@ -55,7 +55,7 @@ pub fn keyword<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn affiliated_keyword<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Keyword<'s>> { start_of_line(input)?; diff --git a/src/parser/latex_environment.rs b/src/parser/latex_environment.rs index 4a71ef6..7a9320f 100644 --- a/src/parser/latex_environment.rs +++ b/src/parser/latex_environment.rs @@ -20,7 +20,7 @@ use crate::parser::LatexEnvironment; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn latex_environment<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, LatexEnvironment<'s>> { start_of_line(input)?; @@ -67,7 +67,7 @@ pub fn contents< F: Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>, >( end_matcher: F, - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, source) = recognize(many_till( @@ -92,7 +92,7 @@ fn latex_environment_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _latex_environment_end<'r, 's, 'x>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, current_name_lower: &'x str, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/latex_fragment.rs b/src/parser/latex_fragment.rs index a4b54f9..077c0c1 100644 --- a/src/parser/latex_fragment.rs +++ b/src/parser/latex_fragment.rs @@ -23,7 +23,7 @@ use crate::parser::LatexFragment; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn latex_fragment<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, LatexFragment<'s>> { let (remaining, _) = alt(( @@ -47,7 +47,7 @@ pub fn latex_fragment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn raw_latex_fragment<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("\\")(input)?; @@ -60,7 +60,7 @@ fn raw_latex_fragment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn name<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alpha1(input) @@ -68,7 +68,7 @@ fn name<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn brackets<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, body) = alt(( @@ -100,7 +100,7 @@ fn brackets<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn escaped_parenthesis_fragment<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("\\(")(input)?; @@ -119,7 +119,7 @@ fn escaped_parenthesis_fragment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn escaped_bracket_fragment<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("\\[")(input)?; @@ -138,7 +138,7 @@ fn escaped_bracket_fragment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn double_dollar_fragment<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // TODO: The documentation on the dollar sign versions is incomplete. Test to figure out what the real requirements are. For example, can this span more than 3 lines and can this contain a single $ since its terminated by $$? @@ -158,7 +158,7 @@ fn double_dollar_fragment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn dollar_char_fragment<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (_, _) = pre(context, input)?; @@ -172,7 +172,7 @@ fn dollar_char_fragment<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn pre<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +pub fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { let preceding_character = input.get_preceding_character(); if let Some('$') = preceding_character { return Err(nom::Err::Error(CustomError::MyError(MyError( @@ -183,7 +183,7 @@ pub fn pre<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +pub fn post<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { // TODO: What about eof? Test to find out. // TODO: Figure out which punctuation characters should be included. @@ -193,7 +193,7 @@ pub fn post<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (_, _) = pre(context, input)?; @@ -219,7 +219,7 @@ fn bordered_dollar_fragment<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn open_border<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(verify(none_of(".,;$"), |c| !c.is_whitespace()))(input) @@ -227,7 +227,7 @@ pub fn open_border<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn close_border<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> { let preceding_character = input.get_preceding_character(); diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index eb241cc..8a78b6a 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -29,7 +29,7 @@ use crate::parser::util::text_until_exit; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn verse_block<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, VerseBlock<'s>> { let (remaining, name) = lesser_block_begin("verse")(context, input)?; @@ -80,7 +80,7 @@ pub fn verse_block<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn comment_block<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, CommentBlock<'s>> { let (remaining, name) = lesser_block_begin("comment")(context, input)?; @@ -116,7 +116,7 @@ pub fn comment_block<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn example_block<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, ExampleBlock<'s>> { let (remaining, _name) = lesser_block_begin("example")(context, input)?; @@ -152,7 +152,7 @@ pub fn example_block<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn export_block<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, ExportBlock<'s>> { let (remaining, name) = lesser_block_begin("export")(context, input)?; @@ -189,7 +189,7 @@ pub fn export_block<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn src_block<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, SrcBlock<'s>> { let (remaining, name) = lesser_block_begin("src")(context, input)?; @@ -245,7 +245,7 @@ fn lesser_block_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _lesser_block_end<'r, 's, 'x>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, current_name_lower: &'x str, ) -> Res, OrgSource<'s>> { @@ -272,7 +272,7 @@ const fn lesser_block_begin( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _lesser_block_begin<'r, 's, 'x>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, current_name_lower: &'x str, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/line_break.rs b/src/parser/line_break.rs index 33a68a7..8f2cb27 100644 --- a/src/parser/line_break.rs +++ b/src/parser/line_break.rs @@ -13,7 +13,7 @@ use crate::parser::LineBreak; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn line_break<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, LineBreak<'s>> { let (remaining, _) = pre(context, input)?; @@ -30,7 +30,7 @@ pub fn line_break<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn pre<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { let preceding_character = input.get_preceding_character(); match preceding_character { // If None, we are at the start of the file diff --git a/src/parser/object_parser.rs b/src/parser/object_parser.rs index b314af1..084d526 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -29,7 +29,7 @@ use crate::parser::timestamp::timestamp; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn standard_set_object<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, object) = alt(( @@ -87,7 +87,7 @@ pub fn standard_set_object<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn minimal_set_object<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, object) = alt(( @@ -109,7 +109,7 @@ pub fn minimal_set_object<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn any_object_except_plain_text<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, object) = alt(( @@ -166,7 +166,7 @@ pub fn any_object_except_plain_text<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn regular_link_description_object_set<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { // TODO: It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]] @@ -195,7 +195,7 @@ pub fn regular_link_description_object_set<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn table_cell_set_object<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, object) = alt(( diff --git a/src/parser/org_macro.rs b/src/parser/org_macro.rs index 70e8447..71f2dd6 100644 --- a/src/parser/org_macro.rs +++ b/src/parser/org_macro.rs @@ -18,7 +18,7 @@ use crate::parser::util::get_consumed; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn org_macro<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgMacro<'s>> { let (remaining, _) = tag("{{{")(input)?; @@ -45,7 +45,7 @@ pub fn org_macro<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn org_macro_name<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = verify(anychar, |c| c.is_alphabetic())(input)?; @@ -58,7 +58,7 @@ fn org_macro_name<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn org_macro_args<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let (remaining, _) = tag("(")(input)?; @@ -71,7 +71,7 @@ fn org_macro_args<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn org_macro_arg<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let mut remaining = input; diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index 59f4bb5..c275f6d 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -19,7 +19,7 @@ use crate::parser::util::start_of_line; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn paragraph<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Paragraph<'s>> { let parser_context = @@ -50,7 +50,7 @@ pub fn paragraph<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn paragraph_end<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let non_paragraph_element_matcher = parser_with_context!(detect_element(false))(context); diff --git a/src/parser/plain_link.rs b/src/parser/plain_link.rs index bf7880a..1cf2b36 100644 --- a/src/parser/plain_link.rs +++ b/src/parser/plain_link.rs @@ -49,7 +49,7 @@ const ORG_LINK_PARAMETERS: [&'static str; 23] = [ #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn plain_link<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, PlainLink<'s>> { let (remaining, _) = pre(context, input)?; @@ -69,7 +69,7 @@ pub fn plain_link<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn pre<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { let preceding_character = input.get_preceding_character(); match preceding_character { // If None, we are at the start of the file which is fine @@ -86,14 +86,14 @@ fn pre<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +fn post<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { let (remaining, _) = alt((eof, recognize(none_of(WORD_CONSTITUENT_CHARACTERS))))(input)?; Ok((remaining, ())) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn protocol<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // TODO: This should be defined by org-link-parameters @@ -114,7 +114,7 @@ pub fn protocol<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn path_plain<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // TODO: "optionally containing parenthesis-wrapped non-whitespace non-bracket substrings up to a depth of two. The string must end with either a non-punctation non-whitespace character, a forwards slash, or a parenthesis-wrapped substring" @@ -136,7 +136,7 @@ fn path_plain<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn path_plain_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(many_till( diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 929d273..0007853 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -56,7 +56,7 @@ pub fn detect_plain_list<'s>(input: OrgSource<'s>) -> Res, ()> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn plain_list<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, PlainList<'s>> { let parser_context = context @@ -125,7 +125,7 @@ pub fn plain_list<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn plain_list_item<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, PlainListItem<'s>> { start_of_line(input)?; @@ -236,7 +236,7 @@ fn counter<'s>(i: OrgSource<'s>) -> Res, OrgSource<'s>> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn plain_list_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( @@ -261,7 +261,7 @@ const fn plain_list_item_end( tracing::instrument(ret, level = "debug", skip(line_indented_lte_matcher)) )] fn _plain_list_item_end<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, line_indented_lte_matcher: impl for<'rr, 'ss> Fn( Context<'rr, 'ss>, @@ -283,7 +283,7 @@ const fn line_indented_lte( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _line_indented_lte<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, indent_level: usize, ) -> Res, OrgSource<'s>> { @@ -298,7 +298,7 @@ fn _line_indented_lte<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn item_tag<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let parser_context = @@ -319,7 +319,7 @@ fn item_tag<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn item_tag_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(alt(( @@ -331,7 +331,7 @@ fn item_tag_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn item_tag_post_gap<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { verify( diff --git a/src/parser/plain_text.rs b/src/parser/plain_text.rs index 916f0fa..96f9c02 100644 --- a/src/parser/plain_text.rs +++ b/src/parser/plain_text.rs @@ -16,7 +16,7 @@ use crate::error::Res; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn plain_text<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, PlainText<'s>> { let (remaining, source) = recognize(verify( @@ -40,7 +40,7 @@ pub fn plain_text<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn plain_text_end<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(parser_with_context!(any_object_except_plain_text)(context))(input) @@ -50,7 +50,7 @@ impl<'x> RematchObject<'x> for PlainText<'x> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn rematch_object<'r, 's>( &'x self, - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { map(tag(self.source), |s| { diff --git a/src/parser/planning.rs b/src/parser/planning.rs index 8d1ae8c..e2e76e1 100644 --- a/src/parser/planning.rs +++ b/src/parser/planning.rs @@ -18,7 +18,7 @@ use crate::parser::util::start_of_line; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn planning<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Planning<'s>> { start_of_line(input)?; diff --git a/src/parser/property_drawer.rs b/src/parser/property_drawer.rs index b5affb7..f9b380e 100644 --- a/src/parser/property_drawer.rs +++ b/src/parser/property_drawer.rs @@ -27,7 +27,7 @@ use crate::parser::util::start_of_line; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn property_drawer<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, PropertyDrawer<'s>> { if immediate_in_section(context, "property-drawer") { @@ -75,7 +75,7 @@ pub fn property_drawer<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn property_drawer_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( @@ -89,7 +89,7 @@ fn property_drawer_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn node_property<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, NodeProperty<'s>> { let (remaining, (_start_of_line, _leading_whitespace, _open_colon, _name, _close_colon)) = @@ -132,7 +132,7 @@ fn node_property<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn node_property_name<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = @@ -157,7 +157,7 @@ fn node_property_name<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn node_property_name_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt((tag("+:"), tag(":")))(input) diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index de78303..5a3a64e 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -18,7 +18,7 @@ use crate::parser::RadioTarget; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn radio_link<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, RadioLink<'s>> { let radio_targets = context @@ -49,7 +49,7 @@ pub fn radio_link<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn rematch_target<'x, 'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, target: &'x Vec>, input: OrgSource<'s>, ) -> Res, Vec>> { @@ -80,7 +80,7 @@ pub fn rematch_target<'x, 'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn radio_target<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, RadioTarget<'s>> { let (remaining, _opening) = tag("<<<")(input)?; @@ -113,7 +113,7 @@ pub fn radio_target<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn radio_target_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt((tag("<"), tag(">"), line_ending))(input) @@ -122,7 +122,7 @@ fn radio_target_end<'r, 's>( pub trait RematchObject<'x> { fn rematch_object<'r, 's>( &'x self, - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>>; } diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index b64ebf3..cf751bb 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -16,7 +16,7 @@ use crate::error::Res; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn regular_link<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, RegularLink<'s>> { alt(( @@ -27,7 +27,7 @@ pub fn regular_link<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn regular_link_without_description<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, RegularLink<'s>> { let (remaining, _opening_bracket) = tag("[[")(input)?; @@ -46,7 +46,7 @@ pub fn regular_link_without_description<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn regular_link_with_description<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, RegularLink<'s>> { let (remaining, _opening_bracket) = tag("[[")(input)?; @@ -67,7 +67,7 @@ pub fn regular_link_with_description<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn pathreg<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, path) = escaped( @@ -83,7 +83,7 @@ pub fn pathreg<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn description<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let parser_context = @@ -104,7 +104,7 @@ pub fn description<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn description_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { tag("]]")(input) diff --git a/src/parser/statistics_cookie.rs b/src/parser/statistics_cookie.rs index 180dd49..3fd2287 100644 --- a/src/parser/statistics_cookie.rs +++ b/src/parser/statistics_cookie.rs @@ -11,7 +11,7 @@ use crate::parser::StatisticsCookie; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn statistics_cookie<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, StatisticsCookie<'s>> { alt(( @@ -22,7 +22,7 @@ pub fn statistics_cookie<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn percent_statistics_cookie<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, StatisticsCookie<'s>> { let (remaining, source) = @@ -39,7 +39,7 @@ pub fn percent_statistics_cookie<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn fraction_statistics_cookie<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, StatisticsCookie<'s>> { let (remaining, source) = recognize(tuple(( diff --git a/src/parser/subscript_and_superscript.rs b/src/parser/subscript_and_superscript.rs index e5233f8..8463a40 100644 --- a/src/parser/subscript_and_superscript.rs +++ b/src/parser/subscript_and_superscript.rs @@ -24,7 +24,7 @@ use crate::parser::Superscript; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn subscript<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Subscript<'s>> { // We check for the underscore first before checking the pre-character as a minor optimization to avoid walking up the context tree to find the document root unnecessarily. @@ -44,7 +44,7 @@ pub fn subscript<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn superscript<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Superscript<'s>> { // We check for the circumflex first before checking the pre-character as a minor optimization to avoid walking up the context tree to find the document root unnecessarily. @@ -63,7 +63,7 @@ pub fn superscript<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn pre<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { let preceding_character = input.get_preceding_character(); match preceding_character { Some(c) if !c.is_whitespace() => {} @@ -84,7 +84,7 @@ enum ScriptBody<'s> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn script_body<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, ScriptBody<'s>> { alt(( @@ -102,7 +102,7 @@ fn script_body<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn script_asterisk<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { tag("*")(input) @@ -110,7 +110,7 @@ fn script_asterisk<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn script_alphanum<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _sign) = opt(recognize(one_of("+-")))(input)?; @@ -124,7 +124,7 @@ fn script_alphanum<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn script_alphanum_character<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(verify(anychar, |c| { @@ -134,7 +134,7 @@ fn script_alphanum_character<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn end_script_alphanum_character<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, final_char) = recognize(verify(anychar, |c| c.is_alphanumeric()))(input)?; @@ -146,7 +146,7 @@ fn end_script_alphanum_character<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn script_with_braces<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let (remaining, _) = tag("{")(input)?; @@ -176,7 +176,7 @@ fn script_with_braces_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _script_with_braces_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, starting_brace_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/table.rs b/src/parser/table.rs index 121f421..eeb3c1a 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -26,7 +26,7 @@ use crate::parser::Table; /// This is not the table.el style. #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn org_mode_table<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Table<'s>> { start_of_line(input)?; @@ -60,7 +60,7 @@ pub fn org_mode_table<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn table_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; @@ -69,7 +69,7 @@ fn table_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn org_mode_table_row<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, TableRow<'s>> { alt(( @@ -80,7 +80,7 @@ pub fn org_mode_table_row<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn org_mode_table_row_rule<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, TableRow<'s>> { start_of_line(input)?; @@ -97,7 +97,7 @@ pub fn org_mode_table_row_rule<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn org_mode_table_row_regular<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, TableRow<'s>> { start_of_line(input)?; @@ -117,7 +117,7 @@ pub fn org_mode_table_row_regular<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn org_mode_table_cell<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, TableCell<'s>> { let parser_context = @@ -150,7 +150,7 @@ pub fn org_mode_table_cell<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn org_mode_table_cell_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple((space0, alt((tag("|"), peek(line_ending))))))(input) diff --git a/src/parser/target.rs b/src/parser/target.rs index ddbc1f5..ebb53b7 100644 --- a/src/parser/target.rs +++ b/src/parser/target.rs @@ -17,7 +17,7 @@ use crate::parser::Target; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn target<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Target<'s>> { let (remaining, _) = tag("<<")(input)?; @@ -58,7 +58,7 @@ pub fn target<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn target_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(one_of("<>\n"))(input) diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index d80b4fd..117b9d3 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -36,7 +36,7 @@ use crate::parser::Verbatim; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn text_markup<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { alt(( @@ -54,7 +54,7 @@ pub fn text_markup<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn bold<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Bold<'s>> { let text_markup_object_specialized = text_markup_object("*"); @@ -71,7 +71,7 @@ pub fn bold<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn italic<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Italic<'s>> { let text_markup_object_specialized = text_markup_object("/"); @@ -88,7 +88,7 @@ pub fn italic<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn underline<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Underline<'s>> { let text_markup_object_specialized = text_markup_object("_"); @@ -105,7 +105,7 @@ pub fn underline<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn strike_through<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, StrikeThrough<'s>> { let text_markup_object_specialized = text_markup_object("+"); @@ -122,7 +122,7 @@ pub fn strike_through<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn verbatim<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Verbatim<'s>> { let text_markup_string_specialized = text_markup_string("="); @@ -139,7 +139,7 @@ pub fn verbatim<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn code<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Code<'s>> { let text_markup_string_specialized = text_markup_string("~"); @@ -165,7 +165,7 @@ fn text_markup_object( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _text_markup_object<'r, 's, 'x>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, marker_symbol: &'x str, ) -> Res, Vec>> { @@ -216,7 +216,7 @@ fn text_markup_string( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _text_markup_string<'r, 's, 'x>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, marker_symbol: &'x str, ) -> Res, OrgSource<'s>> { @@ -257,7 +257,7 @@ fn _text_markup_string<'r, 's, 'x>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn pre<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +pub fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { let preceding_character = input.get_preceding_character(); match preceding_character { // If None, we are at the start of the file which is technically the beginning of a line. @@ -274,7 +274,7 @@ pub fn pre<'r, 's>(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res(_context: RefContext<'r, 's>, input: OrgSource<'s>) -> Res, ()> { +pub fn post<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { let (remaining, _) = alt((recognize(one_of(" \r\n\t-.,;:!?')}[\"")), line_ending))(input)?; Ok((remaining, ())) } @@ -290,7 +290,7 @@ fn text_markup_end( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _text_markup_end<'r, 's, 'x>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, marker_symbol: &'x str, ) -> Res, OrgSource<'s>> { @@ -307,7 +307,7 @@ impl<'x> RematchObject<'x> for Bold<'x> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn rematch_object<'r, 's>( &'x self, - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, children) = @@ -325,7 +325,7 @@ impl<'x> RematchObject<'x> for Bold<'x> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn _rematch_text_markup_object<'r, 's, 'x>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, marker_symbol: &'static str, original_match_children: &'x Vec>, diff --git a/src/parser/timestamp.rs b/src/parser/timestamp.rs index fa1e408..d80df95 100644 --- a/src/parser/timestamp.rs +++ b/src/parser/timestamp.rs @@ -24,7 +24,7 @@ use crate::types::Timestamp; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn timestamp<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { // TODO: This would be more efficient if we didn't throw away the parse result of the first half of an active/inactive date range timestamp if the parse fails (as in, the first thing active_date_range_timestamp parses is a active_timestamp but then we throw that away if it doesn't turn out to be a full active_date_range_timestamp despite the active_timestamp parse being completely valid). I am going with the simplest/cleanest approach for the first implementation. @@ -42,7 +42,7 @@ pub fn timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn diary_timestamp<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("<%%(")(input)?; @@ -62,7 +62,7 @@ fn diary_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn sexp<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = @@ -84,7 +84,7 @@ fn sexp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn sexp_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt((tag(")>"), recognize(one_of(">\n"))))(input) @@ -92,7 +92,7 @@ fn sexp_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn active_timestamp<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("<")(input)?; @@ -126,7 +126,7 @@ fn active_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inactive_timestamp<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("[")(input)?; @@ -160,7 +160,7 @@ fn inactive_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn active_date_range_timestamp<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _first_timestamp) = active_timestamp(context, input)?; @@ -182,7 +182,7 @@ fn active_date_range_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn active_time_range_timestamp<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("<")(input)?; @@ -223,7 +223,7 @@ fn active_time_range_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inactive_date_range_timestamp<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _first_timestamp) = inactive_timestamp(context, input)?; @@ -245,7 +245,7 @@ fn inactive_date_range_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inactive_time_range_timestamp<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("[")(input)?; @@ -286,7 +286,7 @@ fn inactive_time_range_timestamp<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn date<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _year) = verify(digit1, |year: &OrgSource<'_>| year.len() == 4)(input)?; @@ -304,7 +304,7 @@ fn date<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn dayname<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = @@ -326,7 +326,7 @@ fn dayname<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn dayname_end<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(verify(anychar, |c| { @@ -336,7 +336,7 @@ fn dayname_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn time<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _hour) = verify(digit1, |hour: &OrgSource<'_>| { @@ -352,7 +352,7 @@ fn time<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn time_rest<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, body) = recognize(verify( @@ -365,7 +365,7 @@ fn time_rest<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn active_time_rest_end<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt(( @@ -380,7 +380,7 @@ fn active_time_rest_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inactive_time_rest_end<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt(( @@ -395,7 +395,7 @@ fn inactive_time_rest_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn time_range_rest_end<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // We pop off the most recent context element to get a context tree with just the active/inactive_time_rest_end exit matcher (removing this function from the exit matcher chain) because the 2nd time in the range does not end when a "-TIME" pattern is found. @@ -407,7 +407,7 @@ fn time_range_rest_end<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn repeater<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // + for cumulative type @@ -423,7 +423,7 @@ fn repeater<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn warning_delay<'r, 's>( - _context: RefContext<'r, 's>, + _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // - for all type diff --git a/src/parser/util.rs b/src/parser/util.rs index 92a35ec..41539ca 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -26,7 +26,7 @@ pub const WORD_CONSTITUENT_CHARACTERS: &str = /// Check if we are below a section of the given section type regardless of depth #[allow(dead_code)] -pub fn in_section<'r, 's, 'x>(context: RefContext<'r, 's>, section_name: &'x str) -> bool { +pub fn in_section<'r, 's, 'x>(context: RefContext<'_, 'r, 's>, section_name: &'x str) -> bool { for thing in context.iter() { match thing.get_data() { ContextElement::Context(name) if *name == section_name => return true, @@ -38,7 +38,7 @@ pub fn in_section<'r, 's, 'x>(context: RefContext<'r, 's>, section_name: &'x str /// Checks if we are currently an immediate child of the given section type pub fn immediate_in_section<'r, 's, 'x>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, section_name: &'x str, ) -> bool { for thing in context.iter() { @@ -73,7 +73,7 @@ pub fn element_trailing_whitespace<'s>(input: OrgSource<'s>) -> Res( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Option>> { if exit_matcher_parser(context, input).is_err() { @@ -85,7 +85,7 @@ pub fn maybe_consume_object_trailing_whitespace_if_not_exiting<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn maybe_consume_trailing_whitespace_if_not_exiting<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Option>> { if context.should_consume_trailing_whitespace() && exit_matcher_parser(context, input).is_err() @@ -98,7 +98,7 @@ pub fn maybe_consume_trailing_whitespace_if_not_exiting<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn maybe_consume_trailing_whitespace<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Option>> { if context.should_consume_trailing_whitespace() { @@ -147,7 +147,7 @@ pub fn non_whitespace_character(input: OrgSource<'_>) -> Res, char /// Check that we are at the start of a line #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn exit_matcher_parser<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { peek(|i| context.check_exit_matcher(i))(input) @@ -155,7 +155,7 @@ pub fn exit_matcher_parser<'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn text_until_exit<'r, 's>( - context: RefContext<'r, 's>, + context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(verify( From 8502a8830d223cd15b98a05b0aeec4f1fc04c28b Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 2 Sep 2023 23:16:02 -0400 Subject: [PATCH 13/24] Fixing some errors. --- src/parser/text_markup.rs | 103 +++++++++++++++++++++----------------- src/parser/timestamp.rs | 80 ++++++++++++++--------------- 2 files changed, 98 insertions(+), 85 deletions(-) diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index 117b9d3..8b67b15 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -15,10 +15,16 @@ use nom::sequence::terminated; #[cfg(feature = "tracing")] use tracing::span; +use super::object_parser::standard_set_object; use super::org_source::OrgSource; use super::radio_link::RematchObject; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; +use crate::context::parser_with_context; +use crate::context::Context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; @@ -26,13 +32,13 @@ use crate::parser::radio_link::rematch_target; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::preceded_by_whitespace; -use crate::parser::Bold; -use crate::parser::Code; -use crate::parser::Italic; -use crate::parser::Object; -use crate::parser::StrikeThrough; -use crate::parser::Underline; -use crate::parser::Verbatim; +use crate::types::Bold; +use crate::types::Code; +use crate::types::Italic; +use crate::types::Object; +use crate::types::StrikeThrough; +use crate::types::Underline; +use crate::types::Verbatim; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn text_markup<'r, 's>( @@ -154,13 +160,15 @@ pub fn code<'r, 's>( )) } -fn text_markup_object( - marker_symbol: &str, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, Vec>> { +fn text_markup_object<'c>( + marker_symbol: &'c str, +) -> impl for<'b, 'r, 's> Fn( + RefContext<'b, 'r, 's>, + OrgSource<'s>, +) -> Res, Vec>> + + 'c { let marker_symbol = marker_symbol.to_owned(); - move |context: Context, input: OrgSource<'_>| { - _text_markup_object(context, input, marker_symbol.as_str()) - } + move |context, input: OrgSource<'_>| _text_markup_object(context, input, marker_symbol.as_str()) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -173,11 +181,11 @@ fn _text_markup_object<'r, 's, 'x>( let (remaining, open) = tag(marker_symbol)(remaining)?; let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?; let text_markup_end_specialized = text_markup_end(open.into()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &text_markup_end_specialized, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &text_markup_end_specialized, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, (children, _exit_contents)) = verify( many_till( @@ -205,13 +213,14 @@ fn _text_markup_object<'r, 's, 'x>( Ok((remaining, children)) } -fn text_markup_string( - marker_symbol: &str, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { - let marker_symbol = marker_symbol.to_owned(); - move |context: Context, input: OrgSource<'_>| { - _text_markup_string(context, input, marker_symbol.as_str()) - } +fn text_markup_string<'c>( + marker_symbol: &'c str, +) -> impl for<'b, 'r, 's> Fn( + RefContext<'b, 'r, 's>, + OrgSource<'s>, +) -> Res, OrgSource<'s>> + + 'c { + move |context, input: OrgSource<'_>| _text_markup_string(context, input, marker_symbol) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -224,11 +233,11 @@ fn _text_markup_string<'r, 's, 'x>( let (remaining, open) = tag(marker_symbol)(remaining)?; let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?; let text_markup_end_specialized = text_markup_end(open.into()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &text_markup_end_specialized, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &text_markup_end_specialized, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, contents) = recognize(verify( many_till( @@ -257,7 +266,10 @@ fn _text_markup_string<'r, 's, 'x>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { +pub fn pre<'r, 's>( + _context: RefContext<'_, 'r, 's>, + input: OrgSource<'s>, +) -> Res, ()> { let preceding_character = input.get_preceding_character(); match preceding_character { // If None, we are at the start of the file which is technically the beginning of a line. @@ -274,18 +286,19 @@ pub fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Re } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn post<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { +pub fn post<'r, 's>( + _context: RefContext<'_, 'r, 's>, + input: OrgSource<'s>, +) -> Res, ()> { let (remaining, _) = alt((recognize(one_of(" \r\n\t-.,;:!?')}[\"")), line_ending))(input)?; Ok((remaining, ())) } -fn text_markup_end( - marker_symbol: &str, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { - let marker_symbol = marker_symbol.to_owned(); - move |context: Context, input: OrgSource<'_>| { - _text_markup_end(context, input, marker_symbol.as_str()) - } +fn text_markup_end<'c>( + marker_symbol: &'c str, +) -> impl for<'r, 's> Fn(RefContext<'_, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> + 'c +{ + move |context, input: OrgSource<'_>| _text_markup_end(context, input, marker_symbol) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -334,11 +347,11 @@ fn _rematch_text_markup_object<'r, 's, 'x>( let (remaining, open) = tag(marker_symbol)(remaining)?; let (remaining, _peek_not_whitespace) = peek(not(multispace1))(remaining)?; let text_markup_end_specialized = text_markup_end(open.into()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &text_markup_end_specialized, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &text_markup_end_specialized, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, children) = // TODO: This doesn't really check the exit matcher between each object. I think it may be possible to construct an org document that parses incorrectly with the current code. diff --git a/src/parser/timestamp.rs b/src/parser/timestamp.rs index d80df95..19c1b6d 100644 --- a/src/parser/timestamp.rs +++ b/src/parser/timestamp.rs @@ -65,11 +65,11 @@ fn sexp<'r, 's>( context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &sexp_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &sexp_end, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, body) = recognize(verify( many_till( @@ -97,11 +97,11 @@ fn active_timestamp<'r, 's>( ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("<")(input)?; let (remaining, _date) = date(context, remaining)?; - let time_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &active_time_rest_end, - })); + let time_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &active_time_rest_end, + }); + let time_context = context.with_additional_node(&time_context); let (remaining, _time) = opt(tuple((space1, parser_with_context!(time)(&time_context))))(remaining)?; let (remaining, _repeater) = @@ -131,11 +131,11 @@ fn inactive_timestamp<'r, 's>( ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("[")(input)?; let (remaining, _date) = date(context, remaining)?; - let time_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &inactive_time_rest_end, - })); + let time_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &inactive_time_rest_end, + }); + let time_context = context.with_additional_node(&time_context); let (remaining, _time) = opt(tuple((space1, parser_with_context!(time)(&time_context))))(remaining)?; let (remaining, _repeater) = @@ -187,16 +187,16 @@ fn active_time_range_timestamp<'r, 's>( ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("<")(input)?; let (remaining, _date) = date(context, remaining)?; - let time_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &active_time_rest_end, - })); - let first_time_context = - time_context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &time_range_rest_end, - })); + let time_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &active_time_rest_end, + }); + let time_context = context.with_additional_node(&time_context); + let first_time_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &time_range_rest_end, + }); + let first_time_context = time_context.with_additional_node(&first_time_context); let (remaining, _first_time) = tuple((space1, parser_with_context!(time)(&first_time_context)))(remaining)?; let (remaining, _) = tag("-")(remaining)?; @@ -250,16 +250,16 @@ fn inactive_time_range_timestamp<'r, 's>( ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("[")(input)?; let (remaining, _date) = date(context, remaining)?; - let time_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &inactive_time_rest_end, - })); - let first_time_context = - time_context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &time_range_rest_end, - })); + let time_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &inactive_time_rest_end, + }); + let time_context = context.with_additional_node(&time_context); + let first_time_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &time_range_rest_end, + }); + let first_time_context = time_context.with_additional_node(&first_time_context); let (remaining, _first_time) = tuple((space1, parser_with_context!(time)(&first_time_context)))(remaining)?; let (remaining, _) = tag("-")(remaining)?; @@ -307,11 +307,11 @@ fn dayname<'r, 's>( context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &dayname_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &dayname_end, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, body) = recognize(verify( many_till( From 15e8d1ab77662a46912976c08ca45ae668744d94 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 3 Sep 2023 00:05:47 -0400 Subject: [PATCH 14/24] Implement check_exit_matcher. --- src/context/parser_context.rs | 53 +++++++++++++++ src/parser/document.rs | 74 ++++++++++++++------- src/parser/plain_list.rs | 117 ++++++++++++++++++++++------------ src/parser/target.rs | 19 ++++-- src/parser/text_markup.rs | 1 - 5 files changed, 191 insertions(+), 73 deletions(-) diff --git a/src/context/parser_context.rs b/src/context/parser_context.rs index 098f4da..e5cc87b 100644 --- a/src/context/parser_context.rs +++ b/src/context/parser_context.rs @@ -1,10 +1,13 @@ use nom::combinator::eof; +use nom::IResult; use super::exiting::ExitClass; use super::global_settings::GlobalSettings; use super::list::List; use super::DynContextMatcher; use super::RefContext; +use crate::error::CustomError; +use crate::error::MyError; use crate::error::Res; use crate::parser::OrgSource; use crate::types::Object; @@ -169,6 +172,56 @@ impl<'r, 's> Context<'r, 's> { tree: parent_tree.clone(), }) } + + pub fn get_data(&self) -> &ContextElement<'r, 's> { + self.tree.get_data() + } + + #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] + pub fn check_exit_matcher( + &'r self, + i: OrgSource<'s>, + ) -> IResult, OrgSource<'s>, CustomError>> { + let mut current_class_filter = ExitClass::Gamma; + for current_node in self.iter_context() { + let context_element = current_node.get_data(); + match context_element { + ContextElement::ExitMatcherNode(exit_matcher) => { + if exit_matcher.class as u32 <= current_class_filter as u32 { + current_class_filter = exit_matcher.class; + let local_result = (exit_matcher.exit_matcher)(¤t_node, i); + if local_result.is_ok() { + return local_result; + } + } + } + _ => {} + }; + } + // TODO: Make this a specific error instead of just a generic MyError + return Err(nom::Err::Error(CustomError::MyError(MyError( + "NoExit".into(), + )))); + } + + /// Indicates if elements should consume the whitespace after them. + /// + /// Defaults to true. + pub fn should_consume_trailing_whitespace(&self) -> bool { + self._should_consume_trailing_whitespace().unwrap_or(true) + } + + fn _should_consume_trailing_whitespace(&self) -> Option { + for current_node in self.iter() { + match current_node { + ContextElement::ConsumeTrailingWhitespace(should) => { + return Some(*should); + } + _ => {} + } + } + None + } } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] diff --git a/src/parser/document.rs b/src/parser/document.rs index 68db3da..38dad44 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -17,8 +17,6 @@ use nom::multi::many_till; use nom::multi::separated_list1; use nom::sequence::tuple; -use super::element::Element; -use super::object::Object; use super::org_source::convert_error; use super::org_source::OrgSource; use super::token::AllTokensIterator; @@ -26,6 +24,14 @@ use super::token::Token; use super::util::exit_matcher_parser; use super::util::get_consumed; use super::util::start_of_line; +use crate::context::parser_with_context; +use crate::context::Context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::GlobalSettings; +use crate::context::List; +use crate::context::RefContext; use crate::error::Res; use crate::parser::comment::comment; use crate::parser::element_parser::element; @@ -34,11 +40,19 @@ use crate::parser::planning::planning; use crate::parser::property_drawer::property_drawer; use crate::parser::util::blank_line; use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting; +use crate::types::Document; +use crate::types::DocumentElement; +use crate::types::Element; +use crate::types::Heading; +use crate::types::Object; +use crate::types::Section; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[allow(dead_code)] pub fn document(input: &str) -> Res<&str, Document> { - let initial_context = Context::default(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let wrapped_input = OrgSource::new(input); let (remaining, document) = _document(&initial_context, wrapped_input) .map(|(rem, out)| (Into::<&str>::into(rem), out)) @@ -58,9 +72,9 @@ pub fn document(input: &str) -> Res<&str, Document> { .map(|rt| &rt.children) .collect(); if !all_radio_targets.is_empty() { - let initial_context = initial_context - .with_additional_node(ContextElement::RadioTarget(all_radio_targets)); - let (remaining, document) = _document(&initial_context, wrapped_input) + let parser_context = ContextElement::RadioTarget(all_radio_targets); + let parser_context = initial_context.with_additional_node(&parser_context); + let (remaining, document) = _document(&parser_context, wrapped_input) .map(|(rem, out)| (Into::<&str>::into(rem), out)) .map_err(convert_error)?; return Ok((remaining.into(), document)); @@ -96,15 +110,21 @@ fn zeroth_section<'r, 's>( input: OrgSource<'s>, ) -> Res, Section<'s>> { // TODO: The zeroth section is specialized so it probably needs its own parser - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context("section")) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::Context("section"), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Document, exit_matcher: §ion_end, - })); + }), + ]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); + let without_consuming_whitespace_context = ContextElement::ConsumeTrailingWhitespace(false); let without_consuming_whitespace_context = - parser_context.with_additional_node(ContextElement::ConsumeTrailingWhitespace(false)); + parser_context.with_additional_node(&without_consuming_whitespace_context); let element_matcher = parser_with_context!(element(true))(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); @@ -150,13 +170,18 @@ fn section<'r, 's>( mut input: OrgSource<'s>, ) -> Res, Section<'s>> { // TODO: The zeroth section is specialized so it probably needs its own parser - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context("section")) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::Context("section"), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Document, exit_matcher: §ion_end, - })); + }), + ]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); let element_matcher = parser_with_context!(element(true))(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); let (mut remaining, (planning_element, property_drawer_element)) = tuple(( @@ -204,8 +229,9 @@ fn section_end<'r, 's>( const fn heading( parent_stars: usize, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, Heading<'s>> { - move |context: Context, input: OrgSource<'_>| _heading(context, input, parent_stars) +) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, Heading<'s>> +{ + move |context, input: OrgSource<'_>| _heading(context, input, parent_stars) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -270,11 +296,11 @@ fn headline<'r, 's>( Vec<&'s str>, ), > { - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Document, - exit_matcher: &headline_title_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Document, + exit_matcher: &headline_title_end, + }); + let parser_context = context.with_additional_node(&parser_context); let standard_set_object_matcher = parser_with_context!(standard_set_object)(&parser_context); let ( diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 0007853..8960ec0 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -16,21 +16,26 @@ use nom::multi::many1; use nom::multi::many_till; use nom::sequence::tuple; -use super::greater_element::PlainList; -use super::greater_element::PlainListItem; +use super::element_parser::element; +use super::object_parser::standard_set_object; use super::org_source::OrgSource; use super::util::non_whitespace_character; -use super::Context; -use super::Object; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::element_parser::element; use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting; use crate::parser::util::start_of_line; +use crate::types::Object; +use crate::types::PlainList; +use crate::types::PlainListItem; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn detect_plain_list<'s>(input: OrgSource<'s>) -> Res, ()> { @@ -59,13 +64,19 @@ pub fn plain_list<'r, 's>( context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, PlainList<'s>> { - let parser_context = context - .with_additional_node(ContextElement::Context("plain list")) - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::Context("plain list"), + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Beta, exit_matcher: &plain_list_end, - })); + }), + ]; + + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); // children stores tuple of (input string, parsed object) so we can re-parse the final item let mut children = Vec::new(); let mut first_item_indentation: Option = None; @@ -107,8 +118,8 @@ pub fn plain_list<'r, 's>( )))); } }; - let final_item_context = - parser_context.with_additional_node(ContextElement::ConsumeTrailingWhitespace(false)); + let final_item_context = ContextElement::ConsumeTrailingWhitespace(false); + let final_item_context = parser_context.with_additional_node(&final_item_context); let (remaining, reparsed_final_item) = parser_with_context!(plain_list_item)(&final_item_context)(final_child_start)?; children.push((final_child_start, reparsed_final_item)); @@ -164,12 +175,16 @@ pub fn plain_list_item<'r, 's>( }; let (remaining, _ws) = item_tag_post_gap(context, remaining)?; let exit_matcher = plain_list_item_end(indent_level); - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Beta, exit_matcher: &exit_matcher, - })); + }), + ]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]); let (mut remaining, (mut children, _exit_contents)) = many_till( include_input(parser_with_context!(element(true))(&parser_context)), @@ -177,8 +192,8 @@ pub fn plain_list_item<'r, 's>( )(remaining)?; if !children.is_empty() && !context.should_consume_trailing_whitespace() { - let final_item_context = - parser_context.with_additional_node(ContextElement::ConsumeTrailingWhitespace(false)); + let final_item_context = ContextElement::ConsumeTrailingWhitespace(false); + let final_item_context = parser_context.with_additional_node(&final_item_context); let (final_child_start, _original_final_child) = children .pop() .expect("if-statement already checked that children was non-empty."); @@ -249,9 +264,10 @@ fn plain_list_end<'r, 's>( const fn plain_list_item_end( indent_level: usize, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { +) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> +{ let line_indented_lte_matcher = line_indented_lte(indent_level); - move |context: Context, input: OrgSource<'_>| { + move |context, input: OrgSource<'_>| { _plain_list_item_end(context, input, &line_indented_lte_matcher) } } @@ -263,8 +279,8 @@ const fn plain_list_item_end( fn _plain_list_item_end<'r, 's>( context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, - line_indented_lte_matcher: impl for<'rr, 'ss> Fn( - Context<'rr, 'ss>, + line_indented_lte_matcher: impl for<'bb, 'rr, 'ss> Fn( + RefContext<'bb, 'rr, 'ss>, OrgSource<'ss>, ) -> Res, OrgSource<'ss>>, ) -> Res, OrgSource<'s>> { @@ -277,8 +293,9 @@ fn _plain_list_item_end<'r, 's>( const fn line_indented_lte( indent_level: usize, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { - move |context: Context, input: OrgSource<'_>| _line_indented_lte(context, input, indent_level) +) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> +{ + move |context, input: OrgSource<'_>| _line_indented_lte(context, input, indent_level) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -301,11 +318,11 @@ fn item_tag<'r, 's>( context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &item_tag_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &item_tag_end, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, (children, _exit_contents)) = verify( many_till( // TODO: Should this be using a different set like the minimal set? @@ -353,14 +370,16 @@ fn item_tag_post_gap<'r, 's>( #[cfg(test)] mod tests { use super::*; - use crate::parser::parser_context::ContextTree; - use crate::parser::parser_with_context::parser_with_context; - use crate::parser::Source; + use crate::context::Context; + use crate::context::GlobalSettings; + use crate::context::List; #[test] fn plain_list_item_empty() { let input = OrgSource::new("1."); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let plain_list_item_matcher = parser_with_context!(plain_list_item)(&initial_context); let (remaining, result) = plain_list_item_matcher(input).unwrap(); assert_eq!(Into::<&str>::into(remaining), ""); @@ -370,7 +389,9 @@ mod tests { #[test] fn plain_list_item_simple() { let input = OrgSource::new("1. foo"); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let plain_list_item_matcher = parser_with_context!(plain_list_item)(&initial_context); let (remaining, result) = plain_list_item_matcher(input).unwrap(); assert_eq!(Into::<&str>::into(remaining), ""); @@ -380,7 +401,9 @@ mod tests { #[test] fn plain_list_empty() { let input = OrgSource::new("1."); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let plain_list_matcher = parser_with_context!(plain_list)(&initial_context); let (remaining, result) = plain_list_matcher(input).unwrap(); assert_eq!(Into::<&str>::into(remaining), ""); @@ -390,7 +413,9 @@ mod tests { #[test] fn plain_list_simple() { let input = OrgSource::new("1. foo"); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let plain_list_matcher = parser_with_context!(plain_list)(&initial_context); let (remaining, result) = plain_list_matcher(input).unwrap(); assert_eq!(Into::<&str>::into(remaining), ""); @@ -401,7 +426,9 @@ mod tests { fn plain_list_cant_start_line_with_asterisk() { // Plain lists with an asterisk bullet must be indented or else they would be a headline let input = OrgSource::new("* foo"); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let plain_list_matcher = parser_with_context!(plain_list)(&initial_context); let result = plain_list_matcher(input); assert!(result.is_err()); @@ -411,7 +438,9 @@ mod tests { fn indented_can_start_line_with_asterisk() { // Plain lists with an asterisk bullet must be indented or else they would be a headline let input = OrgSource::new(" * foo"); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let plain_list_matcher = parser_with_context!(plain_list)(&initial_context); let result = plain_list_matcher(input); assert!(result.is_ok()); @@ -429,7 +458,9 @@ mod tests { ipsum "#, ); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let plain_list_matcher = parser_with_context!(element(true))(&initial_context); let (remaining, result) = plain_list_matcher(input).expect("Should parse the plain list successfully."); @@ -455,7 +486,9 @@ mod tests { baz"#, ); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let plain_list_matcher = parser_with_context!(element(true))(&initial_context); let (remaining, result) = plain_list_matcher(input).expect("Should parse the plain list successfully."); @@ -486,7 +519,9 @@ baz"#, dolar"#, ); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let plain_list_matcher = parser_with_context!(element(true))(&initial_context); let (remaining, result) = plain_list_matcher(input).expect("Should parse the plain list successfully."); diff --git a/src/parser/target.rs b/src/parser/target.rs index ebb53b7..8f2627b 100644 --- a/src/parser/target.rs +++ b/src/parser/target.rs @@ -7,13 +7,18 @@ use nom::combinator::verify; use nom::multi::many_till; use super::org_source::OrgSource; +use super::util::exit_matcher_parser; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::util::get_consumed; -use crate::parser::Target; +use crate::types::Target; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn target<'r, 's>( @@ -25,11 +30,11 @@ pub fn target<'r, 's>( !c.is_whitespace() && !"<>\n".contains(*c) }))(remaining)?; - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Beta, - exit_matcher: &target_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + exit_matcher: &target_end, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, _body) = recognize(many_till( anychar, parser_with_context!(exit_matcher_parser)(&parser_context), diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index 8b67b15..3b976ef 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -20,7 +20,6 @@ use super::org_source::OrgSource; use super::radio_link::RematchObject; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; use crate::context::parser_with_context; -use crate::context::Context; use crate::context::ContextElement; use crate::context::ExitClass; use crate::context::ExitMatcherNode; From b54c6d366cf2a7a4cb95068b73d4bbd8f3fabbd5 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 3 Sep 2023 00:27:50 -0400 Subject: [PATCH 15/24] Fixing more errors. --- src/parser/property_drawer.rs | 36 +++++++++------ src/parser/radio_link.rs | 59 +++++++++++++++---------- src/parser/regular_link.rs | 22 +++++---- src/parser/subscript_and_superscript.rs | 29 +++++++----- src/parser/table.rs | 39 ++++++++++------ src/parser/util.rs | 4 +- src/types/mod.rs | 1 + 7 files changed, 118 insertions(+), 72 deletions(-) diff --git a/src/parser/property_drawer.rs b/src/parser/property_drawer.rs index f9b380e..d7a2850 100644 --- a/src/parser/property_drawer.rs +++ b/src/parser/property_drawer.rs @@ -14,16 +14,21 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::org_source::OrgSource; -use super::Context; +use super::util::exit_matcher_parser; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::greater_element::NodeProperty; -use crate::parser::greater_element::PropertyDrawer; use crate::parser::util::get_consumed; use crate::parser::util::immediate_in_section; use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting; use crate::parser::util::start_of_line; +use crate::types::NodeProperty; +use crate::types::PropertyDrawer; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn property_drawer<'r, 's>( @@ -46,13 +51,18 @@ pub fn property_drawer<'r, 's>( line_ending, ))(input)?; - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context("property-drawer")) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::Context("property-drawer"), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Alpha, exit_matcher: &property_drawer_end, - })); + }), + ]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); let node_property_matcher = parser_with_context!(node_property)(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); @@ -135,11 +145,11 @@ fn node_property_name<'r, 's>( context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Beta, - exit_matcher: &node_property_name_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + exit_matcher: &node_property_name_end, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, name) = recognize(tuple(( verify( diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index 5a3a64e..977d8d9 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -5,16 +5,22 @@ use nom::character::complete::space0; use nom::combinator::verify; use nom::multi::many_till; +use super::object_parser::minimal_set_object; use super::org_source::OrgSource; +use super::util::exit_matcher_parser; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; -use super::Object; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::util::get_consumed; -use crate::parser::RadioLink; -use crate::parser::RadioTarget; +use crate::types::Object; +use crate::types::RadioLink; +use crate::types::RadioTarget; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn radio_link<'r, 's>( @@ -23,7 +29,7 @@ pub fn radio_link<'r, 's>( ) -> Res, RadioLink<'s>> { let radio_targets = context .iter() - .filter_map(|context_element| match context_element.get_data() { + .filter_map(|context_element| match context_element { ContextElement::RadioTarget(targets) => Some(targets), _ => None, }) @@ -84,11 +90,11 @@ pub fn radio_target<'r, 's>( input: OrgSource<'s>, ) -> Res, RadioTarget<'s>> { let (remaining, _opening) = tag("<<<")(input)?; - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &radio_target_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &radio_target_end, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, (children, _exit_contents)) = verify( many_till( @@ -130,25 +136,28 @@ pub trait RematchObject<'x> { #[cfg(test)] mod tests { use super::*; + use crate::context::Context; + use crate::context::GlobalSettings; + use crate::context::List; use crate::parser::element_parser::element; - use crate::parser::parser_context::ContextElement; - use crate::parser::parser_context::ContextTree; - use crate::parser::parser_with_context::parser_with_context; - use crate::parser::source::Source; - use crate::parser::Bold; - use crate::parser::PlainText; + use crate::types::Bold; + use crate::types::Element; + use crate::types::PlainText; + use crate::types::Source; #[test] fn plain_text_radio_target() { let input = OrgSource::new("foo bar baz"); let radio_target_match = vec![Object::PlainText(PlainText { source: "bar" })]; - let initial_context: ContextTree<'_, '_> = ContextTree::new(); - let document_context = initial_context - .with_additional_node(ContextElement::RadioTarget(vec![&radio_target_match])); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); + let document_context = ContextElement::RadioTarget(vec![&radio_target_match]); + let document_context = initial_context.with_additional_node(&document_context); let paragraph_matcher = parser_with_context!(element(true))(&document_context); let (remaining, first_paragraph) = paragraph_matcher(input).expect("Parse first paragraph"); let first_paragraph = match first_paragraph { - crate::parser::Element::Paragraph(paragraph) => paragraph, + Element::Paragraph(paragraph) => paragraph, _ => panic!("Should be a paragraph!"), }; assert_eq!(Into::<&str>::into(remaining), ""); @@ -173,14 +182,16 @@ mod tests { source: "*bar*", children: vec![Object::PlainText(PlainText { source: "bar" })], })]; - let initial_context: ContextTree<'_, '_> = ContextTree::new(); - let document_context = initial_context - .with_additional_node(ContextElement::RadioTarget(vec![&radio_target_match])); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); + let document_context = ContextElement::RadioTarget(vec![&radio_target_match]); + let document_context = initial_context.with_additional_node(&document_context); let paragraph_matcher = parser_with_context!(element(true))(&document_context); let (remaining, first_paragraph) = paragraph_matcher(input.into()).expect("Parse first paragraph"); let first_paragraph = match first_paragraph { - crate::parser::Element::Paragraph(paragraph) => paragraph, + Element::Paragraph(paragraph) => paragraph, _ => panic!("Should be a paragraph!"), }; assert_eq!(Into::<&str>::into(remaining), ""); diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index cf751bb..ce83bea 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -6,13 +6,19 @@ use nom::character::complete::one_of; use nom::combinator::verify; use nom::multi::many_till; +use super::object_parser::regular_link_description_object_set; use super::org_source::OrgSource; +use super::util::exit_matcher_parser; use super::util::get_consumed; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; -use super::Object; -use super::RegularLink; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::Res; +use crate::types::Object; +use crate::types::RegularLink; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn regular_link<'r, 's>( @@ -86,11 +92,11 @@ pub fn description<'r, 's>( context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Beta, - exit_matcher: &description_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + exit_matcher: &description_end, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, (children, _exit_contents)) = verify( many_till( parser_with_context!(regular_link_description_object_set)(&parser_context), diff --git a/src/parser/subscript_and_superscript.rs b/src/parser/subscript_and_superscript.rs index 8463a40..3fb3ee3 100644 --- a/src/parser/subscript_and_superscript.rs +++ b/src/parser/subscript_and_superscript.rs @@ -10,17 +10,23 @@ use nom::combinator::recognize; use nom::combinator::verify; use nom::multi::many_till; +use super::object_parser::standard_set_object; use super::org_source::BracketDepth; use super::org_source::OrgSource; +use super::util::exit_matcher_parser; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; -use super::Object; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::util::get_consumed; -use crate::parser::Subscript; -use crate::parser::Superscript; +use crate::types::Object; +use crate::types::Subscript; +use crate::types::Superscript; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn subscript<'r, 's>( @@ -151,11 +157,11 @@ fn script_with_braces<'r, 's>( ) -> Res, Vec>> { let (remaining, _) = tag("{")(input)?; let exit_with_depth = script_with_braces_end(remaining.get_brace_depth()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &exit_with_depth, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &exit_with_depth, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, (children, _exit_contents)) = many_till( parser_with_context!(standard_set_object)(&parser_context), @@ -168,8 +174,9 @@ fn script_with_braces<'r, 's>( fn script_with_braces_end( starting_brace_depth: BracketDepth, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { - move |context: Context, input: OrgSource<'_>| { +) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> +{ + move |context, input: OrgSource<'_>| { _script_with_braces_end(context, input, starting_brace_depth) } } diff --git a/src/parser/table.rs b/src/parser/table.rs index eeb3c1a..a471890 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -12,14 +12,20 @@ use nom::multi::many1; use nom::multi::many_till; use nom::sequence::tuple; +use super::object_parser::table_cell_set_object; use super::org_source::OrgSource; -use super::Context; +use super::util::exit_matcher_parser; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::Res; -use crate::parser::greater_element::TableRow; -use crate::parser::lesser_element::TableCell; use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; -use crate::parser::Table; +use crate::types::Table; +use crate::types::TableCell; +use crate::types::TableRow; /// Parse an org-mode-style table /// @@ -32,13 +38,18 @@ pub fn org_mode_table<'r, 's>( start_of_line(input)?; peek(tuple((space0, tag("|"))))(input)?; - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context("table")) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::Context("table"), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Alpha, exit_matcher: &table_end, - })); + }), + ]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); let org_mode_table_row_matcher = parser_with_context!(org_mode_table_row)(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); @@ -120,11 +131,11 @@ pub fn org_mode_table_cell<'r, 's>( context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, TableCell<'s>> { - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Beta, - exit_matcher: &org_mode_table_cell_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + exit_matcher: &org_mode_table_cell_end, + }); + let parser_context = context.with_additional_node(&parser_context); let table_cell_set_object_matcher = parser_with_context!(table_cell_set_object)(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); diff --git a/src/parser/util.rs b/src/parser/util.rs index 41539ca..f5cab9b 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -28,7 +28,7 @@ pub const WORD_CONSTITUENT_CHARACTERS: &str = #[allow(dead_code)] pub fn in_section<'r, 's, 'x>(context: RefContext<'_, 'r, 's>, section_name: &'x str) -> bool { for thing in context.iter() { - match thing.get_data() { + match thing { ContextElement::Context(name) if *name == section_name => return true, _ => {} } @@ -42,7 +42,7 @@ pub fn immediate_in_section<'r, 's, 'x>( section_name: &'x str, ) -> bool { for thing in context.iter() { - match thing.get_data() { + match thing { ContextElement::Context(name) if *name == section_name => return true, ContextElement::Context(name) if *name != section_name => return false, _ => {} diff --git a/src/types/mod.rs b/src/types/mod.rs index 9d2f200..8011bb2 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -17,6 +17,7 @@ pub use greater_element::PlainList; pub use greater_element::PlainListItem; pub use greater_element::PropertyDrawer; pub use greater_element::Table; +pub use greater_element::NodeProperty; pub use greater_element::TableRow; pub use lesser_element::Clock; pub use lesser_element::Comment; From cd69e08516712b727a5f49c1f20f4f321aebd679 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 3 Sep 2023 11:05:34 -0400 Subject: [PATCH 16/24] Fixing more errors. --- src/context/mod.rs | 4 +- src/parser/latex_environment.rs | 29 +++++----- src/parser/lesser_block.rs | 95 ++++++++++++++++++++------------- src/parser/paragraph.rs | 30 +++++++---- src/parser/plain_link.rs | 18 ++++--- 5 files changed, 106 insertions(+), 70 deletions(-) diff --git a/src/context/mod.rs b/src/context/mod.rs index 54e75e7..247b2cf 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -10,9 +10,9 @@ mod parser_with_context; pub type RefContext<'b, 'r, 's> = &'b Context<'r, 's>; pub trait ContextMatcher = for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>; -type DynContextMatcher<'c> = dyn ContextMatcher + 'c; +pub type DynContextMatcher<'c> = dyn ContextMatcher + 'c; pub trait Matcher = for<'s> Fn(OrgSource<'s>) -> Res, OrgSource<'s>>; -type DynMatcher<'c> = dyn Matcher + 'c; +pub type DynMatcher<'c> = dyn Matcher + 'c; pub use exiting::ExitClass; pub use global_settings::GlobalSettings; diff --git a/src/parser/latex_environment.rs b/src/parser/latex_environment.rs index 7a9320f..a001e69 100644 --- a/src/parser/latex_environment.rs +++ b/src/parser/latex_environment.rs @@ -13,10 +13,16 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::get_consumed; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ContextMatcher; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::Res; use crate::parser::util::exit_matcher_parser; use crate::parser::util::start_of_line; -use crate::parser::LatexEnvironment; +use crate::types::LatexEnvironment; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn latex_environment<'r, 's>( @@ -34,11 +40,11 @@ pub fn latex_environment<'r, 's>( ))(remaining)?; let latex_environment_end_specialized = latex_environment_end(name.into()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Beta, - exit_matcher: &latex_environment_end_specialized, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + exit_matcher: &latex_environment_end_specialized, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, _contents) = contents(&latex_environment_end_specialized, context, remaining)?; let (remaining, _end) = latex_environment_end_specialized(&parser_context, remaining)?; @@ -62,12 +68,13 @@ fn name<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { tracing::instrument(ret, level = "debug", skip(end_matcher)) )] pub fn contents< + 'b, 'r, 's, - F: Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>, + F: Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>, >( end_matcher: F, - context: RefContext<'_, 'r, 's>, + context: RefContext<'b, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, source) = recognize(many_till( @@ -81,11 +88,9 @@ pub fn contents< Ok((remaining, source)) } -fn latex_environment_end( - current_name: &str, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { +fn latex_environment_end(current_name: &str) -> impl ContextMatcher { let current_name_lower = current_name.to_lowercase(); - move |context: Context, input: OrgSource<'_>| { + move |context, input: OrgSource<'_>| { _latex_environment_end(context, input, current_name_lower.as_str()) } } diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index 8a78b6a..65d5181 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -12,20 +12,26 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::org_source::OrgSource; +use crate::context::ContextMatcher; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::Res; -use crate::parser::lesser_element::CommentBlock; -use crate::parser::lesser_element::ExampleBlock; -use crate::parser::lesser_element::ExportBlock; -use crate::parser::lesser_element::SrcBlock; -use crate::parser::lesser_element::VerseBlock; -use crate::parser::object::Object; -use crate::parser::object::PlainText; use crate::parser::object_parser::standard_set_object; use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; use crate::parser::util::text_until_exit; +use crate::types::CommentBlock; +use crate::types::ExampleBlock; +use crate::types::ExportBlock; +use crate::types::Object; +use crate::types::PlainText; +use crate::types::SrcBlock; +use crate::types::VerseBlock; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn verse_block<'r, 's>( @@ -36,13 +42,18 @@ pub fn verse_block<'r, 's>( let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?; let (remaining, _nl) = line_ending(remaining)?; let lesser_block_end_specialized = lesser_block_end("verse"); - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context("lesser block")) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::Context("lesser block"), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Beta, exit_matcher: &lesser_block_end_specialized, - })); + }), + ]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, @@ -87,13 +98,18 @@ pub fn comment_block<'r, 's>( let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?; let (remaining, _nl) = line_ending(remaining)?; let lesser_block_end_specialized = lesser_block_end("comment"); - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context("lesser block")) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::Context("lesser block"), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Beta, exit_matcher: &lesser_block_end_specialized, - })); + }), + ]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, @@ -123,13 +139,14 @@ pub fn example_block<'r, 's>( let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?; let (remaining, _nl) = line_ending(remaining)?; let lesser_block_end_specialized = lesser_block_end("example"); - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context("lesser block")) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ContextElement::ConsumeTrailingWhitespace(true), ContextElement::Context("lesser block"), ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Beta, exit_matcher: &lesser_block_end_specialized, - })); + })]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, @@ -160,13 +177,14 @@ pub fn export_block<'r, 's>( let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?; let (remaining, _nl) = line_ending(remaining)?; let lesser_block_end_specialized = lesser_block_end("export"); - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context("lesser block")) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ContextElement::ConsumeTrailingWhitespace(true), ContextElement::Context("lesser block"), ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Beta, exit_matcher: &lesser_block_end_specialized, - })); + })]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, @@ -197,13 +215,14 @@ pub fn src_block<'r, 's>( let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?; let (remaining, _nl) = line_ending(remaining)?; let lesser_block_end_specialized = lesser_block_end("src"); - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context("lesser block")) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ContextElement::ConsumeTrailingWhitespace(true), ContextElement::Context("lesser block"), ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Alpha, exit_matcher: &lesser_block_end_specialized, - })); + })]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, @@ -236,9 +255,9 @@ fn data<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { fn lesser_block_end( current_name: &str, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { +) -> impl ContextMatcher { let current_name_lower = current_name.to_lowercase(); - move |context: Context, input: OrgSource<'_>| { + move |context, input: OrgSource<'_>| { _lesser_block_end(context, input, current_name_lower.as_str()) } } @@ -263,11 +282,11 @@ fn _lesser_block_end<'r, 's, 'x>( /// Parser for the beginning of a lesser block /// /// current_name MUST be lowercase. We do not do the conversion ourselves because it is not allowed in a const fn. -const fn lesser_block_begin( - current_name: &'static str, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { +const fn lesser_block_begin<'c>( + current_name: &'c str, +) -> impl ContextMatcher + 'c { // TODO: Since this is a const fn, is there ANY way to "generate" functions at compile time? - move |context: Context, input: OrgSource<'_>| _lesser_block_begin(context, input, current_name) + move |context, input: OrgSource<'_>| _lesser_block_begin(context, input, current_name) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index c275f6d..643fb5c 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -7,26 +7,30 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::element_parser::detect_element; -use super::lesser_element::Paragraph; use super::org_source::OrgSource; use super::util::blank_line; use super::util::get_consumed; -use super::Context; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::Res; use crate::parser::object_parser::standard_set_object; use crate::parser::util::exit_matcher_parser; use crate::parser::util::start_of_line; +use crate::types::Paragraph; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn paragraph<'r, 's>( context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Paragraph<'s>> { - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: ¶graph_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: ¶graph_end, + }); + let parser_context = context.with_additional_node(&parser_context); let standard_set_object_matcher = parser_with_context!(standard_set_object)(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); @@ -63,16 +67,20 @@ fn paragraph_end<'r, 's>( #[cfg(test)] mod tests { + use crate::context::parser_with_context; + use crate::context::Context; + use crate::context::ContextElement; + use crate::context::GlobalSettings; + use crate::context::List; use crate::parser::element_parser::element; use crate::parser::org_source::OrgSource; - use crate::parser::parser_context::ContextTree; - use crate::parser::parser_with_context::parser_with_context; - use crate::parser::source::Source; #[test] fn two_paragraphs() { let input = OrgSource::new("foo bar baz\n\nlorem ipsum"); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let paragraph_matcher = parser_with_context!(element(true))(&initial_context); let (remaining, first_paragraph) = paragraph_matcher(input).expect("Parse first paragraph"); let (remaining, second_paragraph) = diff --git a/src/parser/plain_link.rs b/src/parser/plain_link.rs index 1cf2b36..2515aff 100644 --- a/src/parser/plain_link.rs +++ b/src/parser/plain_link.rs @@ -11,14 +11,18 @@ use nom::combinator::verify; use nom::multi::many_till; use super::org_source::OrgSource; -use super::Context; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::object::PlainLink; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::WORD_CONSTITUENT_CHARACTERS; +use crate::types::PlainLink; // TODO: Make this a user-provided variable corresponding to elisp's org-link-parameters const ORG_LINK_PARAMETERS: [&'static str; 23] = [ @@ -118,11 +122,11 @@ fn path_plain<'r, 's>( input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // TODO: "optionally containing parenthesis-wrapped non-whitespace non-bracket substrings up to a depth of two. The string must end with either a non-punctation non-whitespace character, a forwards slash, or a parenthesis-wrapped substring" - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &path_plain_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &path_plain_end, + }); + let parser_context = context.with_additional_node(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); From fdf35ba23c77face5f8a150753487da74b4c92a5 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 3 Sep 2023 12:07:51 -0400 Subject: [PATCH 17/24] Fixing more errors. --- src/parser/angle_link.rs | 17 +++++---- src/parser/citation.rs | 60 ++++++++++++++++--------------- src/parser/citation_reference.rs | 46 ++++++++++++------------ src/parser/comment.rs | 14 +++++--- src/parser/drawer.rs | 27 +++++++++----- src/parser/dynamic_block.rs | 27 +++++++++----- src/parser/export_snippet.rs | 17 +++++---- src/parser/footnote_definition.rs | 36 +++++++++++++------ src/parser/footnote_reference.rs | 34 ++++++++++-------- src/parser/greater_block.rs | 39 ++++++++++++-------- src/parser/inline_babel_call.rs | 54 ++++++++++++++-------------- src/parser/inline_source_block.rs | 52 +++++++++++++-------------- src/parser/latex_environment.rs | 15 ++++---- src/parser/object_parser.rs | 5 +-- 14 files changed, 253 insertions(+), 190 deletions(-) diff --git a/src/parser/angle_link.rs b/src/parser/angle_link.rs index da25d49..88e9789 100644 --- a/src/parser/angle_link.rs +++ b/src/parser/angle_link.rs @@ -6,11 +6,16 @@ use nom::multi::many_till; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::Res; use crate::parser::plain_link::protocol; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; -use crate::parser::AngleLink; +use crate::types::AngleLink; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn angle_link<'r, 's>( @@ -40,11 +45,11 @@ fn path_angle<'r, 's>( context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &path_angle_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &path_angle_end, + }); + let parser_context = context.with_additional_node(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); diff --git a/src/parser/citation.rs b/src/parser/citation.rs index babbae8..1b9f65c 100644 --- a/src/parser/citation.rs +++ b/src/parser/citation.rs @@ -14,15 +14,21 @@ use super::citation_reference::must_balance_bracket; use super::org_source::BracketDepth; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ContextMatcher; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::Res; use crate::parser::citation_reference::citation_reference; use crate::parser::citation_reference::citation_reference_key; -use crate::parser::object::Citation; use crate::parser::object_parser::standard_set_object; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; -use crate::parser::Object; +use crate::types::Citation; +use crate::types::Object; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn citation<'r, 's>( @@ -82,11 +88,11 @@ fn global_prefix<'r, 's>( input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = global_prefix_end(input.get_bracket_depth()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &exit_with_depth, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &exit_with_depth, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, (children, _exit_contents)) = verify( many_till( parser_with_context!(standard_set_object)(&parser_context), @@ -98,12 +104,8 @@ fn global_prefix<'r, 's>( Ok((remaining, children)) } -fn global_prefix_end( - starting_bracket_depth: BracketDepth, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { - move |context: Context, input: OrgSource<'_>| { - _global_prefix_end(context, input, starting_bracket_depth) - } +fn global_prefix_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { + move |context, input: OrgSource<'_>| _global_prefix_end(context, input, starting_bracket_depth) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -135,11 +137,11 @@ fn global_suffix<'r, 's>( input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = global_suffix_end(input.get_bracket_depth()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &exit_with_depth, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &exit_with_depth, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, (children, _exit_contents)) = verify( many_till( parser_with_context!(standard_set_object)(&parser_context), @@ -150,12 +152,8 @@ fn global_suffix<'r, 's>( Ok((remaining, children)) } -fn global_suffix_end( - starting_bracket_depth: BracketDepth, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { - move |context: Context, input: OrgSource<'_>| { - _global_suffix_end(context, input, starting_bracket_depth) - } +fn global_suffix_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { + move |context, input: OrgSource<'_>| _global_suffix_end(context, input, starting_bracket_depth) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -184,19 +182,23 @@ fn _global_suffix_end<'r, 's>( #[cfg(test)] mod tests { use super::*; + use crate::context::Context; + use crate::context::GlobalSettings; + use crate::context::List; use crate::parser::element_parser::element; - use crate::parser::parser_context::ContextTree; - use crate::parser::parser_with_context::parser_with_context; - use crate::parser::source::Source; + use crate::types::Element; + use crate::types::Source; #[test] fn citation_simple() { let input = OrgSource::new("[cite:@foo]"); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let paragraph_matcher = parser_with_context!(element(true))(&initial_context); let (remaining, first_paragraph) = paragraph_matcher(input).expect("Parse first paragraph"); let first_paragraph = match first_paragraph { - crate::parser::Element::Paragraph(paragraph) => paragraph, + Element::Paragraph(paragraph) => paragraph, _ => panic!("Should be a paragraph!"), }; assert_eq!(Into::<&str>::into(remaining), ""); diff --git a/src/parser/citation_reference.rs b/src/parser/citation_reference.rs index 8b3c5b1..3a55adf 100644 --- a/src/parser/citation_reference.rs +++ b/src/parser/citation_reference.rs @@ -12,15 +12,21 @@ use nom::sequence::tuple; use super::org_source::BracketDepth; use super::org_source::OrgSource; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ContextMatcher; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::object::CitationReference; use crate::parser::object_parser::minimal_set_object; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::WORD_CONSTITUENT_CHARACTERS; -use crate::parser::Object; +use crate::types::CitationReference; +use crate::types::Object; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn citation_reference<'r, 's>( @@ -68,11 +74,11 @@ fn key_prefix<'r, 's>( input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = key_prefix_end(input.get_bracket_depth()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &exit_with_depth, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &exit_with_depth, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, (children, _exit_contents)) = verify( many_till( parser_with_context!(minimal_set_object)(&parser_context), @@ -89,11 +95,11 @@ fn key_suffix<'r, 's>( input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = key_suffix_end(input.get_bracket_depth()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &exit_with_depth, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &exit_with_depth, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, (children, _exit_contents)) = verify( many_till( parser_with_context!(minimal_set_object)(&parser_context), @@ -104,12 +110,8 @@ fn key_suffix<'r, 's>( Ok((remaining, children)) } -fn key_prefix_end( - starting_bracket_depth: BracketDepth, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { - move |context: Context, input: OrgSource<'_>| { - _key_prefix_end(context, input, starting_bracket_depth) - } +fn key_prefix_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { + move |context, input: OrgSource<'_>| _key_prefix_end(context, input, starting_bracket_depth) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -135,12 +137,8 @@ fn _key_prefix_end<'r, 's>( ))(input) } -fn key_suffix_end( - starting_bracket_depth: BracketDepth, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { - move |context: Context, input: OrgSource<'_>| { - _key_suffix_end(context, input, starting_bracket_depth) - } +fn key_suffix_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { + move |context, input: OrgSource<'_>| _key_suffix_end(context, input, starting_bracket_depth) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] diff --git a/src/parser/comment.rs b/src/parser/comment.rs index 931ab97..545c6ec 100644 --- a/src/parser/comment.rs +++ b/src/parser/comment.rs @@ -13,13 +13,15 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::get_consumed; +use crate::context::parser_with_context; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::util::exit_matcher_parser; use crate::parser::util::immediate_in_section; use crate::parser::util::start_of_line; -use crate::parser::Comment; +use crate::types::Comment; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn comment<'r, 's>( @@ -66,8 +68,10 @@ fn comment_line<'r, 's>( #[cfg(test)] mod tests { use super::*; - use crate::parser::parser_context::ContextTree; - use crate::parser::parser_with_context::parser_with_context; + use crate::context::Context; + use crate::context::ContextElement; + use crate::context::GlobalSettings; + use crate::context::List; #[test] fn require_space_after_hash() { @@ -76,7 +80,9 @@ mod tests { #not a comment # Comment again", ); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let comment_matcher = parser_with_context!(comment)(&initial_context); let (remaining, first_comment) = comment_matcher(input).expect("Parse first comment"); assert_eq!( diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index f794a3f..83246ac 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -11,6 +11,11 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::org_source::OrgSource; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; @@ -21,9 +26,10 @@ use crate::parser::util::get_consumed; use crate::parser::util::immediate_in_section; use crate::parser::util::start_of_line; use crate::parser::util::WORD_CONSTITUENT_CHARACTERS; -use crate::parser::Drawer; -use crate::parser::Element; -use crate::parser::Paragraph; +use crate::types::Drawer; +use crate::types::Element; +use crate::types::Paragraph; +use crate::types::SetSource; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn drawer<'r, 's>( @@ -44,13 +50,18 @@ pub fn drawer<'r, 's>( recognize(tuple((space0, line_ending))), ))(remaining)?; - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context("drawer")) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::Context("drawer"), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Alpha, exit_matcher: &drawer_end, - })); + }), + ]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); let element_matcher = parser_with_context!(element(true))(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); diff --git a/src/parser/dynamic_block.rs b/src/parser/dynamic_block.rs index 7625fde..46a5387 100644 --- a/src/parser/dynamic_block.rs +++ b/src/parser/dynamic_block.rs @@ -12,18 +12,24 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::org_source::OrgSource; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::element_parser::element; -use crate::parser::greater_element::DynamicBlock; -use crate::parser::lesser_element::Paragraph; use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::immediate_in_section; use crate::parser::util::start_of_line; -use crate::parser::Element; +use crate::types::DynamicBlock; +use crate::types::Element; +use crate::types::Paragraph; +use crate::types::SetSource; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn dynamic_block<'r, 's>( @@ -44,13 +50,18 @@ pub fn dynamic_block<'r, 's>( opt(tuple((space1, parameters))), line_ending, ))(remaining)?; - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context("dynamic block")) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::Context("dynamic block"), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Alpha, exit_matcher: &dynamic_block_end, - })); + }), + ]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, diff --git a/src/parser/export_snippet.rs b/src/parser/export_snippet.rs index a294ab7..23d1251 100644 --- a/src/parser/export_snippet.rs +++ b/src/parser/export_snippet.rs @@ -9,10 +9,15 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::Res; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; -use crate::parser::ExportSnippet; +use crate::types::ExportSnippet; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn export_snippet<'r, 's>( @@ -21,11 +26,11 @@ pub fn export_snippet<'r, 's>( ) -> Res, ExportSnippet<'s>> { let (remaining, _) = tag("@@")(input)?; let (remaining, backend_name) = backend(context, remaining)?; - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &export_snippet_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &export_snippet_end, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, backend_contents) = opt(tuple(( tag(":"), parser_with_context!(contents)(&parser_context), diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 0bd1089..ec76833 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -12,17 +12,22 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::WORD_CONSTITUENT_CHARACTERS; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::element_parser::element; -use crate::parser::greater_element::FootnoteDefinition; use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::immediate_in_section; use crate::parser::util::maybe_consume_trailing_whitespace; use crate::parser::util::start_of_line; +use crate::types::FootnoteDefinition; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn footnote_definition<'r, 's>( @@ -38,13 +43,18 @@ pub fn footnote_definition<'r, 's>( // Cannot be indented. let (remaining, (_lead_in, lbl, _lead_out, _ws)) = tuple((tag_no_case("[fn:"), label, tag("]"), space0))(input)?; - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context("footnote definition")) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::Context("footnote definition"), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Alpha, exit_matcher: &footnote_definition_end, - })); + }), + ]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); // TODO: The problem is we are not accounting for trailing whitespace like we do in section. Maybe it would be easier if we passed down whether or not to parse trailing whitespace into the element matcher similar to how tag takes in parameters. let element_matcher = parser_with_context!(element(true))(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); @@ -100,9 +110,9 @@ fn detect_footnote_definition<'s>(input: OrgSource<'s>) -> Res, () #[cfg(test)] mod tests { use super::*; - use crate::parser::parser_context::ContextTree; - use crate::parser::parser_with_context::parser_with_context; - use crate::parser::Source; + use crate::context::Context; + use crate::context::GlobalSettings; + use crate::context::List; #[test] fn two_paragraphs() { @@ -113,7 +123,9 @@ mod tests { line footnote.", ); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let footnote_definition_matcher = parser_with_context!(element(true))(&initial_context); let (remaining, first_footnote_definition) = footnote_definition_matcher(input).expect("Parse first footnote_definition"); @@ -144,7 +156,9 @@ line footnote. not in the footnote.", ); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let footnote_definition_matcher = parser_with_context!(element(true))(&initial_context); let (remaining, first_footnote_definition) = footnote_definition_matcher(input).expect("Parse first footnote_definition"); diff --git a/src/parser/footnote_reference.rs b/src/parser/footnote_reference.rs index 20462c3..bea3d94 100644 --- a/src/parser/footnote_reference.rs +++ b/src/parser/footnote_reference.rs @@ -7,6 +7,12 @@ use nom::multi::many_till; use super::org_source::BracketDepth; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ContextMatcher; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; @@ -14,7 +20,7 @@ use crate::parser::footnote_definition::label; use crate::parser::object_parser::standard_set_object; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; -use crate::parser::FootnoteReference; +use crate::types::FootnoteReference; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn footnote_reference<'r, 's>( @@ -35,11 +41,11 @@ fn anonymous_footnote<'r, 's>( ) -> Res, FootnoteReference<'s>> { let (remaining, _) = tag_no_case("[fn::")(input)?; let exit_with_depth = footnote_definition_end(remaining.get_bracket_depth()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Beta, - exit_matcher: &exit_with_depth, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + exit_matcher: &exit_with_depth, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, (children, _exit_contents)) = verify( many_till( parser_with_context!(standard_set_object)(&parser_context), @@ -71,11 +77,11 @@ fn inline_footnote<'r, 's>( let (remaining, label_contents) = label(remaining)?; let (remaining, _) = tag(":")(remaining)?; let exit_with_depth = footnote_definition_end(remaining.get_bracket_depth()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Beta, - exit_matcher: &exit_with_depth, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + exit_matcher: &exit_with_depth, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, (children, _exit_contents)) = verify( many_till( parser_with_context!(standard_set_object)(&parser_context), @@ -119,10 +125,8 @@ fn footnote_reference_only<'r, 's>( )) } -fn footnote_definition_end( - starting_bracket_depth: BracketDepth, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { - move |context: Context, input: OrgSource<'_>| { +fn footnote_definition_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { + move |context, input: OrgSource<'_>| { _footnote_definition_end(context, input, starting_bracket_depth) } } diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 22a5018..eda0d65 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -13,17 +13,24 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::in_section; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ContextMatcher; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::element_parser::element; -use crate::parser::greater_element::GreaterBlock; use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; -use crate::parser::Element; -use crate::parser::Paragraph; +use crate::types::Element; +use crate::types::GreaterBlock; +use crate::types::Paragraph; +use crate::types::SetSource; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn greater_block<'r, 's>( @@ -55,13 +62,18 @@ pub fn greater_block<'r, 's>( let exit_with_name = greater_block_end(name.into()); let (remaining, parameters) = opt(tuple((space1, parameters)))(remaining)?; let (remaining, _nl) = line_ending(remaining)?; - let parser_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context(context_name.as_str())) - .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::Context(context_name.as_str()), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Alpha, exit_matcher: &exit_with_name, - })); + }), + ]; + let parser_context = context + .with_additional_node(&contexts[0]) + .with_additional_node(&contexts[1]) + .with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, @@ -114,19 +126,16 @@ fn parameters<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { is_not("\r\n")(input) } -fn greater_block_end<'x>( - name: &'x str, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { +fn greater_block_end<'c>(name: &'c str) -> impl ContextMatcher + 'c { // TODO: Can this be done without making an owned copy? - let name = name.to_owned(); - move |context: Context, input: OrgSource<'_>| _greater_block_end(context, input, name.as_str()) + move |context, input: OrgSource<'_>| _greater_block_end(context, input, name) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _greater_block_end<'r, 's, 'x>( +fn _greater_block_end<'r, 's, 'c>( _context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, - name: &'x str, + name: &'c str, ) -> Res, OrgSource<'s>> { start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; diff --git a/src/parser/inline_babel_call.rs b/src/parser/inline_babel_call.rs index e059f50..74bf9ca 100644 --- a/src/parser/inline_babel_call.rs +++ b/src/parser/inline_babel_call.rs @@ -12,12 +12,18 @@ use nom::multi::many_till; use super::org_source::BracketDepth; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ContextMatcher; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; -use crate::parser::InlineBabelCall; +use crate::types::InlineBabelCall; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn inline_babel_call<'r, 's>( @@ -45,11 +51,11 @@ fn name<'r, 's>( context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &name_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &name_end, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, name) = recognize(many_till( verify(anychar, |c| !(c.is_whitespace() || "[]()".contains(*c))), parser_with_context!(exit_matcher_parser)(&parser_context), @@ -73,11 +79,11 @@ fn header<'r, 's>( let (remaining, _) = tag("[")(input)?; let exit_with_depth = header_end(remaining.get_bracket_depth()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &exit_with_depth, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &exit_with_depth, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, name) = recognize(many_till( anychar, @@ -87,12 +93,8 @@ fn header<'r, 's>( Ok((remaining, name)) } -fn header_end( - starting_bracket_depth: BracketDepth, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { - move |context: Context, input: OrgSource<'_>| { - _header_end(context, input, starting_bracket_depth) - } +fn header_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { + move |context, input: OrgSource<'_>| _header_end(context, input, starting_bracket_depth) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -123,11 +125,11 @@ fn argument<'r, 's>( let (remaining, _) = tag("(")(input)?; let exit_with_depth = argument_end(remaining.get_parenthesis_depth()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &exit_with_depth, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + exit_matcher: &exit_with_depth, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, name) = recognize(many_till( anychar, @@ -137,12 +139,8 @@ fn argument<'r, 's>( Ok((remaining, name)) } -fn argument_end( - starting_parenthesis_depth: BracketDepth, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { - move |context: Context, input: OrgSource<'_>| { - _argument_end(context, input, starting_parenthesis_depth) - } +fn argument_end(starting_parenthesis_depth: BracketDepth) -> impl ContextMatcher { + move |context, input: OrgSource<'_>| _argument_end(context, input, starting_parenthesis_depth) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] diff --git a/src/parser/inline_source_block.rs b/src/parser/inline_source_block.rs index 132163f..cd1cad9 100644 --- a/src/parser/inline_source_block.rs +++ b/src/parser/inline_source_block.rs @@ -14,12 +14,18 @@ use tracing::span; use super::org_source::BracketDepth; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; +use crate::context::parser_with_context; +use crate::context::ContextElement; +use crate::context::ContextMatcher; +use crate::context::ExitClass; +use crate::context::ExitMatcherNode; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; -use crate::parser::InlineSourceBlock; +use crate::types::InlineSourceBlock; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn inline_source_block<'r, 's>( @@ -46,11 +52,11 @@ fn lang<'r, 's>( context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Beta, - exit_matcher: &lang_end, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + exit_matcher: &lang_end, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, lang) = recognize(many_till( verify(anychar, |c| !(c.is_whitespace() || "[{".contains(*c))), parser_with_context!(exit_matcher_parser)(&parser_context), @@ -74,11 +80,11 @@ fn header<'r, 's>( let (remaining, _) = tag("[")(input)?; let exit_with_depth = header_end(remaining.get_bracket_depth()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Beta, - exit_matcher: &exit_with_depth, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + exit_matcher: &exit_with_depth, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, header_contents) = recognize(many_till( anychar, @@ -88,12 +94,8 @@ fn header<'r, 's>( Ok((remaining, header_contents)) } -fn header_end( - starting_bracket_depth: BracketDepth, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { - move |context: Context, input: OrgSource<'_>| { - _header_end(context, input, starting_bracket_depth) - } +fn header_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { + move |context, input: OrgSource<'_>| _header_end(context, input, starting_bracket_depth) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -124,11 +126,11 @@ fn body<'r, 's>( let (remaining, _) = tag("{")(input)?; let exit_with_depth = body_end(remaining.get_brace_depth()); - let parser_context = - context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Beta, - exit_matcher: &exit_with_depth, - })); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + exit_matcher: &exit_with_depth, + }); + let parser_context = context.with_additional_node(&parser_context); let (remaining, body_contents) = recognize(many_till( anychar, @@ -148,10 +150,8 @@ fn body<'r, 's>( Ok((remaining, body_contents)) } -fn body_end( - starting_brace_depth: BracketDepth, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> { - move |context: Context, input: OrgSource<'_>| _body_end(context, input, starting_brace_depth) +fn body_end(starting_brace_depth: BracketDepth) -> impl ContextMatcher { + move |context, input: OrgSource<'_>| _body_end(context, input, starting_brace_depth) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] diff --git a/src/parser/latex_environment.rs b/src/parser/latex_environment.rs index a001e69..78299b0 100644 --- a/src/parser/latex_environment.rs +++ b/src/parser/latex_environment.rs @@ -46,7 +46,7 @@ pub fn latex_environment<'r, 's>( }); let parser_context = context.with_additional_node(&parser_context); - let (remaining, _contents) = contents(&latex_environment_end_specialized, context, remaining)?; + let (remaining, _contents) = contents(&latex_environment_end_specialized)(context, remaining)?; let (remaining, _end) = latex_environment_end_specialized(&parser_context, remaining)?; let source = get_consumed(input, remaining); @@ -63,16 +63,15 @@ fn name<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { take_while1(|c: char| c.is_alphanumeric() || c == '*')(input) } +fn contents(end_matcher: F) -> impl ContextMatcher { + move |context, input| _contents(&end_matcher, context, input) +} + #[cfg_attr( feature = "tracing", tracing::instrument(ret, level = "debug", skip(end_matcher)) )] -pub fn contents< - 'b, - 'r, - 's, - F: Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>, ->( +fn _contents<'b, 'r, 's, F: ContextMatcher>( end_matcher: F, context: RefContext<'b, 'r, 's>, input: OrgSource<'s>, @@ -81,7 +80,7 @@ pub fn contents< anychar, peek(alt(( parser_with_context!(exit_matcher_parser)(context), - parser_with_context!(end_matcher)(context), + parser_with_context!(&end_matcher)(context), ))), ))(input)?; diff --git a/src/parser/object_parser.rs b/src/parser/object_parser.rs index 084d526..1ae5189 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -4,7 +4,8 @@ use nom::combinator::map; use super::org_source::OrgSource; use super::plain_text::plain_text; use super::regular_link::regular_link; -use super::Context; +use crate::context::parser_with_context; +use crate::context::RefContext; use crate::error::Res; use crate::parser::angle_link::angle_link; use crate::parser::citation::citation; @@ -15,7 +16,6 @@ use crate::parser::inline_babel_call::inline_babel_call; use crate::parser::inline_source_block::inline_source_block; use crate::parser::latex_fragment::latex_fragment; use crate::parser::line_break::line_break; -use crate::parser::object::Object; use crate::parser::org_macro::org_macro; use crate::parser::plain_link::plain_link; use crate::parser::radio_link::radio_link; @@ -26,6 +26,7 @@ use crate::parser::subscript_and_superscript::superscript; use crate::parser::target::target; use crate::parser::text_markup::text_markup; use crate::parser::timestamp::timestamp; +use crate::types::Object; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn standard_set_object<'r, 's>( From 3bdb24ad88170ac3c5f83333f37c3f42207bc80b Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 3 Sep 2023 12:23:18 -0400 Subject: [PATCH 18/24] Fixing more errors. --- src/parser/clock.rs | 4 +++- src/parser/comment.rs | 4 +++- src/parser/diary_sexp.rs | 3 ++- src/parser/element_parser.rs | 14 +++++++++----- src/parser/entity.rs | 3 ++- src/parser/fixed_width_area.rs | 4 +++- src/parser/horizontal_rule.rs | 3 ++- src/parser/keyword.rs | 3 ++- src/parser/latex_fragment.rs | 14 +++++++++++--- src/parser/line_break.rs | 3 ++- src/parser/org_macro.rs | 5 +++-- src/parser/plain_list.rs | 1 + src/parser/plain_text.rs | 21 ++++++++++++++------- src/parser/planning.rs | 4 ++-- src/parser/statistics_cookie.rs | 5 +++-- 15 files changed, 62 insertions(+), 29 deletions(-) diff --git a/src/parser/clock.rs b/src/parser/clock.rs index 31af225..e527877 100644 --- a/src/parser/clock.rs +++ b/src/parser/clock.rs @@ -12,10 +12,12 @@ use nom::combinator::verify; use nom::sequence::tuple; use super::org_source::OrgSource; +use crate::context::parser_with_context; +use crate::context::RefContext; use crate::error::Res; use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; -use crate::parser::Clock; +use crate::types::Clock; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn clock<'r, 's>( diff --git a/src/parser/comment.rs b/src/parser/comment.rs index 545c6ec..74c3639 100644 --- a/src/parser/comment.rs +++ b/src/parser/comment.rs @@ -14,6 +14,7 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::get_consumed; use crate::context::parser_with_context; +use crate::context::ContextElement; use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; @@ -33,7 +34,8 @@ pub fn comment<'r, 's>( "Cannot nest objects of the same element".into(), )))); } - let parser_context = context.with_additional_node(ContextElement::Context("comment")); + let parser_context = ContextElement::Context("comment"); + let parser_context = context.with_additional_node(&parser_context); let comment_line_matcher = parser_with_context!(comment_line)(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); let (remaining, _first_line) = comment_line_matcher(input)?; diff --git a/src/parser/diary_sexp.rs b/src/parser/diary_sexp.rs index 9fb724e..862a0b8 100644 --- a/src/parser/diary_sexp.rs +++ b/src/parser/diary_sexp.rs @@ -11,10 +11,11 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::sexp::sexp; +use crate::context::RefContext; use crate::error::Res; use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; -use crate::parser::DiarySexp; +use crate::types::DiarySexp; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn diary_sexp<'r, 's>( diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index 18ec00b..dd5e012 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -7,7 +7,6 @@ use super::comment::comment; use super::diary_sexp::diary_sexp; use super::drawer::drawer; use super::dynamic_block::dynamic_block; -use super::element::Element; use super::fixed_width_area::fixed_width_area; use super::footnote_definition::footnote_definition; use super::greater_block::greater_block; @@ -26,15 +25,20 @@ use super::plain_list::detect_plain_list; use super::plain_list::plain_list; use super::util::get_consumed; use super::util::maybe_consume_trailing_whitespace_if_not_exiting; +use crate::context::parser_with_context; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::table::org_mode_table; +use crate::types::Element; +use crate::types::SetSource; pub const fn element( can_be_paragraph: bool, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, Element<'s>> { - move |context: Context, input: OrgSource<'_>| _element(context, input, can_be_paragraph) +) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, Element<'s>> +{ + move |context, input: OrgSource<'_>| _element(context, input, can_be_paragraph) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -115,8 +119,8 @@ fn _element<'r, 's>( pub const fn detect_element( can_be_paragraph: bool, -) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, ()> { - move |context: Context, input: OrgSource<'_>| _detect_element(context, input, can_be_paragraph) +) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, ()> { + move |context, input: OrgSource<'_>| _detect_element(context, input, can_be_paragraph) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] diff --git a/src/parser/entity.rs b/src/parser/entity.rs index dd29793..0752600 100644 --- a/src/parser/entity.rs +++ b/src/parser/entity.rs @@ -8,11 +8,12 @@ use nom::combinator::recognize; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; -use crate::parser::object::Entity; use crate::parser::util::get_consumed; +use crate::types::Entity; // TODO: Make this a user-provided variable corresponding to elisp's org-entities const ORG_ENTITIES: [&'static str; 413] = [ diff --git a/src/parser/fixed_width_area.rs b/src/parser/fixed_width_area.rs index 6a44d5b..03a144b 100644 --- a/src/parser/fixed_width_area.rs +++ b/src/parser/fixed_width_area.rs @@ -12,11 +12,13 @@ use nom::sequence::preceded; use nom::sequence::tuple; use super::org_source::OrgSource; +use crate::context::parser_with_context; +use crate::context::RefContext; use crate::error::Res; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; -use crate::parser::FixedWidthArea; +use crate::types::FixedWidthArea; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn fixed_width_area<'r, 's>( diff --git a/src/parser/horizontal_rule.rs b/src/parser/horizontal_rule.rs index 1429a91..fe75084 100644 --- a/src/parser/horizontal_rule.rs +++ b/src/parser/horizontal_rule.rs @@ -9,9 +9,10 @@ use nom::multi::many1_count; use nom::sequence::tuple; use super::org_source::OrgSource; +use crate::context::RefContext; use crate::error::Res; use crate::parser::util::start_of_line; -use crate::parser::HorizontalRule; +use crate::types::HorizontalRule; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn horizontal_rule<'r, 's>( diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index a3be43a..d68982b 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -16,11 +16,12 @@ use nom::sequence::tuple; use super::org_source::BracketDepth; use super::org_source::OrgSource; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::util::start_of_line; -use crate::parser::Keyword; +use crate::types::Keyword; const ORG_ELEMENT_AFFILIATED_KEYWORDS: [&'static str; 13] = [ "caption", "data", "header", "headers", "label", "name", "plot", "resname", "result", diff --git a/src/parser/latex_fragment.rs b/src/parser/latex_fragment.rs index 077c0c1..1da7fbd 100644 --- a/src/parser/latex_fragment.rs +++ b/src/parser/latex_fragment.rs @@ -14,12 +14,14 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; +use crate::context::parser_with_context; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; -use crate::parser::LatexFragment; +use crate::types::LatexFragment; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn latex_fragment<'r, 's>( @@ -172,7 +174,10 @@ fn dollar_char_fragment<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { +pub fn pre<'r, 's>( + _context: RefContext<'_, 'r, 's>, + input: OrgSource<'s>, +) -> Res, ()> { let preceding_character = input.get_preceding_character(); if let Some('$') = preceding_character { return Err(nom::Err::Error(CustomError::MyError(MyError( @@ -183,7 +188,10 @@ pub fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Re } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn post<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { +pub fn post<'r, 's>( + _context: RefContext<'_, 'r, 's>, + input: OrgSource<'s>, +) -> Res, ()> { // TODO: What about eof? Test to find out. // TODO: Figure out which punctuation characters should be included. diff --git a/src/parser/line_break.rs b/src/parser/line_break.rs index 8f2cb27..5ce792b 100644 --- a/src/parser/line_break.rs +++ b/src/parser/line_break.rs @@ -5,11 +5,12 @@ use nom::combinator::recognize; use nom::multi::many0; use super::org_source::OrgSource; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::util::get_consumed; -use crate::parser::LineBreak; +use crate::types::LineBreak; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn line_break<'r, 's>( diff --git a/src/parser/org_macro.rs b/src/parser/org_macro.rs index 71f2dd6..b23d246 100644 --- a/src/parser/org_macro.rs +++ b/src/parser/org_macro.rs @@ -9,12 +9,13 @@ use nom::multi::separated_list0; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; +use crate::context::parser_with_context; +use crate::context::RefContext; use crate::error::CustomError; use crate::error::Res; -use crate::parser::object::OrgMacro; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; +use crate::types::OrgMacro; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn org_macro<'r, 's>( diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 8960ec0..ceedd9a 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -373,6 +373,7 @@ mod tests { use crate::context::Context; use crate::context::GlobalSettings; use crate::context::List; + use crate::types::Source; #[test] fn plain_list_item_empty() { diff --git a/src/parser/plain_text.rs b/src/parser/plain_text.rs index 96f9c02..aeea58d 100644 --- a/src/parser/plain_text.rs +++ b/src/parser/plain_text.rs @@ -7,12 +7,15 @@ use nom::combinator::recognize; use nom::combinator::verify; use nom::multi::many_till; -use super::object::PlainText; +use super::object_parser::any_object_except_plain_text; use super::org_source::OrgSource; use super::radio_link::RematchObject; -use super::Context; -use super::Object; +use super::util::exit_matcher_parser; +use crate::context::parser_with_context; +use crate::context::RefContext; use crate::error::Res; +use crate::types::Object; +use crate::types::PlainText; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn plain_text<'r, 's>( @@ -66,14 +69,18 @@ mod tests { use nom::combinator::map; use super::*; - use crate::parser::parser_context::ContextTree; - use crate::parser::parser_with_context::parser_with_context; - use crate::parser::source::Source; + use crate::context::Context; + use crate::context::ContextElement; + use crate::context::GlobalSettings; + use crate::context::List; + use crate::types::Source; #[test] fn plain_text_simple() { let input = OrgSource::new("foobarbaz"); - let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); let plain_text_matcher = parser_with_context!(plain_text)(&initial_context); let (remaining, result) = map(plain_text_matcher, Object::PlainText)(input).unwrap(); assert_eq!(Into::<&str>::into(remaining), ""); diff --git a/src/parser/planning.rs b/src/parser/planning.rs index e2e76e1..5d9a7e4 100644 --- a/src/parser/planning.rs +++ b/src/parser/planning.rs @@ -10,11 +10,11 @@ use nom::multi::separated_list1; use nom::sequence::tuple; use super::org_source::OrgSource; -use super::Context; +use crate::context::RefContext; use crate::error::Res; -use crate::parser::lesser_element::Planning; use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; +use crate::types::Planning; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn planning<'r, 's>( diff --git a/src/parser/statistics_cookie.rs b/src/parser/statistics_cookie.rs index 3fd2287..f477ff0 100644 --- a/src/parser/statistics_cookie.rs +++ b/src/parser/statistics_cookie.rs @@ -5,9 +5,10 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; -use super::Context; +use crate::context::parser_with_context; +use crate::context::RefContext; use crate::error::Res; -use crate::parser::StatisticsCookie; +use crate::types::StatisticsCookie; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub fn statistics_cookie<'r, 's>( From 0b009511ff511439de176be6b9cdcf17e14cdb44 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 3 Sep 2023 12:28:45 -0400 Subject: [PATCH 19/24] Fixing more errors. --- src/parser/document.rs | 14 +++---- src/parser/drawer.rs | 7 ++-- src/parser/dynamic_block.rs | 7 ++-- src/parser/footnote_definition.rs | 8 ++-- src/parser/greater_block.rs | 7 ++-- src/parser/lesser_block.rs | 69 ++++++++++++++++--------------- src/parser/plain_list.rs | 12 +++--- src/parser/property_drawer.rs | 7 ++-- src/parser/table.rs | 7 ++-- 9 files changed, 66 insertions(+), 72 deletions(-) diff --git a/src/parser/document.rs b/src/parser/document.rs index 38dad44..5d923d7 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -118,10 +118,9 @@ fn zeroth_section<'r, 's>( exit_matcher: §ion_end, }), ]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); let without_consuming_whitespace_context = ContextElement::ConsumeTrailingWhitespace(false); let without_consuming_whitespace_context = parser_context.with_additional_node(&without_consuming_whitespace_context); @@ -178,10 +177,9 @@ fn section<'r, 's>( exit_matcher: §ion_end, }), ]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); let element_matcher = parser_with_context!(element(true))(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); let (mut remaining, (planning_element, property_drawer_element)) = tuple(( diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index 83246ac..0d1b140 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -58,10 +58,9 @@ pub fn drawer<'r, 's>( exit_matcher: &drawer_end, }), ]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); let element_matcher = parser_with_context!(element(true))(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); diff --git a/src/parser/dynamic_block.rs b/src/parser/dynamic_block.rs index 46a5387..504609d 100644 --- a/src/parser/dynamic_block.rs +++ b/src/parser/dynamic_block.rs @@ -58,10 +58,9 @@ pub fn dynamic_block<'r, 's>( exit_matcher: &dynamic_block_end, }), ]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index ec76833..767088e 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -51,10 +51,9 @@ pub fn footnote_definition<'r, 's>( exit_matcher: &footnote_definition_end, }), ]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); // TODO: The problem is we are not accounting for trailing whitespace like we do in section. Maybe it would be easier if we passed down whether or not to parse trailing whitespace into the element matcher similar to how tag takes in parameters. let element_matcher = parser_with_context!(element(true))(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); @@ -113,6 +112,7 @@ mod tests { use crate::context::Context; use crate::context::GlobalSettings; use crate::context::List; + use crate::types::Source; #[test] fn two_paragraphs() { diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index eda0d65..279d90a 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -70,10 +70,9 @@ pub fn greater_block<'r, 's>( exit_matcher: &exit_with_name, }), ]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index 65d5181..cd5fd94 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -12,9 +12,9 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::org_source::OrgSource; -use crate::context::ContextMatcher; use crate::context::parser_with_context; use crate::context::ContextElement; +use crate::context::ContextMatcher; use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; @@ -50,10 +50,9 @@ pub fn verse_block<'r, 's>( exit_matcher: &lesser_block_end_specialized, }), ]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, @@ -106,10 +105,9 @@ pub fn comment_block<'r, 's>( exit_matcher: &lesser_block_end_specialized, }), ]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, @@ -139,14 +137,17 @@ pub fn example_block<'r, 's>( let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?; let (remaining, _nl) = line_ending(remaining)?; let lesser_block_end_specialized = lesser_block_end("example"); - let contexts = [ContextElement::ConsumeTrailingWhitespace(true), ContextElement::Context("lesser block"), ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::Context("lesser block"), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Beta, exit_matcher: &lesser_block_end_specialized, - })]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + }), + ]; + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, @@ -177,14 +178,17 @@ pub fn export_block<'r, 's>( let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?; let (remaining, _nl) = line_ending(remaining)?; let lesser_block_end_specialized = lesser_block_end("export"); - let contexts = [ContextElement::ConsumeTrailingWhitespace(true), ContextElement::Context("lesser block"), ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::Context("lesser block"), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Beta, exit_matcher: &lesser_block_end_specialized, - })]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + }), + ]; + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, @@ -215,14 +219,17 @@ pub fn src_block<'r, 's>( let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?; let (remaining, _nl) = line_ending(remaining)?; let lesser_block_end_specialized = lesser_block_end("src"); - let contexts = [ContextElement::ConsumeTrailingWhitespace(true), ContextElement::Context("lesser block"), ContextElement::ExitMatcherNode(ExitMatcherNode { + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::Context("lesser block"), + ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Alpha, exit_matcher: &lesser_block_end_specialized, - })]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + }), + ]; + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); let parameters = match parameters { Some((_ws, parameters)) => Some(parameters), None => None, @@ -253,9 +260,7 @@ fn data<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { is_not("\r\n")(input) } -fn lesser_block_end( - current_name: &str, -) -> impl ContextMatcher { +fn lesser_block_end(current_name: &str) -> impl ContextMatcher { let current_name_lower = current_name.to_lowercase(); move |context, input: OrgSource<'_>| { _lesser_block_end(context, input, current_name_lower.as_str()) @@ -282,9 +287,7 @@ fn _lesser_block_end<'r, 's, 'x>( /// Parser for the beginning of a lesser block /// /// current_name MUST be lowercase. We do not do the conversion ourselves because it is not allowed in a const fn. -const fn lesser_block_begin<'c>( - current_name: &'c str, -) -> impl ContextMatcher + 'c { +const fn lesser_block_begin<'c>(current_name: &'c str) -> impl ContextMatcher + 'c { // TODO: Since this is a const fn, is there ANY way to "generate" functions at compile time? move |context, input: OrgSource<'_>| _lesser_block_begin(context, input, current_name) } diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index ceedd9a..0b7c37b 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -73,10 +73,9 @@ pub fn plain_list<'r, 's>( }), ]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); // children stores tuple of (input string, parsed object) so we can re-parse the final item let mut children = Vec::new(); let mut first_item_indentation: Option = None; @@ -182,9 +181,8 @@ pub fn plain_list_item<'r, 's>( exit_matcher: &exit_matcher, }), ]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]); + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); let (mut remaining, (mut children, _exit_contents)) = many_till( include_input(parser_with_context!(element(true))(&parser_context)), diff --git a/src/parser/property_drawer.rs b/src/parser/property_drawer.rs index d7a2850..a0d2ba2 100644 --- a/src/parser/property_drawer.rs +++ b/src/parser/property_drawer.rs @@ -59,10 +59,9 @@ pub fn property_drawer<'r, 's>( exit_matcher: &property_drawer_end, }), ]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); let node_property_matcher = parser_with_context!(node_property)(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); diff --git a/src/parser/table.rs b/src/parser/table.rs index a471890..84692db 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -46,10 +46,9 @@ pub fn org_mode_table<'r, 's>( exit_matcher: &table_end, }), ]; - let parser_context = context - .with_additional_node(&contexts[0]) - .with_additional_node(&contexts[1]) - .with_additional_node(&contexts[2]); + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = parser_context.with_additional_node(&contexts[2]); let org_mode_table_row_matcher = parser_with_context!(org_mode_table_row)(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); From 0d438a8e0f7956cc28848911da8af98288334f10 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 3 Sep 2023 12:45:12 -0400 Subject: [PATCH 20/24] Fixing more errors. --- src/context/global_settings.rs | 1 + src/context/mod.rs | 1 + src/parser/document.rs | 23 +++++++++++++++-------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/context/global_settings.rs b/src/context/global_settings.rs index a3ad30e..b5f818b 100644 --- a/src/context/global_settings.rs +++ b/src/context/global_settings.rs @@ -1,5 +1,6 @@ #[derive(Debug)] pub struct GlobalSettings<'s> { + #[allow(dead_code)] placeholder: Option<&'s str>, } diff --git a/src/context/mod.rs b/src/context/mod.rs index 247b2cf..9d9c362 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -12,6 +12,7 @@ pub trait ContextMatcher = for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>; pub type DynContextMatcher<'c> = dyn ContextMatcher + 'c; pub trait Matcher = for<'s> Fn(OrgSource<'s>) -> Res, OrgSource<'s>>; +#[allow(dead_code)] pub type DynMatcher<'c> = dyn Matcher + 'c; pub use exiting::ExitClass; diff --git a/src/parser/document.rs b/src/parser/document.rs index 5d923d7..4e752a0 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -17,7 +17,6 @@ use nom::multi::many_till; use nom::multi::separated_list1; use nom::sequence::tuple; -use super::org_source::convert_error; use super::org_source::OrgSource; use super::token::AllTokensIterator; use super::token::Token; @@ -54,9 +53,18 @@ pub fn document(input: &str) -> Res<&str, Document> { let initial_context = ContextElement::document_context(); let initial_context = Context::new(&global_settings, List::new(&initial_context)); let wrapped_input = OrgSource::new(input); - let (remaining, document) = _document(&initial_context, wrapped_input) - .map(|(rem, out)| (Into::<&str>::into(rem), out)) - .map_err(convert_error)?; + let _foo = double_pass_document(&initial_context, wrapped_input); + todo!() +} + +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[allow(dead_code)] +fn double_pass_document<'r, 's>( + context: RefContext<'_, 'r, 's>, + input: OrgSource<'s>, +) -> Res, Document<'s>> { + let (remaining, document) = + _document(context, input).map(|(rem, out)| (Into::<&str>::into(rem), out))?; { // If there are radio targets in this document then we need to parse the entire document again with the knowledge of the radio targets. let all_radio_targets: Vec<&Vec>> = document @@ -73,10 +81,9 @@ pub fn document(input: &str) -> Res<&str, Document> { .collect(); if !all_radio_targets.is_empty() { let parser_context = ContextElement::RadioTarget(all_radio_targets); - let parser_context = initial_context.with_additional_node(&parser_context); - let (remaining, document) = _document(&parser_context, wrapped_input) - .map(|(rem, out)| (Into::<&str>::into(rem), out)) - .map_err(convert_error)?; + let parser_context = context.with_additional_node(&parser_context); + let (remaining, document) = _document(&parser_context, input) + .map(|(rem, out)| (Into::<&str>::into(rem), out))?; return Ok((remaining.into(), document)); } } From d262833f9bad334494807a126e1e67122bca2ae8 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 3 Sep 2023 12:52:09 -0400 Subject: [PATCH 21/24] Fixing more errors. --- Cargo.toml | 2 +- src/compare/diff.rs | 116 ++++++++++++++++++++-------------------- src/compare/util.rs | 2 +- src/main.rs | 10 ++-- src/parser/document.rs | 6 +-- src/parser/mod.rs | 1 + src/parser/paragraph.rs | 1 + 7 files changed, 70 insertions(+), 68 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 638017e..aa83298 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ tracing-subscriber = { version = "0.3.17", optional = true, features = ["env-fil walkdir = "2.3.3" [features] -default = [] +default = ["compare"] compare = [] tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"] diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 3f6e3d3..4402200 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -5,64 +5,64 @@ use super::util::assert_name; use super::util::get_property; use crate::parser::sexp::unquote; use crate::parser::sexp::Token; -use crate::parser::AngleLink; -use crate::parser::Bold; -use crate::parser::Citation; -use crate::parser::CitationReference; -use crate::parser::Clock; -use crate::parser::Code; -use crate::parser::Comment; -use crate::parser::CommentBlock; -use crate::parser::DiarySexp; -use crate::parser::Document; -use crate::parser::DocumentElement; -use crate::parser::Drawer; -use crate::parser::DynamicBlock; -use crate::parser::Element; -use crate::parser::Entity; -use crate::parser::ExampleBlock; -use crate::parser::ExportBlock; -use crate::parser::ExportSnippet; -use crate::parser::FixedWidthArea; -use crate::parser::FootnoteDefinition; -use crate::parser::FootnoteReference; -use crate::parser::GreaterBlock; -use crate::parser::Heading; -use crate::parser::HorizontalRule; -use crate::parser::InlineBabelCall; -use crate::parser::InlineSourceBlock; -use crate::parser::Italic; -use crate::parser::Keyword; -use crate::parser::LatexEnvironment; -use crate::parser::LatexFragment; -use crate::parser::LineBreak; -use crate::parser::Object; -use crate::parser::OrgMacro; -use crate::parser::Paragraph; -use crate::parser::PlainLink; -use crate::parser::PlainList; -use crate::parser::PlainListItem; -use crate::parser::PlainText; -use crate::parser::Planning; -use crate::parser::PropertyDrawer; -use crate::parser::RadioLink; -use crate::parser::RadioTarget; -use crate::parser::RegularLink; -use crate::parser::Section; -use crate::parser::Source; -use crate::parser::SrcBlock; -use crate::parser::StatisticsCookie; -use crate::parser::StrikeThrough; -use crate::parser::Subscript; -use crate::parser::Superscript; -use crate::parser::Table; -use crate::parser::TableCell; -use crate::parser::TableRow; -use crate::parser::Target; -use crate::parser::Timestamp; -use crate::parser::Underline; -use crate::parser::Verbatim; -use crate::parser::VerseBlock; +use crate::types::AngleLink; +use crate::types::Bold; +use crate::types::Citation; +use crate::types::CitationReference; +use crate::types::Clock; +use crate::types::Code; +use crate::types::Comment; +use crate::types::CommentBlock; +use crate::types::DiarySexp; +use crate::types::Document; +use crate::types::DocumentElement; +use crate::types::Drawer; +use crate::types::DynamicBlock; +use crate::types::Element; +use crate::types::Entity; +use crate::types::ExampleBlock; +use crate::types::ExportBlock; +use crate::types::ExportSnippet; +use crate::types::FixedWidthArea; +use crate::types::FootnoteDefinition; +use crate::types::FootnoteReference; +use crate::types::GreaterBlock; +use crate::types::Heading; +use crate::types::HorizontalRule; +use crate::types::InlineBabelCall; +use crate::types::InlineSourceBlock; +use crate::types::Italic; +use crate::types::Keyword; +use crate::types::LatexEnvironment; +use crate::types::LatexFragment; +use crate::types::LineBreak; +use crate::types::Object; +use crate::types::OrgMacro; +use crate::types::Paragraph; +use crate::types::PlainLink; +use crate::types::PlainList; +use crate::types::PlainListItem; +use crate::types::PlainText; +use crate::types::Planning; +use crate::types::PropertyDrawer; +use crate::types::RadioLink; +use crate::types::RadioTarget; +use crate::types::RegularLink; +use crate::types::Section; +use crate::types::Source; +use crate::types::SrcBlock; +use crate::types::StatisticsCookie; +use crate::types::StrikeThrough; +use crate::types::Subscript; +use crate::types::Superscript; +use crate::types::Table; +use crate::types::TableCell; +use crate::types::TableRow; +use crate::types::Target; +use crate::types::Timestamp; +use crate::types::Underline; +use crate::types::Verbatim; +use crate::types::VerseBlock; #[derive(Debug)] pub enum DiffEntry<'s> { diff --git a/src/compare/util.rs b/src/compare/util.rs index 94c7451..6367bf9 100644 --- a/src/compare/util.rs +++ b/src/compare/util.rs @@ -1,5 +1,5 @@ use crate::parser::sexp::Token; -use crate::parser::Source; +use crate::types::Source; /// Check if the child string slice is a slice of the parent string slice. fn is_slice_of(parent: &str, child: &str) -> bool { diff --git a/src/main.rs b/src/main.rs index 968cd2d..1eff473 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::io::Read; use std::path::Path; -use ::organic::parser::document; +use ::organic::parser::parse; #[cfg(feature = "compare")] use organic::compare_document; #[cfg(feature = "compare")] @@ -68,7 +68,7 @@ fn run_anonymous_parse>(org_contents: P) -> Result<(), Box>(org_contents: P) -> Result<(), Box>(org_path: P) -> Result<(), Box>(org_path: P) -> Result<(), Box Res<&str, Document> { +pub fn parse(input: &str) -> Res<&str, Document> { let global_settings = GlobalSettings::default(); let initial_context = ContextElement::document_context(); let initial_context = Context::new(&global_settings, List::new(&initial_context)); let wrapped_input = OrgSource::new(input); - let _foo = double_pass_document(&initial_context, wrapped_input); + let _foo = document(&initial_context, wrapped_input); todo!() } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[allow(dead_code)] -fn double_pass_document<'r, 's>( +pub fn document<'r, 's>( context: RefContext<'_, 'r, 's>, input: OrgSource<'s>, ) -> Res, Document<'s>> { diff --git a/src/parser/mod.rs b/src/parser/mod.rs index bc3648d..eae8a04 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -43,4 +43,5 @@ mod timestamp; mod token; mod util; pub use document::document; +pub use document::parse; pub use org_source::OrgSource; diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index 643fb5c..86515d4 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -74,6 +74,7 @@ mod tests { use crate::context::List; use crate::parser::element_parser::element; use crate::parser::org_source::OrgSource; + use crate::types::Source; #[test] fn two_paragraphs() { From a7b9eb9db42876512a1239f4a0d8fc566ee88ba8 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 3 Sep 2023 12:58:46 -0400 Subject: [PATCH 22/24] Lifetime issue. --- src/parser/document.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/parser/document.rs b/src/parser/document.rs index 1cc2fbd..f509414 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -48,19 +48,21 @@ use crate::types::Section; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[allow(dead_code)] -pub fn parse(input: &str) -> Res<&str, Document> { +pub fn parse<'s>(input: &'s str) -> Result, String> { let global_settings = GlobalSettings::default(); let initial_context = ContextElement::document_context(); let initial_context = Context::new(&global_settings, List::new(&initial_context)); let wrapped_input = OrgSource::new(input); - let _foo = document(&initial_context, wrapped_input); - todo!() + let ret = document(&initial_context, wrapped_input) + .map_err(|err| err.to_string()) + .map(|(remaining, parsed_document)| parsed_document); + ret } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[allow(dead_code)] -pub fn document<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn document<'b, 'r, 's>( + context: RefContext<'b, 'r, 's>, input: OrgSource<'s>, ) -> Res, Document<'s>> { let (remaining, document) = From df79cbd0b73230b83b116f7fe7ccf71ed61bbcb6 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 3 Sep 2023 15:44:18 -0400 Subject: [PATCH 23/24] Give global options their own lifetime. --- Cargo.toml | 2 +- build.rs | 2 +- src/context/mod.rs | 8 ++- src/context/parser_context.rs | 22 +++---- src/main.rs | 14 ++--- src/parser/angle_link.rs | 12 ++-- src/parser/citation.rs | 26 ++++---- src/parser/citation_reference.rs | 24 ++++---- src/parser/clock.rs | 12 ++-- src/parser/comment.rs | 8 +-- src/parser/diary_sexp.rs | 4 +- src/parser/document.rs | 43 ++++++------- src/parser/drawer.rs | 8 +-- src/parser/dynamic_block.rs | 8 +-- src/parser/element_parser.rs | 17 +++--- src/parser/entity.rs | 8 +-- src/parser/export_snippet.rs | 16 ++--- src/parser/fixed_width_area.rs | 8 +-- src/parser/footnote_definition.rs | 8 +-- src/parser/footnote_reference.rs | 20 +++---- src/parser/greater_block.rs | 8 +-- src/parser/horizontal_rule.rs | 4 +- src/parser/inline_babel_call.rs | 28 ++++----- src/parser/inline_source_block.rs | 28 ++++----- src/parser/keyword.rs | 8 +-- src/parser/latex_environment.rs | 14 ++--- src/parser/latex_fragment.rs | 52 ++++++++-------- src/parser/lesser_block.rs | 32 +++++----- src/parser/line_break.rs | 9 ++- src/parser/object_parser.rs | 20 +++---- src/parser/org_macro.rs | 16 ++--- src/parser/paragraph.rs | 8 +-- src/parser/plain_link.rs | 26 ++++---- src/parser/plain_list.rs | 48 +++++++-------- src/parser/plain_text.rs | 12 ++-- src/parser/planning.rs | 4 +- src/parser/property_drawer.rs | 20 +++---- src/parser/radio_link.rs | 20 +++---- src/parser/regular_link.rs | 24 ++++---- src/parser/statistics_cookie.rs | 12 ++-- src/parser/subscript_and_superscript.rs | 47 ++++++++------- src/parser/table.rs | 28 ++++----- src/parser/target.rs | 8 +-- src/parser/text_markup.rs | 76 ++++++++++++----------- src/parser/timestamp.rs | 80 ++++++++++++------------- src/parser/util.rs | 29 +++++---- src/types/mod.rs | 2 +- tests/test_template | 3 +- 48 files changed, 470 insertions(+), 466 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa83298..638017e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ tracing-subscriber = { version = "0.3.17", optional = true, features = ["env-fil walkdir = "2.3.3" [features] -default = ["compare"] +default = [] compare = [] tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"] diff --git a/build.rs b/build.rs index d76733e..d920305 100644 --- a/build.rs +++ b/build.rs @@ -72,7 +72,7 @@ fn write_header(test_file: &mut File) { r#" #[feature(exit_status_error)] use organic::compare_document; -use organic::parser::document; +use organic::parser::parse; use organic::emacs_parse_anonymous_org_document; use organic::parser::sexp::sexp_with_padding; diff --git a/src/context/mod.rs b/src/context/mod.rs index 9d9c362..32e04f0 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -7,9 +7,11 @@ mod list; mod parser_context; mod parser_with_context; -pub type RefContext<'b, 'r, 's> = &'b Context<'r, 's>; -pub trait ContextMatcher = - for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>; +pub type RefContext<'b, 'g, 'r, 's> = &'b Context<'g, 'r, 's>; +pub trait ContextMatcher = for<'b, 'g, 'r, 's> Fn( + RefContext<'b, 'g, 'r, 's>, + OrgSource<'s>, +) -> Res, OrgSource<'s>>; pub type DynContextMatcher<'c> = dyn ContextMatcher + 'c; pub trait Matcher = for<'s> Fn(OrgSource<'s>) -> Res, OrgSource<'s>>; #[allow(dead_code)] diff --git a/src/context/parser_context.rs b/src/context/parser_context.rs index e5cc87b..34623b4 100644 --- a/src/context/parser_context.rs +++ b/src/context/parser_context.rs @@ -134,14 +134,14 @@ impl<'r> std::fmt::Debug for ExitMatcherNode<'r> { } #[derive(Debug)] -pub struct Context<'r, 's> { - global_settings: &'s GlobalSettings<'s>, +pub struct Context<'g, 'r, 's> { + global_settings: &'g GlobalSettings<'g>, tree: List<'r, &'r ContextElement<'r, 's>>, } -impl<'r, 's> Context<'r, 's> { +impl<'g, 'r, 's> Context<'g, 'r, 's> { pub fn new( - global_settings: &'s GlobalSettings<'s>, + global_settings: &'g GlobalSettings<'g>, tree: List<'r, &'r ContextElement<'r, 's>>, ) -> Self { Self { @@ -159,7 +159,7 @@ impl<'r, 's> Context<'r, 's> { self.tree.iter() } - pub fn iter_context(&'r self) -> Iter<'r, 's> { + pub fn iter_context(&'r self) -> Iter<'g, 'r, 's> { Iter { next: self.tree.iter_list(), global_settings: self.global_settings, @@ -225,20 +225,20 @@ impl<'r, 's> Context<'r, 's> { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn document_end<'b, 'r, 's>( - _context: RefContext<'b, 'r, 's>, +fn document_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { eof(input) } -pub struct Iter<'r, 's> { - global_settings: &'s GlobalSettings<'s>, +pub struct Iter<'g, 'r, 's> { + global_settings: &'g GlobalSettings<'g>, next: super::list::IterList<'r, &'r ContextElement<'r, 's>>, } -impl<'r, 's> Iterator for Iter<'r, 's> { - type Item = Context<'r, 's>; +impl<'g, 'r, 's> Iterator for Iter<'g, 'r, 's> { + type Item = Context<'g, 'r, 's>; fn next(&mut self) -> Option { let next_tree = self.next.next(); diff --git a/src/main.rs b/src/main.rs index 1eff473..edb1544 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,7 +68,7 @@ fn run_anonymous_parse>(org_contents: P) -> Result<(), Box>(org_contents: P) -> Result<(), Box>(org_contents: P) -> Result<(), Box>(org_path: P) -> Result<(), Box>(org_path: P) -> Result<(), Box>(org_path: P) -> Result<(), Box( - context: RefContext<'_, 'r, 's>, +pub fn angle_link<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, AngleLink<'s>> { let (remaining, _) = tag("<")(input)?; @@ -41,8 +41,8 @@ pub fn angle_link<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn path_angle<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn path_angle<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { @@ -58,8 +58,8 @@ fn path_angle<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn path_angle_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn path_angle_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { tag(">")(input) diff --git a/src/parser/citation.rs b/src/parser/citation.rs index 1b9f65c..d1ebdb2 100644 --- a/src/parser/citation.rs +++ b/src/parser/citation.rs @@ -31,8 +31,8 @@ use crate::types::Citation; use crate::types::Object; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn citation<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn citation<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Citation<'s>> { // TODO: Despite being a standard object, citations cannot exist inside the global prefix/suffix for other citations because citations must contain something that matches @key which is forbidden inside the global prefix/suffix. This TODO is to evaluate if its worth putting in an explicit check for this (which can be easily accomplished by checking the output of `get_bracket_depth()`). I suspect its not worth it because I expect, outside of intentionally crafted inputs, this parser will exit immediately inside a citation since it is unlikely to find the "[cite" substring inside a citation global prefix/suffix. @@ -61,7 +61,7 @@ pub fn citation<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn citestyle<'r, 's>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { +fn citestyle<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { let (remaining, _) = tuple((tag("/"), style))(input)?; let (remaining, _) = opt(tuple((tag("/"), variant)))(remaining)?; let source = get_consumed(input, remaining); @@ -69,22 +69,22 @@ fn citestyle<'r, 's>(input: OrgSource<'s>) -> Res, OrgSource<'s>> } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn style<'r, 's>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { +fn style<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { recognize(many1(verify(anychar, |c| { c.is_alphanumeric() || "_-".contains(*c) })))(input) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn variant<'r, 's>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { +fn variant<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { recognize(many1(verify(anychar, |c| { c.is_alphanumeric() || "_-/".contains(*c) })))(input) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn global_prefix<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn global_prefix<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = global_prefix_end(input.get_bracket_depth()); @@ -109,8 +109,8 @@ fn global_prefix_end(starting_bracket_depth: BracketDepth) -> impl ContextMatche } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _global_prefix_end<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn _global_prefix_end<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { @@ -132,8 +132,8 @@ fn _global_prefix_end<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn global_suffix<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn global_suffix<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = global_suffix_end(input.get_bracket_depth()); @@ -157,8 +157,8 @@ fn global_suffix_end(starting_bracket_depth: BracketDepth) -> impl ContextMatche } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _global_suffix_end<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn _global_suffix_end<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/citation_reference.rs b/src/parser/citation_reference.rs index 3a55adf..50697e2 100644 --- a/src/parser/citation_reference.rs +++ b/src/parser/citation_reference.rs @@ -29,8 +29,8 @@ use crate::types::CitationReference; use crate::types::Object; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn citation_reference<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn citation_reference<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, CitationReference<'s>> { let (remaining, _prefix) = @@ -49,8 +49,8 @@ pub fn citation_reference<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn citation_reference_key<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn citation_reference_key<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, source) = recognize(tuple(( @@ -69,8 +69,8 @@ pub fn citation_reference_key<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn key_prefix<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn key_prefix<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = key_prefix_end(input.get_bracket_depth()); @@ -90,8 +90,8 @@ fn key_prefix<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn key_suffix<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn key_suffix<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let exit_with_depth = key_suffix_end(input.get_bracket_depth()); @@ -115,8 +115,8 @@ fn key_prefix_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _key_prefix_end<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn _key_prefix_end<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { @@ -142,8 +142,8 @@ fn key_suffix_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _key_suffix_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn _key_suffix_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/clock.rs b/src/parser/clock.rs index e527877..7f13d25 100644 --- a/src/parser/clock.rs +++ b/src/parser/clock.rs @@ -20,8 +20,8 @@ use crate::parser::util::start_of_line; use crate::types::Clock; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn clock<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn clock<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Clock<'s>> { start_of_line(input)?; @@ -44,8 +44,8 @@ pub fn clock<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn inactive_timestamp_range_duration<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn inactive_timestamp_range_duration<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( @@ -66,8 +66,8 @@ fn inactive_timestamp_range_duration<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn inactive_timestamp<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn inactive_timestamp<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( diff --git a/src/parser/comment.rs b/src/parser/comment.rs index 74c3639..a6d539c 100644 --- a/src/parser/comment.rs +++ b/src/parser/comment.rs @@ -25,8 +25,8 @@ use crate::parser::util::start_of_line; use crate::types::Comment; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn comment<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn comment<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Comment<'s>> { if immediate_in_section(context, "comment") { @@ -52,8 +52,8 @@ pub fn comment<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn comment_line<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn comment_line<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; diff --git a/src/parser/diary_sexp.rs b/src/parser/diary_sexp.rs index 862a0b8..abadd4d 100644 --- a/src/parser/diary_sexp.rs +++ b/src/parser/diary_sexp.rs @@ -18,8 +18,8 @@ use crate::parser::util::start_of_line; use crate::types::DiarySexp; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn diary_sexp<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn diary_sexp<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, DiarySexp<'s>> { start_of_line(input)?; diff --git a/src/parser/document.rs b/src/parser/document.rs index f509414..3b467a2 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -4,6 +4,7 @@ use nom::character::complete::anychar; use nom::character::complete::line_ending; use nom::character::complete::space0; use nom::character::complete::space1; +use nom::combinator::all_consuming; use nom::combinator::eof; use nom::combinator::map; use nom::combinator::not; @@ -53,16 +54,16 @@ pub fn parse<'s>(input: &'s str) -> Result, String> { let initial_context = ContextElement::document_context(); let initial_context = Context::new(&global_settings, List::new(&initial_context)); let wrapped_input = OrgSource::new(input); - let ret = document(&initial_context, wrapped_input) + let ret = all_consuming(parser_with_context!(document)(&initial_context))(wrapped_input) .map_err(|err| err.to_string()) - .map(|(remaining, parsed_document)| parsed_document); + .map(|(_remaining, parsed_document)| parsed_document); ret } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[allow(dead_code)] -pub fn document<'b, 'r, 's>( - context: RefContext<'b, 'r, 's>, +pub fn document<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Document<'s>> { let (remaining, document) = @@ -93,8 +94,8 @@ pub fn document<'b, 'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _document<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn _document<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Document<'s>> { let zeroth_section_matcher = parser_with_context!(zeroth_section)(context); @@ -114,8 +115,8 @@ fn _document<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn zeroth_section<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn zeroth_section<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Section<'s>> { // TODO: The zeroth section is specialized so it probably needs its own parser @@ -173,8 +174,8 @@ fn zeroth_section<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn section<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn section<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, mut input: OrgSource<'s>, ) -> Res, Section<'s>> { // TODO: The zeroth section is specialized so it probably needs its own parser @@ -227,8 +228,8 @@ fn section<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn section_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn section_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(detect_headline)(input) @@ -236,14 +237,16 @@ fn section_end<'r, 's>( const fn heading( parent_stars: usize, -) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, Heading<'s>> -{ +) -> impl for<'b, 'g, 'r, 's> Fn( + RefContext<'b, 'g, 'r, 's>, + OrgSource<'s>, +) -> Res, Heading<'s>> { move |context, input: OrgSource<'_>| _heading(context, input, parent_stars) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _heading<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn _heading<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, parent_stars: usize, ) -> Res, Heading<'s>> { @@ -289,8 +292,8 @@ fn detect_headline<'s>(input: OrgSource<'s>) -> Res, ()> { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn headline<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn headline<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, parent_stars: usize, ) -> Res< @@ -344,8 +347,8 @@ fn headline<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn headline_title_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn headline_title_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index 0d1b140..1cdabe2 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -32,8 +32,8 @@ use crate::types::Paragraph; use crate::types::SetSource; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn drawer<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn drawer<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Drawer<'s>> { if immediate_in_section(context, "drawer") { @@ -102,8 +102,8 @@ fn name<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn drawer_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn drawer_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; diff --git a/src/parser/dynamic_block.rs b/src/parser/dynamic_block.rs index 504609d..083b26c 100644 --- a/src/parser/dynamic_block.rs +++ b/src/parser/dynamic_block.rs @@ -32,8 +32,8 @@ use crate::types::Paragraph; use crate::types::SetSource; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn dynamic_block<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn dynamic_block<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, DynamicBlock<'s>> { // TODO: Do I need to differentiate between different dynamic block types. @@ -110,8 +110,8 @@ fn parameters<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn dynamic_block_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn dynamic_block_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index dd5e012..fe20fa1 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -36,14 +36,16 @@ use crate::types::SetSource; pub const fn element( can_be_paragraph: bool, -) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, Element<'s>> -{ +) -> impl for<'b, 'g, 'r, 's> Fn( + RefContext<'b, 'g, 'r, 's>, + OrgSource<'s>, +) -> Res, Element<'s>> { move |context, input: OrgSource<'_>| _element(context, input, can_be_paragraph) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _element<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn _element<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, can_be_paragraph: bool, ) -> Res, Element<'s>> { @@ -119,13 +121,14 @@ fn _element<'r, 's>( pub const fn detect_element( can_be_paragraph: bool, -) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, ()> { +) -> impl for<'b, 'g, 'r, 's> Fn(RefContext<'b, 'g, 'r, 's>, OrgSource<'s>) -> Res, ()> +{ move |context, input: OrgSource<'_>| _detect_element(context, input, can_be_paragraph) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _detect_element<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn _detect_element<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, can_be_paragraph: bool, ) -> Res, ()> { diff --git a/src/parser/entity.rs b/src/parser/entity.rs index 0752600..ca8403a 100644 --- a/src/parser/entity.rs +++ b/src/parser/entity.rs @@ -433,8 +433,8 @@ const ORG_ENTITIES: [&'static str; 413] = [ ]; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn entity<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn entity<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Entity<'s>> { let (remaining, _) = tag("\\")(input)?; @@ -454,8 +454,8 @@ pub fn entity<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn name<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn name<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // TODO: This should be defined by org-entities and optionally org-entities-user diff --git a/src/parser/export_snippet.rs b/src/parser/export_snippet.rs index 23d1251..2b40619 100644 --- a/src/parser/export_snippet.rs +++ b/src/parser/export_snippet.rs @@ -20,8 +20,8 @@ use crate::parser::util::get_consumed; use crate::types::ExportSnippet; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn export_snippet<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn export_snippet<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ExportSnippet<'s>> { let (remaining, _) = tag("@@")(input)?; @@ -50,8 +50,8 @@ pub fn export_snippet<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn backend<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn backend<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, backend_name) = @@ -61,8 +61,8 @@ fn backend<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn contents<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn contents<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, source) = recognize(verify( @@ -73,8 +73,8 @@ fn contents<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn export_snippet_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn export_snippet_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { tag("@@")(input) diff --git a/src/parser/fixed_width_area.rs b/src/parser/fixed_width_area.rs index 03a144b..b579ced 100644 --- a/src/parser/fixed_width_area.rs +++ b/src/parser/fixed_width_area.rs @@ -21,8 +21,8 @@ use crate::parser::util::start_of_line; use crate::types::FixedWidthArea; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn fixed_width_area<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn fixed_width_area<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, FixedWidthArea<'s>> { let fixed_width_area_line_matcher = parser_with_context!(fixed_width_area_line)(context); @@ -41,8 +41,8 @@ pub fn fixed_width_area<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn fixed_width_area_line<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn fixed_width_area_line<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 767088e..e413d9d 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -30,8 +30,8 @@ use crate::parser::util::start_of_line; use crate::types::FootnoteDefinition; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn footnote_definition<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn footnote_definition<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteDefinition<'s>> { if immediate_in_section(context, "footnote definition") { @@ -80,8 +80,8 @@ pub fn label<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn footnote_definition_end<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn footnote_definition_end<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, source) = alt(( diff --git a/src/parser/footnote_reference.rs b/src/parser/footnote_reference.rs index bea3d94..0f3738c 100644 --- a/src/parser/footnote_reference.rs +++ b/src/parser/footnote_reference.rs @@ -23,8 +23,8 @@ use crate::parser::util::get_consumed; use crate::types::FootnoteReference; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn footnote_reference<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn footnote_reference<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteReference<'s>> { alt(( @@ -35,8 +35,8 @@ pub fn footnote_reference<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn anonymous_footnote<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn anonymous_footnote<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteReference<'s>> { let (remaining, _) = tag_no_case("[fn::")(input)?; @@ -69,8 +69,8 @@ fn anonymous_footnote<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn inline_footnote<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn inline_footnote<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteReference<'s>> { let (remaining, _) = tag_no_case("[fn:")(input)?; @@ -105,8 +105,8 @@ fn inline_footnote<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn footnote_reference_only<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn footnote_reference_only<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, FootnoteReference<'s>> { let (remaining, _) = tag_no_case("[fn:")(input)?; @@ -132,8 +132,8 @@ fn footnote_definition_end(starting_bracket_depth: BracketDepth) -> impl Context } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _footnote_definition_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn _footnote_definition_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 279d90a..8e973de 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -33,8 +33,8 @@ use crate::types::Paragraph; use crate::types::SetSource; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn greater_block<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn greater_block<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, GreaterBlock<'s>> { // TODO: Do I need to differentiate between different greater block types. @@ -131,8 +131,8 @@ fn greater_block_end<'c>(name: &'c str) -> impl ContextMatcher + 'c { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _greater_block_end<'r, 's, 'c>( - _context: RefContext<'_, 'r, 's>, +fn _greater_block_end<'b, 'g, 'r, 's, 'c>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, name: &'c str, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/horizontal_rule.rs b/src/parser/horizontal_rule.rs index fe75084..c4c054a 100644 --- a/src/parser/horizontal_rule.rs +++ b/src/parser/horizontal_rule.rs @@ -15,8 +15,8 @@ use crate::parser::util::start_of_line; use crate::types::HorizontalRule; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn horizontal_rule<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn horizontal_rule<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, HorizontalRule<'s>> { start_of_line(input)?; diff --git a/src/parser/inline_babel_call.rs b/src/parser/inline_babel_call.rs index 74bf9ca..78cc953 100644 --- a/src/parser/inline_babel_call.rs +++ b/src/parser/inline_babel_call.rs @@ -26,8 +26,8 @@ use crate::parser::util::get_consumed; use crate::types::InlineBabelCall; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn inline_babel_call<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn inline_babel_call<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, InlineBabelCall<'s>> { let (remaining, _) = tag_no_case("call_")(input)?; @@ -47,8 +47,8 @@ pub fn inline_babel_call<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn name<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn name<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { @@ -64,16 +64,16 @@ fn name<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn name_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn name_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(one_of("[("))(input) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn header<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn header<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("[")(input)?; @@ -98,8 +98,8 @@ fn header_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _header_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn _header_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { @@ -118,8 +118,8 @@ fn _header_end<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn argument<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn argument<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("(")(input)?; @@ -144,8 +144,8 @@ fn argument_end(starting_parenthesis_depth: BracketDepth) -> impl ContextMatcher } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _argument_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn _argument_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, starting_parenthesis_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/inline_source_block.rs b/src/parser/inline_source_block.rs index cd1cad9..4589124 100644 --- a/src/parser/inline_source_block.rs +++ b/src/parser/inline_source_block.rs @@ -28,8 +28,8 @@ use crate::parser::util::get_consumed; use crate::types::InlineSourceBlock; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn inline_source_block<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn inline_source_block<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, InlineSourceBlock<'s>> { let (remaining, _) = tag_no_case("src_")(input)?; @@ -48,8 +48,8 @@ pub fn inline_source_block<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn lang<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn lang<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { @@ -65,16 +65,16 @@ fn lang<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn lang_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn lang_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(one_of("[{"))(input) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn header<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn header<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("[")(input)?; @@ -99,8 +99,8 @@ fn header_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _header_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn _header_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, starting_bracket_depth: BracketDepth, ) -> Res, OrgSource<'s>> { @@ -119,8 +119,8 @@ fn _header_end<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn body<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn body<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("{")(input)?; @@ -155,8 +155,8 @@ fn body_end(starting_brace_depth: BracketDepth) -> impl ContextMatcher { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _body_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn _body_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, starting_brace_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index d68982b..ee7a22d 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -30,8 +30,8 @@ const ORG_ELEMENT_AFFILIATED_KEYWORDS: [&'static str; 13] = [ const ORG_ELEMENT_DUAL_KEYWORDS: [&'static str; 2] = ["caption", "results"]; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn keyword<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn keyword<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Keyword<'s>> { start_of_line(input)?; @@ -55,8 +55,8 @@ pub fn keyword<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn affiliated_keyword<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn affiliated_keyword<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Keyword<'s>> { start_of_line(input)?; diff --git a/src/parser/latex_environment.rs b/src/parser/latex_environment.rs index 78299b0..a5d379a 100644 --- a/src/parser/latex_environment.rs +++ b/src/parser/latex_environment.rs @@ -25,8 +25,8 @@ use crate::parser::util::start_of_line; use crate::types::LatexEnvironment; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn latex_environment<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn latex_environment<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, LatexEnvironment<'s>> { start_of_line(input)?; @@ -71,9 +71,9 @@ fn contents(end_matcher: F) -> impl ContextMatcher { feature = "tracing", tracing::instrument(ret, level = "debug", skip(end_matcher)) )] -fn _contents<'b, 'r, 's, F: ContextMatcher>( +fn _contents<'b, 'g, 'r, 's, F: ContextMatcher>( end_matcher: F, - context: RefContext<'b, 'r, 's>, + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, source) = recognize(many_till( @@ -95,10 +95,10 @@ fn latex_environment_end(current_name: &str) -> impl ContextMatcher { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _latex_environment_end<'r, 's, 'x>( - _context: RefContext<'_, 'r, 's>, +fn _latex_environment_end<'b, 'g, 'r, 's, 'c>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, - current_name_lower: &'x str, + current_name_lower: &'c str, ) -> Res, OrgSource<'s>> { start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; diff --git a/src/parser/latex_fragment.rs b/src/parser/latex_fragment.rs index 1da7fbd..7a142d2 100644 --- a/src/parser/latex_fragment.rs +++ b/src/parser/latex_fragment.rs @@ -24,8 +24,8 @@ use crate::parser::util::get_consumed; use crate::types::LatexFragment; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn latex_fragment<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn latex_fragment<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, LatexFragment<'s>> { let (remaining, _) = alt(( @@ -48,8 +48,8 @@ pub fn latex_fragment<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn raw_latex_fragment<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn raw_latex_fragment<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("\\")(input)?; @@ -61,16 +61,16 @@ fn raw_latex_fragment<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn name<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn name<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alpha1(input) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn brackets<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn brackets<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, body) = alt(( @@ -101,8 +101,8 @@ fn brackets<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn escaped_parenthesis_fragment<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn escaped_parenthesis_fragment<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("\\(")(input)?; @@ -120,8 +120,8 @@ fn escaped_parenthesis_fragment<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn escaped_bracket_fragment<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn escaped_bracket_fragment<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = tag("\\[")(input)?; @@ -139,8 +139,8 @@ fn escaped_bracket_fragment<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn double_dollar_fragment<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn double_dollar_fragment<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // TODO: The documentation on the dollar sign versions is incomplete. Test to figure out what the real requirements are. For example, can this span more than 3 lines and can this contain a single $ since its terminated by $$? @@ -159,8 +159,8 @@ fn double_dollar_fragment<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn dollar_char_fragment<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn dollar_char_fragment<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (_, _) = pre(context, input)?; @@ -174,8 +174,8 @@ fn dollar_char_fragment<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn pre<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn pre<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> { let preceding_character = input.get_preceding_character(); @@ -188,8 +188,8 @@ pub fn pre<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn post<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn post<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> { // TODO: What about eof? Test to find out. @@ -200,8 +200,8 @@ pub fn post<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn bordered_dollar_fragment<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn bordered_dollar_fragment<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (_, _) = pre(context, input)?; @@ -226,16 +226,16 @@ fn bordered_dollar_fragment<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn open_border<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn open_border<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(verify(none_of(".,;$"), |c| !c.is_whitespace()))(input) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn close_border<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn close_border<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> { let preceding_character = input.get_preceding_character(); diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index cd5fd94..0caaca0 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -34,8 +34,8 @@ use crate::types::SrcBlock; use crate::types::VerseBlock; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn verse_block<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn verse_block<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, VerseBlock<'s>> { let (remaining, name) = lesser_block_begin("verse")(context, input)?; @@ -89,8 +89,8 @@ pub fn verse_block<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn comment_block<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn comment_block<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, CommentBlock<'s>> { let (remaining, name) = lesser_block_begin("comment")(context, input)?; @@ -129,8 +129,8 @@ pub fn comment_block<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn example_block<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn example_block<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ExampleBlock<'s>> { let (remaining, _name) = lesser_block_begin("example")(context, input)?; @@ -169,8 +169,8 @@ pub fn example_block<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn export_block<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn export_block<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ExportBlock<'s>> { let (remaining, name) = lesser_block_begin("export")(context, input)?; @@ -210,8 +210,8 @@ pub fn export_block<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn src_block<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn src_block<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, SrcBlock<'s>> { let (remaining, name) = lesser_block_begin("src")(context, input)?; @@ -268,10 +268,10 @@ fn lesser_block_end(current_name: &str) -> impl ContextMatcher { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _lesser_block_end<'r, 's, 'x>( - _context: RefContext<'_, 'r, 's>, +fn _lesser_block_end<'b, 'g, 'r, 's, 'c>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, - current_name_lower: &'x str, + current_name_lower: &'c str, ) -> Res, OrgSource<'s>> { start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; @@ -293,10 +293,10 @@ const fn lesser_block_begin<'c>(current_name: &'c str) -> impl ContextMatcher + } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _lesser_block_begin<'r, 's, 'x>( - _context: RefContext<'_, 'r, 's>, +fn _lesser_block_begin<'b, 'g, 'r, 's, 'c>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, - current_name_lower: &'x str, + current_name_lower: &'c str, ) -> Res, OrgSource<'s>> { start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; diff --git a/src/parser/line_break.rs b/src/parser/line_break.rs index 5ce792b..a0c721a 100644 --- a/src/parser/line_break.rs +++ b/src/parser/line_break.rs @@ -13,8 +13,8 @@ use crate::parser::util::get_consumed; use crate::types::LineBreak; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn line_break<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn line_break<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, LineBreak<'s>> { let (remaining, _) = pre(context, input)?; @@ -31,7 +31,10 @@ pub fn line_break<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { +fn pre<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, +) -> Res, ()> { let preceding_character = input.get_preceding_character(); match preceding_character { // If None, we are at the start of the file diff --git a/src/parser/object_parser.rs b/src/parser/object_parser.rs index 1ae5189..e3db553 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -29,8 +29,8 @@ use crate::parser::timestamp::timestamp; use crate::types::Object; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn standard_set_object<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn standard_set_object<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, object) = alt(( @@ -87,8 +87,8 @@ pub fn standard_set_object<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn minimal_set_object<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn minimal_set_object<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, object) = alt(( @@ -109,8 +109,8 @@ pub fn minimal_set_object<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn any_object_except_plain_text<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn any_object_except_plain_text<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, object) = alt(( @@ -166,8 +166,8 @@ pub fn any_object_except_plain_text<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn regular_link_description_object_set<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn regular_link_description_object_set<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { // TODO: It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]] @@ -195,8 +195,8 @@ pub fn regular_link_description_object_set<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn table_cell_set_object<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn table_cell_set_object<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, object) = alt(( diff --git a/src/parser/org_macro.rs b/src/parser/org_macro.rs index b23d246..cf89c3b 100644 --- a/src/parser/org_macro.rs +++ b/src/parser/org_macro.rs @@ -18,8 +18,8 @@ use crate::parser::util::get_consumed; use crate::types::OrgMacro; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn org_macro<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn org_macro<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgMacro<'s>> { let (remaining, _) = tag("{{{")(input)?; @@ -45,8 +45,8 @@ pub fn org_macro<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn org_macro_name<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn org_macro_name<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _) = verify(anychar, |c| c.is_alphabetic())(input)?; @@ -58,8 +58,8 @@ fn org_macro_name<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn org_macro_args<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn org_macro_args<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let (remaining, _) = tag("(")(input)?; @@ -71,8 +71,8 @@ fn org_macro_args<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn org_macro_arg<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn org_macro_arg<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let mut remaining = input; diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index 86515d4..2f7345a 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -22,8 +22,8 @@ use crate::parser::util::start_of_line; use crate::types::Paragraph; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn paragraph<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn paragraph<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Paragraph<'s>> { let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { @@ -53,8 +53,8 @@ pub fn paragraph<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn paragraph_end<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn paragraph_end<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let non_paragraph_element_matcher = parser_with_context!(detect_element(false))(context); diff --git a/src/parser/plain_link.rs b/src/parser/plain_link.rs index 2515aff..0c7735a 100644 --- a/src/parser/plain_link.rs +++ b/src/parser/plain_link.rs @@ -52,8 +52,8 @@ const ORG_LINK_PARAMETERS: [&'static str; 23] = [ ]; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn plain_link<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn plain_link<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, PlainLink<'s>> { let (remaining, _) = pre(context, input)?; @@ -73,7 +73,10 @@ pub fn plain_link<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { +fn pre<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, +) -> Res, ()> { let preceding_character = input.get_preceding_character(); match preceding_character { // If None, we are at the start of the file which is fine @@ -90,14 +93,17 @@ fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { +fn post<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, +) -> Res, ()> { let (remaining, _) = alt((eof, recognize(none_of(WORD_CONSTITUENT_CHARACTERS))))(input)?; Ok((remaining, ())) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn protocol<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn protocol<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // TODO: This should be defined by org-link-parameters @@ -117,8 +123,8 @@ pub fn protocol<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn path_plain<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn path_plain<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // TODO: "optionally containing parenthesis-wrapped non-whitespace non-bracket substrings up to a depth of two. The string must end with either a non-punctation non-whitespace character, a forwards slash, or a parenthesis-wrapped substring" @@ -139,8 +145,8 @@ fn path_plain<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn path_plain_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn path_plain_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(many_till( diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 0b7c37b..f387951 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -22,6 +22,7 @@ use super::org_source::OrgSource; use super::util::non_whitespace_character; use crate::context::parser_with_context; use crate::context::ContextElement; +use crate::context::ContextMatcher; use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; @@ -60,8 +61,8 @@ pub fn detect_plain_list<'s>(input: OrgSource<'s>) -> Res, ()> { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn plain_list<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn plain_list<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, PlainList<'s>> { let contexts = [ @@ -134,8 +135,8 @@ pub fn plain_list<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn plain_list_item<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn plain_list_item<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, PlainListItem<'s>> { start_of_line(input)?; @@ -248,8 +249,8 @@ fn counter<'s>(i: OrgSource<'s>) -> Res, OrgSource<'s>> { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn plain_list_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn plain_list_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( @@ -260,10 +261,7 @@ fn plain_list_end<'r, 's>( )))(input) } -const fn plain_list_item_end( - indent_level: usize, -) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> -{ +const fn plain_list_item_end(indent_level: usize) -> impl ContextMatcher { let line_indented_lte_matcher = line_indented_lte(indent_level); move |context, input: OrgSource<'_>| { _plain_list_item_end(context, input, &line_indented_lte_matcher) @@ -274,13 +272,10 @@ const fn plain_list_item_end( feature = "tracing", tracing::instrument(ret, level = "debug", skip(line_indented_lte_matcher)) )] -fn _plain_list_item_end<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn _plain_list_item_end<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, - line_indented_lte_matcher: impl for<'bb, 'rr, 'ss> Fn( - RefContext<'bb, 'rr, 'ss>, - OrgSource<'ss>, - ) -> Res, OrgSource<'ss>>, + line_indented_lte_matcher: impl ContextMatcher, ) -> Res, OrgSource<'s>> { start_of_line(input)?; recognize(tuple(( @@ -289,16 +284,13 @@ fn _plain_list_item_end<'r, 's>( )))(input) } -const fn line_indented_lte( - indent_level: usize, -) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> -{ +const fn line_indented_lte(indent_level: usize) -> impl ContextMatcher { move |context, input: OrgSource<'_>| _line_indented_lte(context, input, indent_level) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _line_indented_lte<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn _line_indented_lte<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, indent_level: usize, ) -> Res, OrgSource<'s>> { @@ -312,8 +304,8 @@ fn _line_indented_lte<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn item_tag<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn item_tag<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { @@ -333,8 +325,8 @@ fn item_tag<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn item_tag_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn item_tag_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(alt(( @@ -345,8 +337,8 @@ fn item_tag_end<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn item_tag_post_gap<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn item_tag_post_gap<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { verify( diff --git a/src/parser/plain_text.rs b/src/parser/plain_text.rs index aeea58d..1dbc295 100644 --- a/src/parser/plain_text.rs +++ b/src/parser/plain_text.rs @@ -18,8 +18,8 @@ use crate::types::Object; use crate::types::PlainText; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn plain_text<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn plain_text<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, PlainText<'s>> { let (remaining, source) = recognize(verify( @@ -42,8 +42,8 @@ pub fn plain_text<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn plain_text_end<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn plain_text_end<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(parser_with_context!(any_object_except_plain_text)(context))(input) @@ -51,9 +51,9 @@ fn plain_text_end<'r, 's>( impl<'x> RematchObject<'x> for PlainText<'x> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] - fn rematch_object<'r, 's>( + fn rematch_object<'b, 'g, 'r, 's>( &'x self, - _context: RefContext<'_, 'r, 's>, + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { map(tag(self.source), |s| { diff --git a/src/parser/planning.rs b/src/parser/planning.rs index 5d9a7e4..77e70c1 100644 --- a/src/parser/planning.rs +++ b/src/parser/planning.rs @@ -17,8 +17,8 @@ use crate::parser::util::start_of_line; use crate::types::Planning; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn planning<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn planning<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Planning<'s>> { start_of_line(input)?; diff --git a/src/parser/property_drawer.rs b/src/parser/property_drawer.rs index a0d2ba2..ca0938f 100644 --- a/src/parser/property_drawer.rs +++ b/src/parser/property_drawer.rs @@ -31,8 +31,8 @@ use crate::types::NodeProperty; use crate::types::PropertyDrawer; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn property_drawer<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn property_drawer<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, PropertyDrawer<'s>> { if immediate_in_section(context, "property-drawer") { @@ -83,8 +83,8 @@ pub fn property_drawer<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn property_drawer_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn property_drawer_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple(( @@ -97,8 +97,8 @@ fn property_drawer_end<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn node_property<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn node_property<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, NodeProperty<'s>> { let (remaining, (_start_of_line, _leading_whitespace, _open_colon, _name, _close_colon)) = @@ -140,8 +140,8 @@ fn node_property<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn node_property_name<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn node_property_name<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { @@ -165,8 +165,8 @@ fn node_property_name<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn node_property_name_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn node_property_name_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt((tag("+:"), tag(":")))(input) diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index 977d8d9..ec1e444 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -23,8 +23,8 @@ use crate::types::RadioLink; use crate::types::RadioTarget; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn radio_link<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn radio_link<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, RadioLink<'s>> { let radio_targets = context @@ -54,8 +54,8 @@ pub fn radio_link<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn rematch_target<'x, 'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn rematch_target<'x, 'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, target: &'x Vec>, input: OrgSource<'s>, ) -> Res, Vec>> { @@ -85,8 +85,8 @@ pub fn rematch_target<'x, 'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn radio_target<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn radio_target<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, RadioTarget<'s>> { let (remaining, _opening) = tag("<<<")(input)?; @@ -118,17 +118,17 @@ pub fn radio_target<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn radio_target_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn radio_target_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt((tag("<"), tag(">"), line_ending))(input) } pub trait RematchObject<'x> { - fn rematch_object<'r, 's>( + fn rematch_object<'b, 'g, 'r, 's>( &'x self, - context: RefContext<'_, 'r, 's>, + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>>; } diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index ce83bea..615e77f 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -21,8 +21,8 @@ use crate::types::Object; use crate::types::RegularLink; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn regular_link<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn regular_link<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, RegularLink<'s>> { alt(( @@ -32,8 +32,8 @@ pub fn regular_link<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn regular_link_without_description<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn regular_link_without_description<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, RegularLink<'s>> { let (remaining, _opening_bracket) = tag("[[")(input)?; @@ -51,8 +51,8 @@ pub fn regular_link_without_description<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn regular_link_with_description<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn regular_link_with_description<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, RegularLink<'s>> { let (remaining, _opening_bracket) = tag("[[")(input)?; @@ -72,8 +72,8 @@ pub fn regular_link_with_description<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn pathreg<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn pathreg<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, path) = escaped( @@ -88,8 +88,8 @@ pub fn pathreg<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn description<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn description<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { @@ -109,8 +109,8 @@ pub fn description<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn description_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn description_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { tag("]]")(input) diff --git a/src/parser/statistics_cookie.rs b/src/parser/statistics_cookie.rs index f477ff0..22ec3f5 100644 --- a/src/parser/statistics_cookie.rs +++ b/src/parser/statistics_cookie.rs @@ -11,8 +11,8 @@ use crate::error::Res; use crate::types::StatisticsCookie; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn statistics_cookie<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn statistics_cookie<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, StatisticsCookie<'s>> { alt(( @@ -22,8 +22,8 @@ pub fn statistics_cookie<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn percent_statistics_cookie<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn percent_statistics_cookie<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, StatisticsCookie<'s>> { let (remaining, source) = @@ -39,8 +39,8 @@ pub fn percent_statistics_cookie<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn fraction_statistics_cookie<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn fraction_statistics_cookie<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, StatisticsCookie<'s>> { let (remaining, source) = recognize(tuple(( diff --git a/src/parser/subscript_and_superscript.rs b/src/parser/subscript_and_superscript.rs index 3fb3ee3..9ad8906 100644 --- a/src/parser/subscript_and_superscript.rs +++ b/src/parser/subscript_and_superscript.rs @@ -17,6 +17,7 @@ use super::util::exit_matcher_parser; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; use crate::context::parser_with_context; use crate::context::ContextElement; +use crate::context::ContextMatcher; use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; @@ -29,8 +30,8 @@ use crate::types::Subscript; use crate::types::Superscript; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn subscript<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn subscript<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Subscript<'s>> { // We check for the underscore first before checking the pre-character as a minor optimization to avoid walking up the context tree to find the document root unnecessarily. @@ -49,8 +50,8 @@ pub fn subscript<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn superscript<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn superscript<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Superscript<'s>> { // We check for the circumflex first before checking the pre-character as a minor optimization to avoid walking up the context tree to find the document root unnecessarily. @@ -69,7 +70,10 @@ pub fn superscript<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res, ()> { +fn pre<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, +) -> Res, ()> { let preceding_character = input.get_preceding_character(); match preceding_character { Some(c) if !c.is_whitespace() => {} @@ -89,8 +93,8 @@ enum ScriptBody<'s> { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn script_body<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn script_body<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ScriptBody<'s>> { alt(( @@ -107,16 +111,16 @@ fn script_body<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn script_asterisk<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn script_asterisk<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { tag("*")(input) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn script_alphanum<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn script_alphanum<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _sign) = opt(recognize(one_of("+-")))(input)?; @@ -129,8 +133,8 @@ fn script_alphanum<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn script_alphanum_character<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn script_alphanum_character<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(verify(anychar, |c| { @@ -139,8 +143,8 @@ fn script_alphanum_character<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn end_script_alphanum_character<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn end_script_alphanum_character<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, final_char) = recognize(verify(anychar, |c| c.is_alphanumeric()))(input)?; @@ -151,8 +155,8 @@ fn end_script_alphanum_character<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn script_with_braces<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn script_with_braces<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { let (remaining, _) = tag("{")(input)?; @@ -172,18 +176,15 @@ fn script_with_braces<'r, 's>( Ok((remaining, children)) } -fn script_with_braces_end( - starting_brace_depth: BracketDepth, -) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> -{ +fn script_with_braces_end(starting_brace_depth: BracketDepth) -> impl ContextMatcher { move |context, input: OrgSource<'_>| { _script_with_braces_end(context, input, starting_brace_depth) } } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _script_with_braces_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn _script_with_braces_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, starting_brace_depth: BracketDepth, ) -> Res, OrgSource<'s>> { diff --git a/src/parser/table.rs b/src/parser/table.rs index 84692db..2dbe014 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -31,8 +31,8 @@ use crate::types::TableRow; /// /// This is not the table.el style. #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn org_mode_table<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn org_mode_table<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Table<'s>> { start_of_line(input)?; @@ -69,8 +69,8 @@ pub fn org_mode_table<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn table_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn table_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { start_of_line(input)?; @@ -78,8 +78,8 @@ fn table_end<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn org_mode_table_row<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn org_mode_table_row<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, TableRow<'s>> { alt(( @@ -89,8 +89,8 @@ pub fn org_mode_table_row<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn org_mode_table_row_rule<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn org_mode_table_row_rule<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, TableRow<'s>> { start_of_line(input)?; @@ -106,8 +106,8 @@ pub fn org_mode_table_row_rule<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn org_mode_table_row_regular<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn org_mode_table_row_regular<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, TableRow<'s>> { start_of_line(input)?; @@ -126,8 +126,8 @@ pub fn org_mode_table_row_regular<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn org_mode_table_cell<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn org_mode_table_cell<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, TableCell<'s>> { let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { @@ -159,8 +159,8 @@ pub fn org_mode_table_cell<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn org_mode_table_cell_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn org_mode_table_cell_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(tuple((space0, alt((tag("|"), peek(line_ending))))))(input) diff --git a/src/parser/target.rs b/src/parser/target.rs index 8f2627b..b978966 100644 --- a/src/parser/target.rs +++ b/src/parser/target.rs @@ -21,8 +21,8 @@ use crate::parser::util::get_consumed; use crate::types::Target; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn target<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn target<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Target<'s>> { let (remaining, _) = tag("<<")(input)?; @@ -62,8 +62,8 @@ pub fn target<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn target_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn target_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(one_of("<>\n"))(input) diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index 3b976ef..f339fdd 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -21,6 +21,7 @@ use super::radio_link::RematchObject; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; use crate::context::parser_with_context; use crate::context::ContextElement; +use crate::context::ContextMatcher; use crate::context::ExitClass; use crate::context::ExitMatcherNode; use crate::context::RefContext; @@ -40,8 +41,8 @@ use crate::types::Underline; use crate::types::Verbatim; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn text_markup<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn text_markup<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { alt(( @@ -58,8 +59,8 @@ pub fn text_markup<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn bold<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn bold<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Bold<'s>> { let text_markup_object_specialized = text_markup_object("*"); @@ -75,8 +76,8 @@ pub fn bold<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn italic<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn italic<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Italic<'s>> { let text_markup_object_specialized = text_markup_object("/"); @@ -92,8 +93,8 @@ pub fn italic<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn underline<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn underline<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Underline<'s>> { let text_markup_object_specialized = text_markup_object("_"); @@ -109,8 +110,8 @@ pub fn underline<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn strike_through<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn strike_through<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, StrikeThrough<'s>> { let text_markup_object_specialized = text_markup_object("+"); @@ -126,8 +127,8 @@ pub fn strike_through<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn verbatim<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn verbatim<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Verbatim<'s>> { let text_markup_string_specialized = text_markup_string("="); @@ -143,8 +144,8 @@ pub fn verbatim<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn code<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn code<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Code<'s>> { let text_markup_string_specialized = text_markup_string("~"); @@ -161,8 +162,8 @@ pub fn code<'r, 's>( fn text_markup_object<'c>( marker_symbol: &'c str, -) -> impl for<'b, 'r, 's> Fn( - RefContext<'b, 'r, 's>, +) -> impl for<'b, 'g, 'r, 's> Fn( + RefContext<'b, 'g, 'r, 's>, OrgSource<'s>, ) -> Res, Vec>> + 'c { @@ -171,10 +172,10 @@ fn text_markup_object<'c>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _text_markup_object<'r, 's, 'x>( - context: RefContext<'_, 'r, 's>, +fn _text_markup_object<'b, 'g, 'r, 's, 'c>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, - marker_symbol: &'x str, + marker_symbol: &'c str, ) -> Res, Vec>> { let (remaining, _) = pre(context, input)?; let (remaining, open) = tag(marker_symbol)(remaining)?; @@ -214,8 +215,8 @@ fn _text_markup_object<'r, 's, 'x>( fn text_markup_string<'c>( marker_symbol: &'c str, -) -> impl for<'b, 'r, 's> Fn( - RefContext<'b, 'r, 's>, +) -> impl for<'b, 'g, 'r, 's> Fn( + RefContext<'b, 'g, 'r, 's>, OrgSource<'s>, ) -> Res, OrgSource<'s>> + 'c { @@ -223,10 +224,10 @@ fn text_markup_string<'c>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _text_markup_string<'r, 's, 'x>( - context: RefContext<'_, 'r, 's>, +fn _text_markup_string<'b, 'g, 'r, 's, 'c>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, - marker_symbol: &'x str, + marker_symbol: &'c str, ) -> Res, OrgSource<'s>> { let (remaining, _) = pre(context, input)?; let (remaining, open) = tag(marker_symbol)(remaining)?; @@ -265,8 +266,8 @@ fn _text_markup_string<'r, 's, 'x>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn pre<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn pre<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> { let preceding_character = input.get_preceding_character(); @@ -285,26 +286,23 @@ pub fn pre<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn post<'r, 's>( - _context: RefContext<'_, 'r, 's>, +pub fn post<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> { let (remaining, _) = alt((recognize(one_of(" \r\n\t-.,;:!?')}[\"")), line_ending))(input)?; Ok((remaining, ())) } -fn text_markup_end<'c>( - marker_symbol: &'c str, -) -> impl for<'r, 's> Fn(RefContext<'_, 'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>> + 'c -{ +fn text_markup_end<'c>(marker_symbol: &'c str) -> impl ContextMatcher + 'c { move |context, input: OrgSource<'_>| _text_markup_end(context, input, marker_symbol) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _text_markup_end<'r, 's, 'x>( - context: RefContext<'_, 'r, 's>, +fn _text_markup_end<'b, 'g, 'r, 's, 'c>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, - marker_symbol: &'x str, + marker_symbol: &'c str, ) -> Res, OrgSource<'s>> { not(preceded_by_whitespace)(input)?; let (remaining, _marker) = terminated( @@ -317,9 +315,9 @@ fn _text_markup_end<'r, 's, 'x>( impl<'x> RematchObject<'x> for Bold<'x> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] - fn rematch_object<'r, 's>( + fn rematch_object<'b, 'g, 'r, 's>( &'x self, - _context: RefContext<'_, 'r, 's>, + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { let (remaining, children) = @@ -336,8 +334,8 @@ impl<'x> RematchObject<'x> for Bold<'x> { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn _rematch_text_markup_object<'r, 's, 'x>( - context: RefContext<'_, 'r, 's>, +fn _rematch_text_markup_object<'b, 'g, 'r, 's, 'x>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, marker_symbol: &'static str, original_match_children: &'x Vec>, diff --git a/src/parser/timestamp.rs b/src/parser/timestamp.rs index 19c1b6d..a1fff17 100644 --- a/src/parser/timestamp.rs +++ b/src/parser/timestamp.rs @@ -23,8 +23,8 @@ use crate::parser::util::get_consumed; use crate::types::Timestamp; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn timestamp<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn timestamp<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { // TODO: This would be more efficient if we didn't throw away the parse result of the first half of an active/inactive date range timestamp if the parse fails (as in, the first thing active_date_range_timestamp parses is a active_timestamp but then we throw that away if it doesn't turn out to be a full active_date_range_timestamp despite the active_timestamp parse being completely valid). I am going with the simplest/cleanest approach for the first implementation. @@ -41,8 +41,8 @@ pub fn timestamp<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn diary_timestamp<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn diary_timestamp<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("<%%(")(input)?; @@ -61,8 +61,8 @@ fn diary_timestamp<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn sexp<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn sexp<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { @@ -83,16 +83,16 @@ fn sexp<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn sexp_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn sexp_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt((tag(")>"), recognize(one_of(">\n"))))(input) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn active_timestamp<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn active_timestamp<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("<")(input)?; @@ -125,8 +125,8 @@ fn active_timestamp<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn inactive_timestamp<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn inactive_timestamp<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("[")(input)?; @@ -159,8 +159,8 @@ fn inactive_timestamp<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn active_date_range_timestamp<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn active_date_range_timestamp<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _first_timestamp) = active_timestamp(context, input)?; @@ -181,8 +181,8 @@ fn active_date_range_timestamp<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn active_time_range_timestamp<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn active_time_range_timestamp<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("<")(input)?; @@ -222,8 +222,8 @@ fn active_time_range_timestamp<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn inactive_date_range_timestamp<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn inactive_date_range_timestamp<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _first_timestamp) = inactive_timestamp(context, input)?; @@ -244,8 +244,8 @@ fn inactive_date_range_timestamp<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn inactive_time_range_timestamp<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn inactive_time_range_timestamp<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Timestamp<'s>> { let (remaining, _) = tag("[")(input)?; @@ -285,8 +285,8 @@ fn inactive_time_range_timestamp<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn date<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn date<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _year) = verify(digit1, |year: &OrgSource<'_>| year.len() == 4)(input)?; @@ -303,8 +303,8 @@ fn date<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn dayname<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn dayname<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { @@ -325,8 +325,8 @@ fn dayname<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn dayname_end<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn dayname_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(verify(anychar, |c| { @@ -335,8 +335,8 @@ fn dayname_end<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn time<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn time<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, _hour) = verify(digit1, |hour: &OrgSource<'_>| { @@ -351,8 +351,8 @@ fn time<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn time_rest<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn time_rest<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { let (remaining, body) = recognize(verify( @@ -364,8 +364,8 @@ fn time_rest<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn active_time_rest_end<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn active_time_rest_end<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt(( @@ -379,8 +379,8 @@ fn active_time_rest_end<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn inactive_time_rest_end<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn inactive_time_rest_end<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { alt(( @@ -394,8 +394,8 @@ fn inactive_time_rest_end<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn time_range_rest_end<'r, 's>( - context: RefContext<'_, 'r, 's>, +fn time_range_rest_end<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // We pop off the most recent context element to get a context tree with just the active/inactive_time_rest_end exit matcher (removing this function from the exit matcher chain) because the 2nd time in the range does not end when a "-TIME" pattern is found. @@ -406,8 +406,8 @@ fn time_range_rest_end<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn repeater<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn repeater<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // + for cumulative type @@ -422,8 +422,8 @@ fn repeater<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn warning_delay<'r, 's>( - _context: RefContext<'_, 'r, 's>, +fn warning_delay<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { // - for all type diff --git a/src/parser/util.rs b/src/parser/util.rs index f5cab9b..ba84ae1 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -26,7 +26,10 @@ pub const WORD_CONSTITUENT_CHARACTERS: &str = /// Check if we are below a section of the given section type regardless of depth #[allow(dead_code)] -pub fn in_section<'r, 's, 'x>(context: RefContext<'_, 'r, 's>, section_name: &'x str) -> bool { +pub fn in_section<'b, 'g, 'r, 's, 'x>( + context: RefContext<'b, 'g, 'r, 's>, + section_name: &'x str, +) -> bool { for thing in context.iter() { match thing { ContextElement::Context(name) if *name == section_name => return true, @@ -37,8 +40,8 @@ pub fn in_section<'r, 's, 'x>(context: RefContext<'_, 'r, 's>, section_name: &'x } /// Checks if we are currently an immediate child of the given section type -pub fn immediate_in_section<'r, 's, 'x>( - context: RefContext<'_, 'r, 's>, +pub fn immediate_in_section<'b, 'g, 'r, 's, 'x>( + context: RefContext<'b, 'g, 'r, 's>, section_name: &'x str, ) -> bool { for thing in context.iter() { @@ -72,8 +75,8 @@ pub fn element_trailing_whitespace<'s>(input: OrgSource<'s>) -> Res( - context: RefContext<'_, 'r, 's>, +pub fn maybe_consume_object_trailing_whitespace_if_not_exiting<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Option>> { if exit_matcher_parser(context, input).is_err() { @@ -84,8 +87,8 @@ pub fn maybe_consume_object_trailing_whitespace_if_not_exiting<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn maybe_consume_trailing_whitespace_if_not_exiting<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn maybe_consume_trailing_whitespace_if_not_exiting<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Option>> { if context.should_consume_trailing_whitespace() && exit_matcher_parser(context, input).is_err() @@ -97,8 +100,8 @@ pub fn maybe_consume_trailing_whitespace_if_not_exiting<'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn maybe_consume_trailing_whitespace<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn maybe_consume_trailing_whitespace<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Option>> { if context.should_consume_trailing_whitespace() { @@ -146,16 +149,16 @@ pub fn non_whitespace_character(input: OrgSource<'_>) -> Res, char /// Check that we are at the start of a line #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn exit_matcher_parser<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn exit_matcher_parser<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { peek(|i| context.check_exit_matcher(i))(input) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub fn text_until_exit<'r, 's>( - context: RefContext<'_, 'r, 's>, +pub fn text_until_exit<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { recognize(verify( diff --git a/src/types/mod.rs b/src/types/mod.rs index 8011bb2..4ab8c17 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -13,11 +13,11 @@ pub use greater_element::Drawer; pub use greater_element::DynamicBlock; pub use greater_element::FootnoteDefinition; pub use greater_element::GreaterBlock; +pub use greater_element::NodeProperty; pub use greater_element::PlainList; pub use greater_element::PlainListItem; pub use greater_element::PropertyDrawer; pub use greater_element::Table; -pub use greater_element::NodeProperty; pub use greater_element::TableRow; pub use lesser_element::Clock; pub use lesser_element::Comment; diff --git a/tests/test_template b/tests/test_template index 2dd2ed4..776ebbe 100644 --- a/tests/test_template +++ b/tests/test_template @@ -6,7 +6,7 @@ fn {name}() {{ let org_sexp = emacs_parse_anonymous_org_document(org_contents.as_str()).expect("Use emacs to parse org file."); println!("{{}}", org_sexp); let (_remaining, parsed_sexp) = sexp_with_padding(org_sexp.as_str()).expect("Sexp Parse failure"); - let (remaining, rust_parsed) = document(org_contents.as_str()).expect("Org Parse failure"); + let rust_parsed = parse(org_contents.as_str()).expect("Org Parse failure"); println!("{{:#?}}", rust_parsed); let diff_result = compare_document(&parsed_sexp, &rust_parsed).expect("Compare parsed documents."); @@ -14,5 +14,4 @@ fn {name}() {{ .print(org_contents.as_str()) .expect("Print document parse tree diff."); assert!(!diff_result.is_bad()); - assert_eq!(remaining, ""); }} From 2915a81edc8ccc80fd22b58bdece94fa11941a98 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 3 Sep 2023 16:08:17 -0400 Subject: [PATCH 24/24] Cleanup. --- src/context/parser_context.rs | 88 ----------------------------------- 1 file changed, 88 deletions(-) diff --git a/src/context/parser_context.rs b/src/context/parser_context.rs index 34623b4..8b21c50 100644 --- a/src/context/parser_context.rs +++ b/src/context/parser_context.rs @@ -12,94 +12,6 @@ use crate::error::Res; use crate::parser::OrgSource; use crate::types::Object; -// type Matcher = -// dyn for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res, OrgSource<'s>>; - -// #[derive(Debug, Clone)] -// pub struct ContextTree<'r, 's> { -// tree: List>, -// } - -// impl<'r, 's> ContextTree<'r, 's> { -// pub fn new() -> Self { -// ContextTree { tree: List::new() } -// } - -// pub fn branch_from(trunk: &Rc>>) -> Self { -// ContextTree { -// tree: List::branch_from(trunk), -// } -// } - -// #[allow(dead_code)] -// pub fn ptr_eq<'x, 'y>(&self, other: &ContextTree<'x, 'y>) -> bool { -// self.tree.ptr_eq(&other.tree) -// } - -// pub fn with_additional_node(&self, data: ContextElement<'r, 's>) -> ContextTree<'r, 's> { -// let new_list = self.tree.push_front(data); -// ContextTree { tree: new_list } -// } - -// pub fn iter(&self) -> impl Iterator>>> { -// self.tree.iter() -// } - -// #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -// pub fn check_exit_matcher( -// &'r self, -// i: OrgSource<'s>, -// ) -> IResult, OrgSource<'s>, CustomError>> { -// // Special check for EOF. We don't just make this a document-level exit matcher since the IgnoreParent ChainBehavior could cause early exit matchers to not run. -// let at_end_of_file = eof(i); -// if at_end_of_file.is_ok() { -// return at_end_of_file; -// } - -// let mut current_class_filter = ExitClass::Gamma; -// for current_node in self.iter() { -// let context_element = current_node.get_data(); -// match context_element { -// ContextElement::ExitMatcherNode(exit_matcher) => { -// if exit_matcher.class as u32 <= current_class_filter as u32 { -// current_class_filter = exit_matcher.class; -// let local_context = ContextTree::branch_from(current_node); -// let local_result = (exit_matcher.exit_matcher)(&local_context, i); -// if local_result.is_ok() { -// return local_result; -// } -// } -// } -// _ => {} -// }; -// } -// // TODO: Make this a specific error instead of just a generic MyError -// return Err(nom::Err::Error(CustomError::MyError(MyError( -// "NoExit".into(), -// )))); -// } - -// /// Indicates if elements should consume the whitespace after them. -// /// -// /// Defaults to true. -// pub fn should_consume_trailing_whitespace(&self) -> bool { -// self._should_consume_trailing_whitespace().unwrap_or(true) -// } - -// fn _should_consume_trailing_whitespace(&self) -> Option { -// for current_node in self.iter() { -// let context_element = current_node.get_data(); -// match context_element { -// ContextElement::ConsumeTrailingWhitespace(should) => { -// return Some(*should); -// } -// _ => {} -// } -// } -// None -// } -// } - #[derive(Debug)] pub enum ContextElement<'r, 's> { /// Stores a parser that indicates that children should exit upon matching an exit matcher.