Un-macro indented_seq

This commit is contained in:
Jackson Wambolt 2024-04-14 23:59:40 -05:00
parent 60fa7ebe9e
commit 1b4b0a0aa1
No known key found for this signature in database
GPG key ID: 76F29A42FEE8811C
2 changed files with 31 additions and 29 deletions

View file

@ -1686,32 +1686,33 @@ macro_rules! record {
};
}
/// Similar to [`and!`], but we modify the `min_indent` of the second parser to be
/// 1 greater than the `line_indent()` at the start of the first parser.
#[macro_export]
macro_rules! indented_seq {
($p1:expr, $p2:expr) => {
move |arena: &'a bumpalo::Bump, state: $crate::state::State<'a>, _min_indent: u32| {
let start_indent = state.line_indent();
/// Similar to [`and`], but we modify the `min_indent` of the second parser
/// (`parser`) to be 1 greater than the `line_indent()` at the start of the
/// first parser (`before`).
pub fn indented_seq<'a, O, E: 'a>(
before: impl Parser<'a, (), E>,
parser: impl Parser<'a, O, E>,
) -> impl Parser<'a, O, E> {
move |arena: &'a bumpalo::Bump, state: crate::state::State<'a>, _min_indent: u32| {
let start_indent = state.line_indent();
// TODO: we should account for min_indent here, but this doesn't currently work
// because min_indent is sometimes larger than it really should be, which is in turn
// due to uses of `increment_indent`.
//
// let p1_indent = std::cmp::max(start_indent, min_indent);
// TODO: we should account for min_indent here, but this doesn't currently work
// because min_indent is sometimes larger than it really should be, which is in turn
// due to uses of `increment_indent`.
//
// let p1_indent = std::cmp::max(start_indent, min_indent);
let p1_indent = start_indent;
let p2_indent = p1_indent + 1;
let p1_indent = start_indent;
let p2_indent = p1_indent + 1;
match $p1.parse(arena, state, p1_indent) {
Ok((p1, (), state)) => match $p2.parse(arena, state, p2_indent) {
Ok((p2, out2, state)) => Ok((p1.or(p2), out2, state)),
Err((p2, fail)) => Err((p1.or(p2), fail)),
},
Err((progress, fail)) => Err((progress, fail)),
}
match before.parse(arena, state, p1_indent) {
Ok((p1, (), state)) => match parser.parse(arena, state, p2_indent) {
Ok((p2, out2, state)) => Ok((p1.or(p2), out2, state)),
Err((p2, fail)) => Err((p1.or(p2), fail)),
},
Err((progress, fail)) => Err((progress, fail)),
}
};
}
}
/// Similar to [`and!`], but we modify the `min_indent` of the second parser to be