use std::cell::RefCell; use std::rc::Rc; use nom::branch::alt; use nom::combinator::not; use nom::error::VerboseError; use nom::IResult; use nom::Parser; type Link<'r, T> = Option<&'r Node<'r, T>>; type Matcher = dyn for<'s> Fn(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>; pub struct Node<'r, T> { elem: T, next: Link<'r, T>, } pub struct List<'r, T> { head: Link<'r, T>, } impl<'r, T> List<'r, T> { pub fn new() -> Self { List { head: None } } pub fn with_additional_node(&self, element: T) -> Node<'r, T> { let new_node = Node { elem: element, next: self.head, }; new_node } } struct ContextElement<'r> { fail_matcher: ChainBehavior<'r>, } enum ChainBehavior<'r> { AndParent(Option<&'r Matcher>), IgnoreParent(Option<&'r Matcher>), }