make optional always backtrack on error

This commit is contained in:
Folkert 2021-02-02 16:04:06 +01:00
parent 872f83680f
commit 851f472167

View file

@ -925,12 +925,11 @@ where
match parser.parse(arena, state) {
Ok((progress, out1, state)) => Ok((progress, Some(out1), state)),
Err((MadeProgress, fail, state)) => {
Err((_, _, _)) => {
// NOTE this will backtrack
// Ok((NoProgress, None, original_state))
Err((MadeProgress, fail, state))
// TODO can we get rid of some of the potential backtracking?
Ok((NoProgress, None, original_state))
}
Err((NoProgress, _, _)) => Ok((NoProgress, None, original_state)),
}
}
}
@ -1296,6 +1295,13 @@ macro_rules! one_or_more {
};
}
#[macro_export]
macro_rules! debug {
($parser:expr) => {
move |arena, state: $crate::parser::State<'a>| dbg!($parser.parse(arena, state))
};
}
#[macro_export]
macro_rules! attempt {
($attempting:expr, $parser:expr) => {