get_fail_matcher implemented.

This commit is contained in:
Tom Alexander 2022-11-26 23:35:10 -05:00
parent 4a2b633f9c
commit 9673917a3c
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 20 additions and 4 deletions

View File

@ -27,9 +27,9 @@ pub trait NodeType<'p> {
impl<'p, T> NodeType<'p> for Node<'p, T>
where
T: ContextElement,
T: for<'s> ContextElement<'s>,
{
fn get_data(&self) -> &dyn ContextElement {
fn get_data<'s>(&'s self) -> &dyn ContextElement {
&self.data
}
@ -38,7 +38,9 @@ where
}
}
pub trait ContextElement {}
pub trait ContextElement<'r> {
fn get_fail_matcher(&self) -> ChainBehavior<'r>;
}
struct FailMatcherNode<'r> {
fail_matcher: ChainBehavior<'r>,
@ -48,7 +50,21 @@ struct PreviousElementNode<'r> {
dummy: &'r str,
}
enum ChainBehavior<'r> {
#[derive(Clone)]
pub enum ChainBehavior<'r> {
AndParent(Option<&'r Matcher>),
IgnoreParent(Option<&'r Matcher>),
}
impl<'r> ContextElement<'r> for FailMatcherNode<'r> {
fn get_fail_matcher(&self) -> ChainBehavior<'r> {
// TODO: Remove this clone
self.fail_matcher.clone()
}
}
impl<'r> ContextElement<'r> for PreviousElementNode<'r> {
fn get_fail_matcher(&self) -> ChainBehavior<'r> {
ChainBehavior::AndParent(None)
}
}