From bc91775880f7c41ddb3c6fead346807014c51adf Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 3 Dec 2022 21:06:04 -0500 Subject: [PATCH] Add the with_additional_node function to the ContextTree. --- src/parser/list.rs | 4 ++-- src/parser/new_context.rs | 7 +++++++ src/parser/text_element_parser.rs | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/parser/list.rs b/src/parser/list.rs index 235a5831..a8e39aa2 100644 --- a/src/parser/list.rs +++ b/src/parser/list.rs @@ -23,7 +23,7 @@ impl List { } } - pub fn get_data(&self) -> &T { - &self.data + pub fn get_data(&self) -> Option<&T> { + self.head.map(|rc_node| &rc_node.as_ref().data) } } diff --git a/src/parser/new_context.rs b/src/parser/new_context.rs index 5f62a674..d6706024 100644 --- a/src/parser/new_context.rs +++ b/src/parser/new_context.rs @@ -13,6 +13,13 @@ impl<'r> ContextTree<'r> { pub fn new() -> Self { 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> { diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index 529b8c99..6988f009 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -83,7 +83,7 @@ where pub fn document(input: &str) -> Res<&str, Vec<(Vec, &str)>> { let initial_context: ContextTree<'_> = ContextTree::new(); let paragraph_parser = parser_with_context!(paragraph); - let ret = many1(paragraph_parser(&initial_context))(input); + let ret = many1(paragraph_parser(initial_context))(input); ret }