mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Un-macro indented_seq
This commit is contained in:
parent
60fa7ebe9e
commit
1b4b0a0aa1
2 changed files with 31 additions and 29 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue