mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
Un-macro one_or_more
This commit is contained in:
parent
f88e46fc32
commit
2f776f366f
1 changed files with 27 additions and 27 deletions
|
@ -2311,39 +2311,39 @@ pub fn zero_or_more<'a, Output, E: 'a>(
|
||||||
/// # }
|
/// # }
|
||||||
/// # foo(&arena);
|
/// # foo(&arena);
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
pub fn one_or_more<'a, Output, E: 'a>(
|
||||||
macro_rules! one_or_more {
|
parser: impl Parser<'a, Output, E>,
|
||||||
($parser:expr, $to_error:expr) => {
|
to_error: impl Fn(Position) -> E,
|
||||||
move |arena, state: State<'a>, min_indent: u32| {
|
) -> impl Parser<'a, bumpalo::collections::Vec<'a, Output>, E> {
|
||||||
use bumpalo::collections::Vec;
|
move |arena, state: State<'a>, min_indent: u32| match parser.parse(
|
||||||
|
arena,
|
||||||
|
state.clone(),
|
||||||
|
min_indent,
|
||||||
|
) {
|
||||||
|
Ok((_, first_output, next_state)) => {
|
||||||
|
let mut state = next_state;
|
||||||
|
let mut buf = Vec::with_capacity_in(1, arena);
|
||||||
|
|
||||||
match $parser.parse(arena, state.clone(), min_indent) {
|
buf.push(first_output);
|
||||||
Ok((_, first_output, next_state)) => {
|
|
||||||
let mut state = next_state;
|
|
||||||
let mut buf = Vec::with_capacity_in(1, arena);
|
|
||||||
|
|
||||||
buf.push(first_output);
|
loop {
|
||||||
|
let old_state = state.clone();
|
||||||
loop {
|
match parser.parse(arena, state, min_indent) {
|
||||||
let old_state = state.clone();
|
Ok((_, next_output, next_state)) => {
|
||||||
match $parser.parse(arena, state, min_indent) {
|
state = next_state;
|
||||||
Ok((_, next_output, next_state)) => {
|
buf.push(next_output);
|
||||||
state = next_state;
|
}
|
||||||
buf.push(next_output);
|
Err((NoProgress, _)) => {
|
||||||
}
|
return Ok((MadeProgress, buf, old_state));
|
||||||
Err((NoProgress, _)) => {
|
}
|
||||||
return Ok((MadeProgress, buf, old_state));
|
Err((MadeProgress, fail)) => {
|
||||||
}
|
return Err((MadeProgress, fail));
|
||||||
Err((MadeProgress, fail)) => {
|
|
||||||
return Err((MadeProgress, fail));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err((progress, _)) => Err((progress, $to_error(state.pos()))),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
Err((progress, _)) => Err((progress, to_error(state.pos()))),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a parser that debug prints the result of parsing.
|
/// Creates a parser that debug prints the result of parsing.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue