Fix one_of error state handling

This commit is contained in:
Joshua Warner 2022-11-03 17:23:31 -04:00
parent b2bb38220b
commit 311193fe70
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
3 changed files with 27 additions and 9 deletions

View file

@ -346,6 +346,7 @@ fn parse_expr_start<'a>(
loc!(move |a, s, m| parse_expr_operator_chain(m, options, a, s)),
fail_expr_start_e()
]
.trace("expr_start")
.parse(arena, state, min_indent)
}
@ -2076,10 +2077,10 @@ mod when {
parser::keyword_e(keyword::IS, EWhen::Is)
)
),
move |arena, state, progress, (case_indent, loc_condition), min_indent| {
move |arena, state, _progress, (case_indent, loc_condition), min_indent| {
if case_indent < min_indent {
return Err((
progress,
MadeProgress,
// TODO maybe pass case_indent here?
EWhen::PatternAlignment(5, state.pos()),
state,
@ -2089,15 +2090,18 @@ mod when {
// Everything in the branches must be indented at least as much as the case itself.
let min_indent = case_indent;
let (p1, branches, state) = branches(options).parse(arena, state, min_indent)?;
let (_p1, branches, state) = branches(options)
.parse(arena, state, min_indent)
.map_err(|(_p, e, s)| (MadeProgress, e, s))?;
Ok((
progress.or(p1),
MadeProgress,
Expr::When(arena.alloc(loc_condition), branches.into_bump_slice()),
state,
))
},
)
.trace("when")
}
/// Parsing when with indentation.

View file

@ -1380,11 +1380,12 @@ macro_rules! and {
macro_rules! one_of {
($p1:expr, $p2:expr) => {
move |arena: &'a bumpalo::Bump, state: $crate::state::State<'a>, min_indent: u32| {
let original_state = state.clone();
match $p1.parse(arena, state, min_indent) {
valid @ Ok(_) => valid,
Err((MadeProgress, fail, state)) => Err((MadeProgress, fail, state)),
Err((NoProgress, _, state)) => $p2.parse(arena, state, min_indent),
Err((NoProgress, _, _)) => $p2.parse(arena, original_state, min_indent),
}
}
};