I think thats all for context_many1. Just need to start using it.
This commit is contained in:
parent
1f1a18782e
commit
6459cc64d0
@ -72,19 +72,24 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
current_context
|
let elements: Vec<Token<'s>> = current_context
|
||||||
.iter_until(context)
|
.into_iter_until(context)
|
||||||
.filter(|context_element| match context_element.get_data() {
|
.filter_map(|context_element| match context_element {
|
||||||
ContextElement::PreviousElementNode(_) => true,
|
ContextElement::PreviousElementNode(elem) => Some(elem.element),
|
||||||
ContextElement::ExitMatcherNode(_) => false,
|
ContextElement::ExitMatcherNode(_) => None,
|
||||||
ContextElement::Context(_) => false,
|
ContextElement::Context(_) => None,
|
||||||
ContextElement::StartOfParagraph => false,
|
ContextElement::StartOfParagraph => None,
|
||||||
});
|
})
|
||||||
|
.collect();
|
||||||
|
if elements.is_empty() {
|
||||||
|
if let Some(err) = err {
|
||||||
|
err?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok((i, elements))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// todo
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn context_many_till<'r, 's, I, O, E, F, M, T>(
|
pub fn context_many_till<'r, 's, I, O, E, F, M, T>(
|
||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
mut many_matcher: M,
|
mut many_matcher: M,
|
||||||
|
@ -27,7 +27,7 @@ impl<T> Node<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This Debug is only needed because of the try_unwrap+expect
|
// TODO: This Debug is only needed because of the try_unwrap+expect
|
||||||
impl<T: Debug> List<T> {
|
impl<T> List<T> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
List { head: None }
|
List { head: None }
|
||||||
}
|
}
|
||||||
@ -45,8 +45,10 @@ impl<T: Debug> List<T> {
|
|||||||
match self.head.take() {
|
match self.head.take() {
|
||||||
None => (None, List::new()),
|
None => (None, List::new()),
|
||||||
Some(popped_node) => {
|
Some(popped_node) => {
|
||||||
let extracted_node =
|
let extracted_node = match Rc::try_unwrap(popped_node) {
|
||||||
Rc::try_unwrap(popped_node).expect("TODO I should handle this better");
|
Ok(node) => node,
|
||||||
|
Err(e) => panic!("try_unwrap failed on Rc in pop_front on List."),
|
||||||
|
};
|
||||||
(
|
(
|
||||||
Some(extracted_node.data),
|
Some(extracted_node.data),
|
||||||
List {
|
List {
|
||||||
@ -91,6 +93,13 @@ impl<T: Debug> List<T> {
|
|||||||
stop: &other.head,
|
stop: &other.head,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_iter_until<'a>(self, other: &'a List<T>) -> impl Iterator<Item = T> + 'a {
|
||||||
|
NodeIntoIterUntil {
|
||||||
|
position: self,
|
||||||
|
stop: &other,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NodeIter<'a, T> {
|
pub struct NodeIter<'a, T> {
|
||||||
@ -144,3 +153,21 @@ impl<'a, T> Iterator for NodeIterUntil<'a, T> {
|
|||||||
Some(return_value)
|
Some(return_value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct NodeIntoIterUntil<'a, T> {
|
||||||
|
position: List<T>,
|
||||||
|
stop: &'a List<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T> Iterator for NodeIntoIterUntil<'a, T> {
|
||||||
|
type Item = T;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
if self.position.ptr_eq(self.stop) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let (popped_element, new_position) = self.position.pop_front();
|
||||||
|
self.position = new_position;
|
||||||
|
popped_element
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -50,6 +50,13 @@ impl<'r, 's> ContextTree<'r, 's> {
|
|||||||
self.tree.iter_until(&other.tree)
|
self.tree.iter_until(&other.tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_iter_until<'x: 'r>(
|
||||||
|
self,
|
||||||
|
other: &'x ContextTree<'x, 's>,
|
||||||
|
) -> impl Iterator<Item = ContextElement<'r, 's>> {
|
||||||
|
self.tree.into_iter_until(&other.tree)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn check_exit_matcher(
|
pub fn check_exit_matcher(
|
||||||
&'r self,
|
&'r self,
|
||||||
i: &'s str,
|
i: &'s str,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user