Compiling but I'm not generating a new context.
This commit is contained in:
parent
ee9e6297a6
commit
b4215128fa
@ -1,30 +1,25 @@
|
|||||||
macro_rules! failable_sequence {
|
macro_rules! failable_sequence {
|
||||||
($name:ident,$inp:ident,$context:ident,$begin_matcher:expr,$element_matcher:expr,$success_matcher:expr) => {
|
($name:ident,$inp:ident,$context:ident,$begin_matcher:expr,$element_matcher:expr,$success_matcher:expr) => {
|
||||||
pub fn $name<'b, F>(
|
pub fn $name<F>(
|
||||||
$context: &'b NomContext<F>,
|
$context: &NomContext<F>,
|
||||||
) -> impl for<'a> FnMut(
|
) -> impl for<'a> FnMut(
|
||||||
&'a str,
|
&'a str,
|
||||||
) -> nom::IResult<
|
) -> nom::IResult<
|
||||||
&'a str,
|
&'a str,
|
||||||
crate::parser::text::Sequence<'a>,
|
crate::parser::text::Sequence<'a>,
|
||||||
VerboseError<&'a str>,
|
VerboseError<&'a str>,
|
||||||
> + 'b
|
> + '_
|
||||||
where
|
where
|
||||||
F: for<'a> nom::Parser<&'a str, &'a str, VerboseError<&'a str>>,
|
F: for<'a> FnMut(&'a str) -> nom::IResult<&'a str, &'a str, VerboseError<&'a str>>,
|
||||||
{
|
{
|
||||||
let fail_matcher = $context.fail_matcher.clone();
|
|
||||||
let new_fail_matcher = alt((
|
|
||||||
|i| fail_matcher.borrow_mut().parse(i),
|
|
||||||
recognize($success_matcher),
|
|
||||||
));
|
|
||||||
|
|
||||||
move |$inp: &str| {
|
move |$inp: &str| {
|
||||||
let new_context = $context.with_no_bold();
|
let new_context = $context.with_no_bold();
|
||||||
// let other_new_context = NomContext::with_additional_fail_matcher(
|
// let other_new_context = NomContext::with_additional_fail_matcher(
|
||||||
// |i: &str| recognize($success_matcher)(i),
|
// |i: &str| recognize($success_matcher)(i),
|
||||||
// $context,
|
// $context,
|
||||||
// );
|
// );
|
||||||
let other_new_context = super::nom_context::NomContext::new(new_fail_matcher);
|
// let other_new_context =
|
||||||
|
// super::nom_context::NomContext::new($context.fail_matcher.clone());
|
||||||
let element_matcher = recognize($element_matcher(&new_context));
|
let element_matcher = recognize($element_matcher(&new_context));
|
||||||
let local_fail_matcher = $context.fail_matcher.clone();
|
let local_fail_matcher = $context.fail_matcher.clone();
|
||||||
let ret = map(
|
let ret = map(
|
||||||
@ -32,11 +27,11 @@ macro_rules! failable_sequence {
|
|||||||
$begin_matcher,
|
$begin_matcher,
|
||||||
nom::multi::many_till(
|
nom::multi::many_till(
|
||||||
nom::sequence::preceded(
|
nom::sequence::preceded(
|
||||||
not(|i| local_fail_matcher.borrow_mut().parse(i)),
|
not(|i| local_fail_matcher.borrow_mut()(i)),
|
||||||
element_matcher,
|
element_matcher,
|
||||||
),
|
),
|
||||||
nom::sequence::preceded(
|
nom::sequence::preceded(
|
||||||
not(|i| local_fail_matcher.borrow_mut().parse(i)),
|
not(|i| local_fail_matcher.borrow_mut()(i)),
|
||||||
$success_matcher,
|
$success_matcher,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use nom::error::VerboseError;
|
use nom::error::VerboseError;
|
||||||
use nom::Parser;
|
use nom::IResult;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ pub struct NomContext<F> {
|
|||||||
|
|
||||||
impl<F> NomContext<F>
|
impl<F> NomContext<F>
|
||||||
where
|
where
|
||||||
F: for<'a> Parser<&'a str, &'a str, VerboseError<&'a str>>,
|
F: for<'a> FnMut(&'a str) -> IResult<&'a str, &'a str, VerboseError<&'a str>>,
|
||||||
{
|
{
|
||||||
pub fn new(fail_matcher: F) -> Self {
|
pub fn new(fail_matcher: F) -> Self {
|
||||||
NomContext {
|
NomContext {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user