refactor(parser): Switch 'impl FnMut' to 'impl Parser'

This commit is contained in:
Ed Page 2024-10-25 09:06:14 -05:00
parent 25067bdb4e
commit 88c702e6a8
2 changed files with 7 additions and 7 deletions

View File

@ -286,8 +286,8 @@ fn not_ws(c: char) -> bool {
} }
fn ws<'a, O>( fn ws<'a, O>(
inner: impl FnMut(&'a str) -> ParseResult<'a, O>, inner: impl Parser<&'a str, O, ErrorContext<'a>>,
) -> impl FnMut(&'a str) -> ParseResult<'a, O> { ) -> impl Parser<&'a str, O, ErrorContext<'a>> {
delimited(take_till(not_ws), inner, take_till(not_ws)) delimited(take_till(not_ws), inner, take_till(not_ws))
} }
@ -295,8 +295,8 @@ fn ws<'a, O>(
/// Returns tuple that would be returned when parsing `end`. /// Returns tuple that would be returned when parsing `end`.
fn skip_till<'a, 'b, O>( fn skip_till<'a, 'b, O>(
candidate_finder: impl crate::memchr_splitter::Splitter, candidate_finder: impl crate::memchr_splitter::Splitter,
end: impl FnMut(&'a str) -> ParseResult<'a, O>, end: impl Parser<&'a str, O, ErrorContext<'a>>,
) -> impl FnMut(&'a str) -> ParseResult<'a, (&'a str, O)> { ) -> impl Parser<&'a str, (&'a str, O), ErrorContext<'a>> {
let mut next = alt((map(end, Some), map(anychar, |_| None))); let mut next = alt((map(end, Some), map(anychar, |_| None)));
move |start: &'a str| { move |start: &'a str| {
let mut i = start; let mut i = start;
@ -318,7 +318,7 @@ fn skip_till<'a, 'b, O>(
} }
} }
fn keyword<'a>(k: &'a str) -> impl FnMut(&'a str) -> ParseResult<'a> { fn keyword<'a>(k: &'a str) -> impl Parser<&'a str, &'a str, ErrorContext<'a>> {
move |i: &'a str| -> ParseResult<'a> { move |i: &'a str| -> ParseResult<'a> {
let (j, v) = identifier.parse_next(i)?; let (j, v) = identifier.parse_next(i)?;
if k == v { Ok((j, v)) } else { fail(i) } if k == v { Ok((j, v)) } else { fail(i) }

View File

@ -210,8 +210,8 @@ impl<'a> Node<'a> {
fn cut_node<'a, O>( fn cut_node<'a, O>(
kind: Option<&'static str>, kind: Option<&'static str>,
inner: impl FnMut(&'a str) -> ParseResult<'a, O>, inner: impl Parser<&'a str, O, ErrorContext<'a>>,
) -> impl FnMut(&'a str) -> ParseResult<'a, O> { ) -> impl Parser<&'a str, O, ErrorContext<'a>> {
let mut inner = cut(inner); let mut inner = cut(inner);
move |i: &'a str| { move |i: &'a str| {
let result = inner.parse_next(i); let result = inner.parse_next(i);