Un-macro one_or_more

This commit is contained in:
Jackson Wambolt 2024-04-15 20:43:12 -05:00
parent f88e46fc32
commit 2f776f366f
No known key found for this signature in database
GPG key ID: 76F29A42FEE8811C

View file

@ -2311,13 +2311,15 @@ 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,
match $parser.parse(arena, state.clone(), min_indent) { state.clone(),
min_indent,
) {
Ok((_, first_output, next_state)) => { Ok((_, first_output, next_state)) => {
let mut state = next_state; let mut state = next_state;
let mut buf = Vec::with_capacity_in(1, arena); let mut buf = Vec::with_capacity_in(1, arena);
@ -2326,7 +2328,7 @@ macro_rules! one_or_more {
loop { loop {
let old_state = state.clone(); let old_state = state.clone();
match $parser.parse(arena, state, min_indent) { match parser.parse(arena, state, min_indent) {
Ok((_, next_output, next_state)) => { Ok((_, next_output, next_state)) => {
state = next_state; state = next_state;
buf.push(next_output); buf.push(next_output);
@ -2340,10 +2342,8 @@ macro_rules! one_or_more {
} }
} }
} }
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.