Add the with_additional_node function to the ContextTree.

This commit is contained in:
Tom Alexander 2022-12-03 21:06:04 -05:00
parent c0e51298b6
commit bc91775880
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 10 additions and 3 deletions

View File

@ -23,7 +23,7 @@ impl<T> List<T> {
} }
} }
pub fn get_data(&self) -> &T { pub fn get_data(&self) -> Option<&T> {
&self.data self.head.map(|rc_node| &rc_node.as_ref().data)
} }
} }

View File

@ -13,6 +13,13 @@ impl<'r> ContextTree<'r> {
pub fn new() -> Self { pub fn new() -> Self {
ContextTree { tree: List::new() } ContextTree { tree: List::new() }
} }
pub fn with_additional_node<'x>(&self, data: ContextElement<'x>) -> ContextTree<'x> {
let new_list = self.tree.push_front(data);
ContextTree {
tree: new_list,
}
}
} }
pub enum ContextElement<'r> { pub enum ContextElement<'r> {

View File

@ -83,7 +83,7 @@ where
pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> { pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> {
let initial_context: ContextTree<'_> = ContextTree::new(); let initial_context: ContextTree<'_> = ContextTree::new();
let paragraph_parser = parser_with_context!(paragraph); let paragraph_parser = parser_with_context!(paragraph);
let ret = many1(paragraph_parser(&initial_context))(input); let ret = many1(paragraph_parser(initial_context))(input);
ret ret
} }