Add accessors for booleans on what we are allowed to match.

This commit is contained in:
Tom Alexander 2022-10-15 14:20:40 -04:00
parent 9d534aa627
commit 1d571acc17
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -26,8 +26,8 @@ pub struct NomContext<'r> {
parent: Option<&'r Self>, parent: Option<&'r Self>,
fail_matcher: ChainBehavior, fail_matcher: ChainBehavior,
/// You can't have nested bolds or links in org-mode /// You can't have nested bolds or links in org-mode
can_match_bold: bool, match_bold_allowed: bool,
can_match_link: bool, match_link_allowed: bool,
} }
impl<'r> NomContext<'r> { impl<'r> NomContext<'r> {
@ -35,8 +35,8 @@ impl<'r> NomContext<'r> {
NomContext { NomContext {
parent: None, parent: None,
fail_matcher: ChainBehavior::IgnoreParent(Some(fail_matcher)), fail_matcher: ChainBehavior::IgnoreParent(Some(fail_matcher)),
can_match_bold: true, match_bold_allowed: true,
can_match_link: true, match_link_allowed: true,
} }
} }
@ -44,14 +44,22 @@ impl<'r> NomContext<'r> {
NomContext { NomContext {
parent: Some(&self), parent: Some(&self),
fail_matcher: ChainBehavior::AndParent(Some(other)), fail_matcher: ChainBehavior::AndParent(Some(other)),
can_match_bold: self.can_match_bold, match_bold_allowed: self.match_bold_allowed,
can_match_link: self.can_match_link, match_link_allowed: self.match_link_allowed,
} }
} }
pub fn not_matching_fail<'s>(&self, i: &'s str) -> IResult<&'s str, (), VerboseError<&'s str>> { pub fn not_matching_fail<'s>(&self, i: &'s str) -> IResult<&'s str, (), VerboseError<&'s str>> {
not(FailChecker::new(self))(i) not(FailChecker::new(self))(i)
} }
pub fn can_match_bold(&self) -> bool {
self.match_bold_allowed
}
pub fn can_match_link(&self) -> bool {
self.match_link_allowed
}
} }
impl<'a, 'b> Parser<&'b str, &'b str, VerboseError<&'b str>> for FailChecker<'a> { impl<'a, 'b> Parser<&'b str, &'b str, VerboseError<&'b str>> for FailChecker<'a> {