Start of working on enum.
This commit is contained in:
parent
f4473cbf01
commit
2bb6f50cba
@ -42,7 +42,12 @@ impl<'r, T> ContextTree<'r, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ContextElement<'r> {
|
pub enum ContextElement<'r> {
|
||||||
|
FailMatcherNode(FailMatcherNode<'r>),
|
||||||
|
PreviousElementNode(PreviousElementNode<'r>),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct FailMatcherNode<'r> {
|
||||||
pub fail_matcher: ChainBehavior<'r>,
|
pub fail_matcher: ChainBehavior<'r>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,6 +55,7 @@ pub struct PreviousElementNode<'r> {
|
|||||||
pub dummy: &'r str,
|
pub dummy: &'r str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub enum ChainBehavior<'r> {
|
pub enum ChainBehavior<'r> {
|
||||||
AndParent(Option<&'r Matcher>),
|
AndParent(Option<&'r Matcher>),
|
||||||
IgnoreParent(Option<&'r Matcher>),
|
IgnoreParent(Option<&'r Matcher>),
|
||||||
@ -66,9 +72,9 @@ impl<'r> OrgModeContextTree<'r> for OrgModeContextNode<'r> {
|
|||||||
&'r self,
|
&'r self,
|
||||||
fail_matcher: &'r Matcher,
|
fail_matcher: &'r Matcher,
|
||||||
) -> ContextTree<'r, ContextElement<'r>> {
|
) -> ContextTree<'r, ContextElement<'r>> {
|
||||||
self.with_additional_node(ContextElement {
|
self.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode {
|
||||||
fail_matcher: ChainBehavior::AndParent(Some(fail_matcher)),
|
fail_matcher: ChainBehavior::AndParent(Some(fail_matcher)),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn with_previous_element(&'r self, dummy: &'r str) -> ContextTree<'r, PreviousElementNode<'r>> {
|
// fn with_previous_element(&'r self, dummy: &'r str) -> ContextTree<'r, PreviousElementNode<'r>> {
|
||||||
@ -80,10 +86,9 @@ impl<'r> OrgModeContextTree<'r> for OrgModeContextNode<'r> {
|
|||||||
fn match_fail<'s>(&'r self, i: &'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>> {
|
fn match_fail<'s>(&'r self, i: &'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>> {
|
||||||
let mut current_node = self.head.as_ref();
|
let mut current_node = self.head.as_ref();
|
||||||
while current_node.is_some() {
|
while current_node.is_some() {
|
||||||
let current_node_unwrapped = current_node
|
let current_node_unwrapped =
|
||||||
.as_ref()
|
current_node.expect("while loop asserts current_node is some.");
|
||||||
.expect("while loop asserts current_node is some.");
|
match current_node_unwrapped.elem.get_fail_matcher() {
|
||||||
match current_node_unwrapped.elem.fail_matcher {
|
|
||||||
ChainBehavior::AndParent(Some(matcher)) => {
|
ChainBehavior::AndParent(Some(matcher)) => {
|
||||||
let local_result = matcher(i);
|
let local_result = matcher(i);
|
||||||
if local_result.is_ok() {
|
if local_result.is_ok() {
|
||||||
@ -117,3 +122,16 @@ impl<'r, T> std::fmt::Debug for ContextTree<'r, T> {
|
|||||||
write!(f, "ContextTree")
|
write!(f, "ContextTree")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'r> ContextElement<'r> {
|
||||||
|
pub fn get_fail_matcher(&self) -> ChainBehavior<'r> {
|
||||||
|
match self {
|
||||||
|
ContextElement::FailMatcherNode(fail_matcher_node) => {
|
||||||
|
fail_matcher_node.fail_matcher.clone()
|
||||||
|
}
|
||||||
|
ContextElement::PreviousElementNode(previous_element_node) => {
|
||||||
|
ChainBehavior::AndParent(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user