diff --git a/src/blanket.rs b/src/blanket.rs index 00b74ad7..fabe3d27 100644 --- a/src/blanket.rs +++ b/src/blanket.rs @@ -1,12 +1,12 @@ use super::*; -impl<'a, T, I, O, E> Parser<'a, I, O, E> for &T +impl<'src, T, I, O, E> Parser<'src, I, O, E> for &T where - T: ?Sized + Parser<'a, I, O, E>, - I: Input<'a>, - E: ParserExtra<'a, I>, + T: ?Sized + Parser<'src, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, { - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized, { @@ -16,15 +16,19 @@ where go_extra!(O); } -impl<'a, T, I, O, E> ConfigParser<'a, I, O, E> for &T +impl<'src, T, I, O, E> ConfigParser<'src, I, O, E> for &T where - T: ?Sized + ConfigParser<'a, I, O, E>, - I: Input<'a>, - E: ParserExtra<'a, I>, + T: ?Sized + ConfigParser<'src, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, { type Config = T::Config; - fn go_cfg(&self, inp: &mut InputRef<'a, '_, I, E>, cfg: Self::Config) -> PResult + fn go_cfg( + &self, + inp: &mut InputRef<'src, '_, I, E>, + cfg: Self::Config, + ) -> PResult where Self: Sized, { diff --git a/src/combinator.rs b/src/combinator.rs index 70497e33..91aa3644 100644 --- a/src/combinator.rs +++ b/src/combinator.rs @@ -10,8 +10,8 @@ use inspector::Inspector; use super::*; /// The type of a lazy parser. -pub type Lazy<'a, A, I, E> = - ThenIgnore, >::Token, I, E>, (), E>; +pub type Lazy<'src, A, I, E> = + ThenIgnore, >::Token, I, E>, (), E>; /// Alter the configuration of a struct using parse-time context #[derive(Copy, Clone)] @@ -20,15 +20,15 @@ pub struct Configure { pub(crate) cfg: F, } -impl<'a, I, O, E, A, F> Parser<'a, I, O, E> for Configure +impl<'src, I, O, E, A, F> Parser<'src, I, O, E> for Configure where - A: ConfigParser<'a, I, O, E>, + A: ConfigParser<'src, I, O, E>, F: Fn(A::Config, &E::Context) -> A::Config, - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized, { @@ -58,15 +58,15 @@ impl Clone for IterConfigure { } } -impl<'a, I, OA, E, A, F> Parser<'a, I, (), E> for IterConfigure +impl<'src, I, OA, E, A, F> Parser<'src, I, (), E> for IterConfigure where - A: ConfigIterParser<'a, I, OA, E>, + A: ConfigIterParser<'src, I, OA, E>, F: Fn(A::Config, &E::Context) -> A::Config, - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let mut state = self.make_iter::(inp)?; loop { match self.next::(inp, &mut state) { @@ -80,22 +80,22 @@ where go_extra!(()); } -impl<'a, I, O, E, A, F> IterParser<'a, I, O, E> for IterConfigure +impl<'src, I, O, E, A, F> IterParser<'src, I, O, E> for IterConfigure where - A: ConfigIterParser<'a, I, O, E>, + A: ConfigIterParser<'src, I, O, E>, F: Fn(A::Config, &E::Context) -> A::Config, - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { type IterState = (A::IterState, A::Config) where - I: 'a; + I: 'src; #[inline(always)] fn make_iter( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, ) -> PResult> { Ok(( A::make_iter(&self.parser, inp)?, @@ -106,7 +106,7 @@ where #[inline(always)] fn next( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, state: &mut Self::IterState, ) -> IPResult { self.parser.next_cfg(inp, &mut state.0, &state.1) @@ -132,15 +132,15 @@ impl Clone for TryIterConfigure { } } -impl<'a, I, OA, E, A, F> Parser<'a, I, (), E> for TryIterConfigure +impl<'src, I, OA, E, A, F> Parser<'src, I, (), E> for TryIterConfigure where - A: ConfigIterParser<'a, I, OA, E>, + A: ConfigIterParser<'src, I, OA, E>, F: Fn(A::Config, &E::Context, I::Span) -> Result, - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let mut state = self.make_iter::(inp)?; loop { match self.next::(inp, &mut state) { @@ -154,21 +154,21 @@ where go_extra!(()); } -impl<'a, I, O, E, A, F> IterParser<'a, I, O, E> for TryIterConfigure +impl<'src, I, O, E, A, F> IterParser<'src, I, O, E> for TryIterConfigure where - A: ConfigIterParser<'a, I, O, E>, + A: ConfigIterParser<'src, I, O, E>, F: Fn(A::Config, &E::Context, I::Span) -> Result, - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { type IterState = (A::IterState, A::Config) where - I: 'a; + I: 'src; fn make_iter( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, ) -> PResult> { let span = inp.span_since(&inp.cursor()); let cfg = (self.cfg)(A::Config::default(), inp.ctx(), span) @@ -179,7 +179,7 @@ where fn next( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, state: &mut Self::IterState, ) -> IPResult { self.parser.next_cfg(inp, &mut state.0, &state.1) @@ -203,14 +203,14 @@ impl Clone for ToSlice { } } -impl<'a, A, I, O, E> Parser<'a, I, I::Slice, E> for ToSlice +impl<'src, A, I, O, E> Parser<'src, I, I::Slice, E> for ToSlice where - A: Parser<'a, I, O, E>, - I: SliceInput<'a>, - E: ParserExtra<'a, I>, + A: Parser<'src, I, O, E>, + I: SliceInput<'src>, + E: ParserExtra<'src, I>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized, { @@ -239,15 +239,15 @@ impl Clone for Filter { } } -impl<'a, A, I, O, E, F> Parser<'a, I, O, E> for Filter +impl<'src, A, I, O, E, F> Parser<'src, I, O, E> for Filter where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, E>, F: Fn(&O) -> bool, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); self.parser.go::(inp).and_then(|out| { if (self.filter)(&out) { @@ -282,15 +282,15 @@ impl Clone for Map { } } -impl<'a, I, O, E, A, OA, F> Parser<'a, I, O, E> for Map +impl<'src, I, O, E, A, OA, F> Parser<'src, I, O, E> for Map where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, F: Fn(OA) -> O, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let out = self.parser.go::(inp)?; Ok(M::map(out, &self.mapper)) } @@ -298,22 +298,22 @@ where go_extra!(O); } -impl<'a, I, O, E, A, OA, F> IterParser<'a, I, O, E> for Map +impl<'src, I, O, E, A, OA, F> IterParser<'src, I, O, E> for Map where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: IterParser<'a, I, OA, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: IterParser<'src, I, OA, E>, F: Fn(OA) -> O, { type IterState = A::IterState where - I: 'a; + I: 'src; #[inline(always)] fn make_iter( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, ) -> PResult> { self.parser.make_iter(inp) } @@ -321,7 +321,7 @@ where #[inline(always)] fn next( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, state: &mut Self::IterState, ) -> IPResult { match self.parser.next::(inp, state) { @@ -351,15 +351,15 @@ impl Clone for MapWith { } } -impl<'a, I, O, E, A, OA, F> Parser<'a, I, O, E> for MapWith +impl<'src, I, O, E, A, OA, F> Parser<'src, I, O, E> for MapWith where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - F: Fn(OA, &mut MapExtra<'a, '_, I, E>) -> O, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + F: Fn(OA, &mut MapExtra<'src, '_, I, E>) -> O, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); let out = self.parser.go::(inp)?; Ok(M::map(out, |out| { @@ -370,22 +370,22 @@ where go_extra!(O); } -impl<'a, I, O, E, A, OA, F> IterParser<'a, I, O, E> for MapWith +impl<'src, I, O, E, A, OA, F> IterParser<'src, I, O, E> for MapWith where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: IterParser<'a, I, OA, E>, - F: Fn(OA, &mut MapExtra<'a, '_, I, E>) -> O, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: IterParser<'src, I, OA, E>, + F: Fn(OA, &mut MapExtra<'src, '_, I, E>) -> O, { type IterState = A::IterState where - I: 'a; + I: 'src; #[inline(always)] fn make_iter( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, ) -> PResult> { self.parser.make_iter(inp) } @@ -393,7 +393,7 @@ where #[inline(always)] fn next( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, state: &mut Self::IterState, ) -> IPResult { let before = inp.cursor(); @@ -430,16 +430,16 @@ impl Clone for MapGroup { } #[cfg(feature = "nightly")] -impl<'a, I, O, E, A, OA, F> Parser<'a, I, O, E> for MapGroup +impl<'src, I, O, E, A, OA, F> Parser<'src, I, O, E> for MapGroup where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, F: Fn, OA: Tuple, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let out = self.parser.go::(inp)?; Ok(M::map(out, |out| self.mapper.call(out))) } @@ -448,23 +448,23 @@ where } #[cfg(feature = "nightly")] -impl<'a, I, O, E, A, OA, F> IterParser<'a, I, O, E> for MapGroup +impl<'src, I, O, E, A, OA, F> IterParser<'src, I, O, E> for MapGroup where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: IterParser<'a, I, OA, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: IterParser<'src, I, OA, E>, F: Fn, OA: Tuple, { type IterState = A::IterState where - I: 'a; + I: 'src; #[inline(always)] fn make_iter( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, ) -> PResult> { self.parser.make_iter(inp) } @@ -472,7 +472,7 @@ where #[inline(always)] fn next( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, state: &mut Self::IterState, ) -> IPResult { match self.parser.next::(inp, state) { @@ -500,14 +500,14 @@ impl Clone for ToSpan { } } -impl<'a, I, OA, E, A> Parser<'a, I, I::Span, E> for ToSpan +impl<'src, I, OA, E, A> Parser<'src, I, I::Span, E> for ToSpan where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); self.parser.go::(inp)?; Ok(M::bind(|| inp.span_since(&before))) @@ -535,15 +535,15 @@ impl Clone for TryMap { } } -impl<'a, I, O, E, A, OA, F> Parser<'a, I, O, E> for TryMap +impl<'src, I, O, E, A, OA, F> Parser<'src, I, O, E> for TryMap where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, F: Fn(OA, I::Span) -> Result, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); let out = self.parser.go::(inp)?; let span = inp.span_since(&before); @@ -578,15 +578,15 @@ impl Clone for TryMapWith { } } -impl<'a, I, O, E, A, OA, F> Parser<'a, I, O, E> for TryMapWith +impl<'src, I, O, E, A, OA, F> Parser<'src, I, O, E> for TryMapWith where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - F: Fn(OA, &mut MapExtra<'a, '_, I, E>) -> Result, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + F: Fn(OA, &mut MapExtra<'src, '_, I, E>) -> Result, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); let out = self.parser.go::(inp)?; match (self.mapper)(out, &mut MapExtra::new(&before, inp)) { @@ -620,15 +620,15 @@ impl Clone for To { } } -impl<'a, I, O, E, A, OA> Parser<'a, I, O, E> for To +impl<'src, I, O, E, A, OA> Parser<'src, I, O, E> for To where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, O: Clone, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { self.parser.go::(inp)?; Ok(M::bind(|| self.to.clone())) } @@ -653,11 +653,11 @@ impl Clone for IntoIter { } } -impl<'a, A, O, I, E> IterParser<'a, I, O::Item, E> for IntoIter +impl<'src, A, O, I, E> IterParser<'src, I, O::Item, E> for IntoIter where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, E>, O: IntoIterator, { // TODO: Don't always produce output for non-emitting modes, but needed due to length. Use some way to 'select' @@ -669,7 +669,7 @@ where #[inline(always)] fn make_iter( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, ) -> PResult> { // M::map(self.parser.go::(inp)?, |out| out.into_iter()) self.parser.go::(inp).map(|out| out.into_iter()) @@ -678,7 +678,7 @@ where #[inline(always)] fn next( &self, - _inp: &mut InputRef<'a, '_, I, E>, + _inp: &mut InputRef<'src, '_, I, E>, iter: &mut Self::IterState, ) -> IPResult { Ok(iter.next().map(|out| M::bind(|| out))) @@ -702,14 +702,14 @@ impl Clone for Ignored { } } -impl<'a, I, E, A, OA> Parser<'a, I, (), E> for Ignored +impl<'src, I, E, A, OA> Parser<'src, I, (), E> for Ignored where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { self.parser.go::(inp)?; Ok(M::bind(|| ())) } @@ -736,15 +736,15 @@ impl Clone for Unwrapped { } } -impl<'a, I, E, A, O, U> Parser<'a, I, O, E> for Unwrapped> +impl<'src, I, E, A, O, U> Parser<'src, I, O, E> for Unwrapped> where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, Result, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, Result, E>, U: fmt::Debug, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let out = self.parser.go::(inp)?; Ok(M::map(out, |out| match out { Ok(out) => out, @@ -758,14 +758,14 @@ where go_extra!(O); } -impl<'a, I, E, A, O> Parser<'a, I, O, E> for Unwrapped> +impl<'src, I, E, A, O> Parser<'src, I, O, E> for Unwrapped> where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, Option, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, Option, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let out = self.parser.go::(inp)?; Ok(M::map(out, |out| match out { Some(out) => out, @@ -787,15 +787,15 @@ pub struct Memoized { } #[cfg(feature = "memoization")] -impl<'a, I, E, A, O> Parser<'a, I, O, E> for Memoized +impl<'src, I, E, A, O> Parser<'src, I, O, E> for Memoized where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, E::Error: Clone, - A: Parser<'a, I, O, E>, + A: Parser<'src, I, O, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); // TODO: Don't use address, since this might not be constant? let key = ( @@ -853,15 +853,15 @@ impl Clone for Then { } } -impl<'a, I, E, A, B, OA, OB> Parser<'a, I, (OA, OB), E> for Then +impl<'src, I, E, A, B, OA, OB> Parser<'src, I, (OA, OB), E> for Then where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - B: Parser<'a, I, OB, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + B: Parser<'src, I, OB, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let a = self.parser_a.go::(inp)?; let b = self.parser_b.go::(inp)?; Ok(M::combine(a, b, |a: OA, b: OB| (a, b))) @@ -889,15 +889,15 @@ impl Clone for IgnoreThen { } } -impl<'a, I, E, A, B, OA, OB> Parser<'a, I, OB, E> for IgnoreThen +impl<'src, I, E, A, B, OA, OB> Parser<'src, I, OB, E> for IgnoreThen where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - B: Parser<'a, I, OB, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + B: Parser<'src, I, OB, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { self.parser_a.go::(inp)?; let b = self.parser_b.go::(inp)?; Ok(M::map(b, |b: OB| b)) @@ -925,15 +925,15 @@ impl Clone for ThenIgnore { } } -impl<'a, I, E, A, B, OA, OB> Parser<'a, I, OA, E> for ThenIgnore +impl<'src, I, E, A, B, OA, OB> Parser<'src, I, OA, E> for ThenIgnore where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - B: Parser<'a, I, OB, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + B: Parser<'src, I, OB, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let a = self.parser_a.go::(inp)?; self.parser_b.go::(inp)?; Ok(M::map(a, |a: OA| a)) @@ -961,17 +961,17 @@ impl Clone for NestedIn { } } -impl<'a, I, J, E, F, A, B, O> Parser<'a, I, O, E> for NestedIn +impl<'src, I, J, E, F, A, B, O> Parser<'src, I, O, E> for NestedIn where - I: Input<'a>, - E: ParserExtra<'a, I>, - B: Parser<'a, I, J, E>, - J: Input<'a>, - F: ParserExtra<'a, J, State = E::State, Context = E::Context, Error = E::Error>, - A: Parser<'a, J, O, F>, + I: Input<'src>, + E: ParserExtra<'src, I>, + B: Parser<'src, I, J, E>, + J: Input<'src>, + F: ParserExtra<'src, J, State = E::State, Context = E::Context, Error = E::Error>, + A: Parser<'src, J, O, F>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let inp2 = self.parser_b.go::(inp)?; let alt = inp.errors.alt.take(); @@ -1020,17 +1020,17 @@ impl Clone for IgnoreWithCtx { } } -impl<'a, I, E, A, B, OA, OB> Parser<'a, I, OB, E> +impl<'src, I, E, A, B, OA, OB> Parser<'src, I, OB, E> for IgnoreWithCtx> where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - B: Parser<'a, I, OB, extra::Full>, - OA: 'a, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + B: Parser<'src, I, OB, extra::Full>, + OA: 'src, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let p1 = self.parser.go::(inp)?; inp.with_ctx(&p1, |inp| self.then.go::(inp)) } @@ -1038,24 +1038,24 @@ where go_extra!(OB); } -impl<'a, I, E, A, B, OA, OB> IterParser<'a, I, OB, E> +impl<'src, I, E, A, B, OA, OB> IterParser<'src, I, OB, E> for IgnoreWithCtx> where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - B: IterParser<'a, I, OB, extra::Full>, - OA: 'a, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + B: IterParser<'src, I, OB, extra::Full>, + OA: 'src, { type IterState = (OA, B::IterState) where - I: 'a; + I: 'src; #[inline(always)] fn make_iter( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, ) -> PResult> { let out = self.parser.go::(inp)?; let then = inp.with_ctx(&out, |inp| self.then.make_iter::(inp))?; @@ -1065,7 +1065,7 @@ where #[inline(always)] fn next( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, state: &mut Self::IterState, ) -> IPResult { let (ctx, inner_state) = state; @@ -1093,17 +1093,17 @@ impl Clone for ThenWithCtx { } } -impl<'a, I, E, A, B, OA, OB> Parser<'a, I, (OA, OB), E> +impl<'src, I, E, A, B, OA, OB> Parser<'src, I, (OA, OB), E> for ThenWithCtx> where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - B: Parser<'a, I, OB, extra::Full>, - OA: 'a, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + B: Parser<'src, I, OB, extra::Full>, + OA: 'src, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let p1 = self.parser.go::(inp)?; let p2 = inp.with_ctx(&p1, |inp| self.then.go::(inp))?; Ok(M::map(p2, |p2| (p1, p2))) @@ -1112,24 +1112,24 @@ where go_extra!((OA, OB)); } -impl<'a, I, E, A, B, OA, OB> IterParser<'a, I, OB, E> +impl<'src, I, E, A, B, OA, OB> IterParser<'src, I, OB, E> for ThenWithCtx> where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - B: IterParser<'a, I, OB, extra::Full>, - OA: 'a, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + B: IterParser<'src, I, OB, extra::Full>, + OA: 'src, { type IterState = (OA, B::IterState) where - I: 'a; + I: 'src; #[inline(always)] fn make_iter( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, ) -> PResult> { let out = self.parser.go::(inp)?; let then = inp.with_ctx(&out, |inp| self.then.make_iter::(inp))?; @@ -1139,7 +1139,7 @@ where #[inline(always)] fn next( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, state: &mut Self::IterState, ) -> IPResult { let (ctx, inner_state) = state; @@ -1164,15 +1164,15 @@ impl Clone for WithCtx { } } -impl<'a, I, O, E, A, Ctx> Parser<'a, I, O, E> for WithCtx +impl<'src, I, O, E, A, Ctx> Parser<'src, I, O, E> for WithCtx where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, extra::Full>, - Ctx: 'a, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, extra::Full>, + Ctx: 'src, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { inp.with_ctx(&self.ctx, |inp| self.parser.go::(inp)) } @@ -1195,15 +1195,15 @@ impl Clone for WithState { } } -impl<'a, I, O, E, A, State> Parser<'a, I, O, E> for WithState +impl<'src, I, O, E, A, State> Parser<'src, I, O, E> for WithState where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, extra::Full>, - State: 'a + Clone + Inspector<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, extra::Full>, + State: 'src + Clone + Inspector<'src, I>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { inp.with_state(&mut self.state.clone(), |inp| self.parser.go::(inp)) } @@ -1231,16 +1231,16 @@ impl Clone for DelimitedBy Parser<'a, I, OA, E> for DelimitedBy +impl<'src, I, E, A, B, C, OA, OB, OC> Parser<'src, I, OA, E> for DelimitedBy where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - B: Parser<'a, I, OB, E>, - C: Parser<'a, I, OC, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + B: Parser<'src, I, OB, E>, + C: Parser<'src, I, OC, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { self.start.go::(inp)?; let a = self.parser.go::(inp)?; self.end.go::(inp)?; @@ -1269,15 +1269,15 @@ impl Clone for PaddedBy { } } -impl<'a, I, E, A, B, OA, OB> Parser<'a, I, OA, E> for PaddedBy +impl<'src, I, E, A, B, OA, OB> Parser<'src, I, OA, E> for PaddedBy where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - B: Parser<'a, I, OB, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + B: Parser<'src, I, OB, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { self.padding.go::(inp)?; let a = self.parser.go::(inp)?; self.padding.go::(inp)?; @@ -1293,15 +1293,15 @@ pub struct Or { pub(crate) choice: crate::primitive::Choice<(A, B)>, } -impl<'a, I, O, E, A, B> Parser<'a, I, O, E> for Or +impl<'src, I, O, E, A, B> Parser<'src, I, O, E> for Or where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, E>, - B: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, E>, + B: Parser<'src, I, O, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { self.choice.go::(inp) } @@ -1362,11 +1362,11 @@ impl Clone for Repeated { } } -impl<'a, A, OA, I, E> Repeated +impl<'src, A, OA, I, E> Repeated where - A: Parser<'a, I, OA, E>, - I: Input<'a>, - E: ParserExtra<'a, I>, + A: Parser<'src, I, OA, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, { /// Require that the pattern appear at least a minimum number of times. pub fn at_least(self, at_least: usize) -> Self { @@ -1429,15 +1429,15 @@ where } } -impl<'a, I, E, A, OA> Parser<'a, I, (), E> for Repeated +impl<'src, I, E, A, OA> Parser<'src, I, (), E> for Repeated where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, { #[inline(always)] #[allow(clippy::nonminimal_bool)] // TODO: Remove this, lint is currently buggy - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { if self.at_most == !0 && self.at_least == 0 { loop { let before = inp.save(); @@ -1483,18 +1483,18 @@ where go_extra!(()); } -impl<'a, A, O, I, E> IterParser<'a, I, O, E> for Repeated +impl<'src, A, O, I, E> IterParser<'src, I, O, E> for Repeated where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, E>, { type IterState = usize; #[inline(always)] fn make_iter( &self, - _inp: &mut InputRef<'a, '_, I, E>, + _inp: &mut InputRef<'src, '_, I, E>, ) -> PResult> { Ok(0) } @@ -1502,7 +1502,7 @@ where #[inline(always)] fn next( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, count: &mut Self::IterState, ) -> IPResult { if *count as u64 >= self.at_most { @@ -1527,18 +1527,18 @@ where } } -impl<'a, A, O, I, E> ConfigIterParser<'a, I, O, E> for Repeated +impl<'src, A, O, I, E> ConfigIterParser<'src, I, O, E> for Repeated where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, E>, { type Config = RepeatedCfg; #[inline(always)] fn next_cfg( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, count: &mut Self::IterState, cfg: &Self::Config, ) -> IPResult { @@ -1599,12 +1599,12 @@ impl Clone for SeparatedBy } } -impl<'a, A, B, OA, OB, I, E> SeparatedBy +impl<'src, A, B, OA, OB, I, E> SeparatedBy where - A: Parser<'a, I, OA, E>, - B: Parser<'a, I, OB, E>, - I: Input<'a>, - E: ParserExtra<'a, I>, + A: Parser<'src, I, OA, E>, + B: Parser<'src, I, OB, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, { /// Require that the pattern appear at least a minimum number of times. /// @@ -1736,22 +1736,22 @@ where } } -impl<'a, I, E, A, B, OA, OB> IterParser<'a, I, OA, E> for SeparatedBy +impl<'src, I, E, A, B, OA, OB> IterParser<'src, I, OA, E> for SeparatedBy where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - B: Parser<'a, I, OB, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + B: Parser<'src, I, OB, E>, { type IterState = usize where - I: 'a; + I: 'src; #[inline(always)] fn make_iter( &self, - _inp: &mut InputRef<'a, '_, I, E>, + _inp: &mut InputRef<'src, '_, I, E>, ) -> PResult> { Ok(0) } @@ -1759,7 +1759,7 @@ where #[inline(always)] fn next( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, state: &mut Self::IterState, ) -> IPResult { if *state as u64 >= self.at_most { @@ -1817,15 +1817,15 @@ where } } -impl<'a, I, E, A, B, OA, OB> Parser<'a, I, (), E> for SeparatedBy +impl<'src, I, E, A, B, OA, OB> Parser<'src, I, (), E> for SeparatedBy where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - B: Parser<'a, I, OB, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + B: Parser<'src, I, OB, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let mut state = self.make_iter::(inp)?; loop { #[cfg(debug_assertions)] @@ -1867,21 +1867,21 @@ impl Clone for Enumerate { } } -impl<'a, I, O, E, A> IterParser<'a, I, (usize, O), E> for Enumerate +impl<'src, I, O, E, A> IterParser<'src, I, (usize, O), E> for Enumerate where - A: IterParser<'a, I, O, E>, - I: Input<'a>, - E: ParserExtra<'a, I>, + A: IterParser<'src, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, { type IterState = (usize, A::IterState) where - I: 'a; + I: 'src; #[inline(always)] fn make_iter( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, ) -> PResult> { Ok((0, A::make_iter(&self.parser, inp)?)) } @@ -1889,7 +1889,7 @@ where #[inline(always)] fn next( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, state: &mut Self::IterState, ) -> IPResult { let out = self @@ -1922,15 +1922,15 @@ impl Clone for Collect { } } -impl<'a, I, O, E, A, C> Parser<'a, I, C, E> for Collect +impl<'src, I, O, E, A, C> Parser<'src, I, C, E> for Collect where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: IterParser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: IterParser<'src, I, O, E>, C: Container, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let mut output = M::bind::(|| C::default()); let mut iter_state = self.parser.make_iter::(inp)?; #[cfg(debug_assertions)] @@ -1981,15 +1981,15 @@ impl Clone for CollectExactly { } } -impl<'a, I, O, E, A, C> Parser<'a, I, C, E> for CollectExactly +impl<'src, I, O, E, A, C> Parser<'src, I, C, E> for CollectExactly where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: IterParser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: IterParser<'src, I, O, E>, C: ContainerExactly, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); let mut output = M::bind(|| C::uninit()); let mut iter_state = self.parser.make_iter::(inp)?; @@ -2029,14 +2029,14 @@ pub struct OrNot { pub(crate) parser: A, } -impl<'a, I, O, E, A> Parser<'a, I, Option, E> for OrNot +impl<'src, I, O, E, A> Parser<'src, I, Option, E> for OrNot where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult> { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult> { let before = inp.save(); Ok(match self.parser.go::(inp) { Ok(out) => M::map::(out, Some), @@ -2050,18 +2050,18 @@ where go_extra!(Option); } -impl<'a, A, O, I, E> IterParser<'a, I, O, E> for OrNot +impl<'src, A, O, I, E> IterParser<'src, I, O, E> for OrNot where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, E>, { type IterState = bool; #[inline(always)] fn make_iter( &self, - _inp: &mut InputRef<'a, '_, I, E>, + _inp: &mut InputRef<'src, '_, I, E>, ) -> PResult> { Ok(false) } @@ -2069,7 +2069,7 @@ where #[inline(always)] fn next( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, finished: &mut Self::IterState, ) -> IPResult { if *finished { @@ -2108,14 +2108,14 @@ impl Clone for Not { } } -impl<'a, I, E, A, OA> Parser<'a, I, (), E> for Not +impl<'src, I, E, A, OA> Parser<'src, I, (), E> for Not where - I: ValueInput<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, + I: ValueInput<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.save(); let alt = inp.errors.alt.take(); @@ -2160,11 +2160,11 @@ impl Clone for Flatten { } #[cfg(feature = "nightly")] -impl<'a, A, O, I, E> IterParser<'a, I, O::Item, E> for Flatten +impl<'src, A, O, I, E> IterParser<'src, I, O::Item, E> for Flatten where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: IterParser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: IterParser<'src, I, O, E>, O: IntoIterator, { type IterState = (A::IterState, Option>); @@ -2172,7 +2172,7 @@ where #[inline(always)] fn make_iter( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, ) -> PResult> { Ok((self.parser.make_iter(inp)?, None)) } @@ -2180,7 +2180,7 @@ where #[inline(always)] fn next( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, (st, iter): &mut Self::IterState, ) -> IPResult { if let Some(item) = iter @@ -2234,15 +2234,15 @@ impl Clone for AndIs { } } -impl<'a, I, E, A, B, OA, OB> Parser<'a, I, OA, E> for AndIs +impl<'src, I, E, A, B, OA, OB> Parser<'src, I, OA, E> for AndIs where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - B: Parser<'a, I, OB, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + B: Parser<'src, I, OB, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.save().clone(); match self.parser_a.go::(inp) { Ok(out) => { @@ -2298,16 +2298,16 @@ impl Clone for Foldr { } } -impl<'a, I, F, A, B, O, OA, E> Parser<'a, I, O, E> for Foldr +impl<'src, I, F, A, B, O, OA, E> Parser<'src, I, O, E> for Foldr where - I: Input<'a>, - A: IterParser<'a, I, OA, E>, - B: Parser<'a, I, O, E>, - E: ParserExtra<'a, I>, + I: Input<'src>, + A: IterParser<'src, I, OA, E>, + B: Parser<'src, I, O, E>, + E: ParserExtra<'src, I>, F: Fn(OA, O) -> O, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized, { @@ -2368,16 +2368,16 @@ impl Clone for FoldrWith { } } -impl<'a, I, F, A, B, O, OA, E> Parser<'a, I, O, E> for FoldrWith +impl<'src, I, F, A, B, O, OA, E> Parser<'src, I, O, E> for FoldrWith where - I: Input<'a>, - A: IterParser<'a, I, OA, E>, - B: Parser<'a, I, O, E>, - E: ParserExtra<'a, I>, - F: Fn(OA, O, &mut MapExtra<'a, '_, I, E>) -> O, + I: Input<'src>, + A: IterParser<'src, I, OA, E>, + B: Parser<'src, I, O, E>, + E: ParserExtra<'src, I>, + F: Fn(OA, O, &mut MapExtra<'src, '_, I, E>) -> O, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized, { @@ -2441,16 +2441,16 @@ impl Clone for Foldl { } } -impl<'a, I, F, A, B, O, OB, E> Parser<'a, I, O, E> for Foldl +impl<'src, I, F, A, B, O, OB, E> Parser<'src, I, O, E> for Foldl where - I: Input<'a>, - A: Parser<'a, I, O, E>, - B: IterParser<'a, I, OB, E>, - E: ParserExtra<'a, I>, + I: Input<'src>, + A: Parser<'src, I, O, E>, + B: IterParser<'src, I, OB, E>, + E: ParserExtra<'src, I>, F: Fn(O, OB) -> O, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized, { @@ -2505,16 +2505,16 @@ impl Clone for FoldlWith { } } -impl<'a, I, F, A, B, O, OB, E> Parser<'a, I, O, E> for FoldlWith +impl<'src, I, F, A, B, O, OB, E> Parser<'src, I, O, E> for FoldlWith where - I: Input<'a>, - A: Parser<'a, I, O, E>, - B: IterParser<'a, I, OB, E>, - E: ParserExtra<'a, I>, - F: Fn(O, OB, &mut MapExtra<'a, '_, I, E>) -> O, + I: Input<'src>, + A: Parser<'src, I, O, E>, + B: IterParser<'src, I, OB, E>, + E: ParserExtra<'src, I>, + F: Fn(O, OB, &mut MapExtra<'src, '_, I, E>) -> O, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized, { @@ -2554,14 +2554,14 @@ pub struct Rewind { pub(crate) parser: A, } -impl<'a, I, O, E, A> Parser<'a, I, O, E> for Rewind +impl<'src, I, O, E, A> Parser<'src, I, O, E> for Rewind where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.save(); match self.parser.go::(inp) { Ok(out) => { @@ -2582,15 +2582,15 @@ pub struct MapErr { pub(crate) mapper: F, } -impl<'a, I, O, E, A, F> Parser<'a, I, O, E> for MapErr +impl<'src, I, O, E, A, F> Parser<'src, I, O, E> for MapErr where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, E>, F: Fn(E::Error) -> E::Error, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized, { @@ -2615,15 +2615,15 @@ where // pub(crate) mapper: F, // } -// impl<'a, I, O, E, A, F> Parser<'a, I, O, E> for MapErrWithSpan +// impl<'src, I, O, E, A, F> Parser<'src, I, O, E> for MapErrWithSpan // where -// I: Input<'a>, -// E: ParserExtra<'a, I>, -// A: Parser<'a, I, O, E>, +// I: Input<'src>, +// E: ParserExtra<'src, I>, +// A: Parser<'src, I, O, E>, // F: Fn(E::Error, I::Span) -> E::Error, // { // #[inline(always)] -// fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult +// fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult // where // Self: Sized, // { @@ -2650,15 +2650,15 @@ pub struct MapErrWithState { pub(crate) mapper: F, } -impl<'a, I, O, E, A, F> Parser<'a, I, O, E> for MapErrWithState +impl<'src, I, O, E, A, F> Parser<'src, I, O, E> for MapErrWithState where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, E>, F: Fn(E::Error, I::Span, &mut E::State) -> E::Error, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized, { @@ -2697,15 +2697,15 @@ impl Clone for Validate { } } -impl<'a, I, OA, U, E, A, F> Parser<'a, I, U, E> for Validate +impl<'src, I, OA, U, E, A, F> Parser<'src, I, U, E> for Validate where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, OA, E>, - F: Fn(OA, &mut MapExtra<'a, '_, I, E>, &mut Emitter) -> U, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, OA, E>, + F: Fn(OA, &mut MapExtra<'src, '_, I, E>, &mut Emitter) -> U, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized, { @@ -2730,15 +2730,15 @@ where // pub(crate) or_else: F, // } -// impl<'a, I, O, E, A, F> Parser<'a, I, O, E> for OrElse +// impl<'src, I, O, E, A, F> Parser<'src, I, O, E> for OrElse // where -// I: Input<'a>, -// E: ParserExtra<'a, I>, -// A: Parser<'a, I, O, E>, +// I: Input<'src>, +// E: ParserExtra<'src, I>, +// A: Parser<'src, I, O, E>, // F: Fn(E::Error) -> Result, // { // #[inline(always)] -// fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult +// fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult // where // Self: Sized, // { diff --git a/src/either.rs b/src/either.rs index b29105ab..c8473649 100644 --- a/src/either.rs +++ b/src/either.rs @@ -4,16 +4,16 @@ use super::*; use ::either::Either; -impl<'a, L, R, I, O, E> Parser<'a, I, O, E> for Either +impl<'src, L, R, I, O, E> Parser<'src, I, O, E> for Either where - I: Input<'a>, - E: ParserExtra<'a, I>, - L: Parser<'a, I, O, E>, - R: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + L: Parser<'src, I, O, E>, + R: Parser<'src, I, O, E>, { fn go( &self, - inp: &mut crate::input::InputRef<'a, '_, I, E>, + inp: &mut crate::input::InputRef<'src, '_, I, E>, ) -> crate::private::PResult where Self: Sized, @@ -35,7 +35,7 @@ mod tests { }; use either::Either; - fn parser<'a>() -> impl Parser<'a, &'a str, Vec> { + fn parser<'src>() -> impl Parser<'src, &'src str, Vec> { any() .filter(|c: &char| c.is_ascii_digit()) .repeated() diff --git a/src/extension.rs b/src/extension.rs index 7402ccef..43956f46 100644 --- a/src/extension.rs +++ b/src/extension.rs @@ -21,12 +21,12 @@ //! pub struct Null_; //! //! // We implement `ExtParser` for our null byte parser, plugging us into the chumsky ecosystem -//! impl<'a, I, E> ExtParser<'a, I, (), E> for Null_ +//! impl<'src, I, E> ExtParser<'src, I, (), E> for Null_ //! where -//! I: Input<'a, Token = u8>, -//! E: extra::ParserExtra<'a, I>, +//! I: Input<'src, Token = u8>, +//! E: extra::ParserExtra<'src, I>, //! { -//! fn parse(&self, inp: &mut InputRef<'a, '_, I, E>) -> Result<(), E::Error> { +//! fn parse(&self, inp: &mut InputRef<'src, '_, I, E>) -> Result<(), E::Error> { //! let before = inp.cursor(); //! match inp.next_maybe().as_deref() { //! // The next token was a null byte, meaning that parsing was successful @@ -53,7 +53,7 @@ //! } //! //! // Let's give our parser a test! -//! fn make_parser<'a>() -> impl Parser<'a, &'a [u8], ()> { +//! fn make_parser<'src>() -> impl Parser<'src, &'src [u8], ()> { //! null() //! } //! @@ -92,15 +92,15 @@ mod current { /// /// pub struct FrobnicatedWith { a: A, b: B } /// - /// pub trait ParserExt<'a, I, O, E> + /// pub trait ParserExt<'src, I, O, E> /// where - /// I: Input<'a>, - /// E: extra::ParserExtra<'a, I> + /// I: Input<'src>, + /// E: extra::ParserExtra<'src, I> /// { /// fn frobnicated_with(self, other: B) -> FrobnicatedWith /// where /// Self: Sized, - /// B: Parser<'a, I, O, E>, + /// B: Parser<'src, I, O, E>, /// { /// FrobnicatedWith { a: self, b: other } /// } @@ -108,11 +108,11 @@ mod current { /// ``` /// /// Now, users can import your trait and do `a.frobnicate_with(b)` as if your parser were native to chumsky! - pub trait ExtParser<'a, I: Input<'a>, O, E: ParserExtra<'a, I>> { + pub trait ExtParser<'src, I: Input<'src>, O, E: ParserExtra<'src, I>> { /// Attempt parsing on the given input. /// /// See [`InputRef`] for more information about how you can work with parser inputs. - fn parse(&self, inp: &mut InputRef<'a, '_, I, E>) -> Result; + fn parse(&self, inp: &mut InputRef<'src, '_, I, E>) -> Result; /// Attempt to check the given input. /// @@ -123,7 +123,7 @@ mod current { /// /// By default, this method just uses `ExtParser::parse`, dropping the output. You may want to override the /// implementation so that this output is never even generated, thereby improving performance. - fn check(&self, inp: &mut InputRef<'a, '_, I, E>) -> Result<(), E::Error> { + fn check(&self, inp: &mut InputRef<'src, '_, I, E>) -> Result<(), E::Error> { self.parse(inp).map(|_| ()) } } @@ -145,14 +145,14 @@ mod current { #[repr(transparent)] pub struct Ext(pub T); - impl<'a, I, O, E, P> Parser<'a, I, O, E> for Ext

+ impl<'src, I, O, E, P> Parser<'src, I, O, E> for Ext

, } -impl<'a, 'b, I: Input<'a>, O, E: ParserExtra<'a, I>> Recursive> { +impl<'src, 'b, I: Input<'src>, O, E: ParserExtra<'src, I>> Recursive> { /// Declare the existence of a recursive parser, allowing it to be used to construct parser combinators before /// being fulled defined. /// @@ -134,7 +134,7 @@ impl<'a, 'b, I: Input<'a>, O, E: ParserExtra<'a, I>> Recursive + Clone + MaybeSync + 'a + 'b>(&mut self, parser: P) { + pub fn define + Clone + MaybeSync + 'src + 'b>(&mut self, parser: P) { let location = *Location::caller(); self.parser() .inner @@ -179,13 +179,13 @@ pub(crate) fn recurse R>(f: F) -> R { f() } -impl<'a, I, O, E> Parser<'a, I, O, E> for Recursive> +impl<'src, I, O, E> Parser<'src, I, O, E> for Recursive> where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { recurse(move || { M::invoke( self.parser() @@ -201,13 +201,13 @@ where go_extra!(O); } -impl<'a, I, O, E> Parser<'a, I, O, E> for Recursive> +impl<'src, I, O, E> Parser<'src, I, O, E> for Recursive> where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { recurse(move || M::invoke(&*self.parser(), inp)) } @@ -227,9 +227,9 @@ where /// ``` /// # use chumsky::prelude::*; /// #[derive(Debug, PartialEq)] -/// enum Tree<'a> { -/// Leaf(&'a str), -/// Branch(Vec>), +/// enum Tree<'src> { +/// Leaf(&'src str), +/// Branch(Vec>), /// } /// /// // Parser that recursively parses nested lists @@ -264,15 +264,15 @@ where /// ]))); /// ``` // INFO: Clone bound not actually needed, but good to be safe for future compat -pub fn recursive<'a, 'b, I, O, E, A, F>(f: F) -> Recursive> +pub fn recursive<'src, 'b, I, O, E, A, F>(f: F) -> Recursive> where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, E> + Clone + MaybeSync + 'b, - F: FnOnce(Recursive>) -> A, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, E> + Clone + MaybeSync + 'b, + F: FnOnce(Recursive>) -> A, { let rc = RefC::new_cyclic(|rc| { - let rc: RefW> = rc.clone() as _; + let rc: RefW> = rc.clone() as _; let parser = Recursive { inner: RecursiveInner::Unowned(rc.clone()), }; diff --git a/src/regex.rs b/src/regex.rs index 5920c80c..2d322abb 100644 --- a/src/regex.rs +++ b/src/regex.rs @@ -27,14 +27,14 @@ pub fn regex(pattern: &str) -> Regex { } } -impl<'a, C, I, E> Parser<'a, I, &'a C::Str, E> for Regex +impl<'src, C, I, E> Parser<'src, I, &'src C::Str, E> for Regex where C: Char, - I: StrInput<'a, C>, - E: ParserExtra<'a, I>, + I: StrInput<'src, C>, + E: ParserExtra<'src, I>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); let re_in = ReInput::new(inp.full_slice()) @@ -62,7 +62,7 @@ where } } - go_extra!(&'a C::Str); + go_extra!(&'src C::Str); } #[cfg(test)] @@ -74,7 +74,8 @@ mod tests { use self::prelude::*; use self::regex::*; - fn parser<'a, C: Char, I: StrInput<'a, C>>() -> impl Parser<'a, I, Vec<&'a C::Str>> { + fn parser<'src, C: Char, I: StrInput<'src, C>>() -> impl Parser<'src, I, Vec<&'src C::Str>> + { regex("[a-zA-Z_][a-zA-Z0-9_]*") .padded() .repeated() diff --git a/src/text.rs b/src/text.rs index b4f9ce1e..f84407ec 100644 --- a/src/text.rs +++ b/src/text.rs @@ -45,7 +45,7 @@ pub trait Char: Sized + Copy + PartialEq + fmt::Debug + Sealed + 'static { fn to_char(&self) -> char; /// The iterator returned by `Self::str_to_chars`. - type StrCharIter<'a>: Iterator; + type StrCharIter<'src>: Iterator; /// Turn a string of this character type into an iterator over those characters. fn str_to_chars(s: &Self::Str) -> Self::StrCharIter<'_>; @@ -74,7 +74,7 @@ impl Char for char { *self } - type StrCharIter<'a> = core::str::Chars<'a>; + type StrCharIter<'src> = core::str::Chars<'src>; fn str_to_chars(s: &Self::Str) -> Self::StrCharIter<'_> { s.chars() } @@ -111,7 +111,7 @@ impl Char for u8 { *self as char } - type StrCharIter<'a> = core::iter::Copied>; + type StrCharIter<'src> = core::iter::Copied>; fn str_to_chars(s: &Self::Str) -> Self::StrCharIter<'_> { s.iter().copied() } @@ -131,14 +131,14 @@ pub struct Padded { pub(crate) parser: A, } -impl<'a, I, O, E, A> Parser<'a, I, O, E> for Padded +impl<'src, I, O, E, A> Parser<'src, I, O, E> for Padded where - I: ValueInput<'a>, - E: ParserExtra<'a, I>, + I: ValueInput<'src>, + E: ParserExtra<'src, I>, I::Token: Char, - A: Parser<'a, I, O, E>, + A: Parser<'src, I, O, E>, { - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { inp.skip_while(|c| c.is_whitespace()); let out = self.parser.go::(inp)?; inp.skip_while(|c| c.is_whitespace()); @@ -165,8 +165,8 @@ where /// // ...including none at all! /// assert_eq!(whitespace.parse("").into_result(), Ok(())); /// ``` -pub fn whitespace<'a, C: Char, I: ValueInput<'a> + StrInput<'a, C>, E: ParserExtra<'a, I>>( -) -> Repeated + Copy, (), I, E> +pub fn whitespace<'src, C: Char, I: ValueInput<'src> + StrInput<'src, C>, E: ParserExtra<'src, I>>( +) -> Repeated + Copy, (), I, E> where I::Token: Char, { @@ -194,8 +194,12 @@ where /// // ... but not newlines /// assert!(inline_whitespace.at_least(1).parse("\n\r").has_errors()); /// ``` -pub fn inline_whitespace<'a, C: Char, I: ValueInput<'a> + StrInput<'a, C>, E: ParserExtra<'a, I>>( -) -> Repeated + Copy, (), I, E> +pub fn inline_whitespace< + 'src, + C: Char, + I: ValueInput<'src> + StrInput<'src, C>, + E: ParserExtra<'src, I>, +>() -> Repeated + Copy, (), I, E> where I::Token: Char, { @@ -235,7 +239,8 @@ where /// assert_eq!(newline.parse("\u{2029}").into_result(), Ok(())); /// ``` #[must_use] -pub fn newline<'a, I: ValueInput<'a>, E: ParserExtra<'a, I>>() -> impl Parser<'a, I, (), E> + Copy +pub fn newline<'src, I: ValueInput<'src>, E: ParserExtra<'src, I>>( +) -> impl Parser<'src, I, (), E> + Copy where I::Token: Char, { @@ -278,11 +283,11 @@ where /// assert!(digits.parse("").has_errors()); /// ``` #[must_use] -pub fn digits<'a, C, I, E>(radix: u32) -> Repeated + Copy, C, I, E> +pub fn digits<'src, C, I, E>(radix: u32) -> Repeated + Copy, C, I, E> where C: Char, - I: ValueInput<'a, Token = C>, - E: ParserExtra<'a, I>, + I: ValueInput<'src, Token = C>, + E: ParserExtra<'src, I>, { any() // Use try_map over filter to get a better error on failure @@ -328,9 +333,9 @@ where /// ``` /// #[must_use] -pub fn int<'a, I: StrInput<'a, C>, C: Char, E: ParserExtra<'a, I>>( +pub fn int<'src, I: StrInput<'src, C>, C: Char, E: ParserExtra<'src, I>>( radix: u32, -) -> impl Parser<'a, I, &'a C::Str, E> + Copy { +) -> impl Parser<'src, I, &'src C::Str, E> + Copy { any() // Use try_map over filter to get a better error on failure .try_map(move |c: C, span| { @@ -359,8 +364,12 @@ pub mod ascii { /// An identifier is defined as an ASCII alphabetic character or an underscore followed by any number of alphanumeric /// characters or underscores. The regex pattern for it is `[a-zA-Z_][a-zA-Z0-9_]*`. #[must_use] - pub fn ident<'a, I: ValueInput<'a> + StrInput<'a, C>, C: Char, E: ParserExtra<'a, I>>( - ) -> impl Parser<'a, I, &'a C::Str, E> + Copy { + pub fn ident< + 'src, + I: ValueInput<'src> + StrInput<'src, C>, + C: Char, + E: ParserExtra<'src, I>, + >() -> impl Parser<'src, I, &'src C::Str, E> + Copy { any() // Use try_map over filter to get a better error on failure .try_map(|c: C, span| { @@ -398,14 +407,14 @@ pub mod ascii { /// ``` #[track_caller] pub fn keyword< - 'a, - I: ValueInput<'a> + StrInput<'a, C>, - C: Char + 'a, - Str: AsRef + 'a + Clone, - E: ParserExtra<'a, I> + 'a, + 'src, + I: ValueInput<'src> + StrInput<'src, C>, + C: Char + 'src, + Str: AsRef + 'src + Clone, + E: ParserExtra<'src, I> + 'src, >( keyword: Str, - ) -> impl Parser<'a, I, &'a C::Str, E> + Clone + 'a + ) -> impl Parser<'src, I, &'src C::Str, E> + Clone + 'src where C::Str: PartialEq, { @@ -447,8 +456,12 @@ pub mod unicode { /// /// An identifier is defined as per "Default Identifiers" in [Unicode Standard Annex #31](https://www.unicode.org/reports/tr31/). #[must_use] - pub fn ident<'a, I: ValueInput<'a> + StrInput<'a, C>, C: Char, E: ParserExtra<'a, I>>( - ) -> impl Parser<'a, I, &'a C::Str, E> + Copy { + pub fn ident< + 'src, + I: ValueInput<'src> + StrInput<'src, C>, + C: Char, + E: ParserExtra<'src, I>, + >() -> impl Parser<'src, I, &'src C::Str, E> + Copy { any() // Use try_map over filter to get a better error on failure .try_map(|c: C, span| { @@ -483,14 +496,14 @@ pub mod unicode { /// ``` #[track_caller] pub fn keyword< - 'a, - I: ValueInput<'a> + StrInput<'a, C>, - C: Char + 'a, - Str: AsRef + 'a + Clone, - E: ParserExtra<'a, I> + 'a, + 'src, + I: ValueInput<'src> + StrInput<'src, C>, + C: Char + 'src, + Str: AsRef + 'src + Clone, + E: ParserExtra<'src, I> + 'src, >( keyword: Str, - ) -> impl Parser<'a, I, &'a C::Str, E> + Clone + 'a + ) -> impl Parser<'src, I, &'src C::Str, E> + Clone + 'src where C::Str: PartialEq, { @@ -528,25 +541,25 @@ pub mod unicode { mod tests { use crate::prelude::*; - fn make_ascii_kw_parser<'a, C: text::Char, I: crate::StrInput<'a, C>>( - s: &'a C::Str, - ) -> impl Parser<'a, I, ()> + fn make_ascii_kw_parser<'src, C: text::Char, I: crate::StrInput<'src, C>>( + s: &'src C::Str, + ) -> impl Parser<'src, I, ()> where C::Str: PartialEq, { text::ascii::keyword(s).ignored() } - fn make_unicode_kw_parser<'a, C: text::Char, I: crate::StrInput<'a, C>>( - s: &'a C::Str, - ) -> impl Parser<'a, I, ()> + fn make_unicode_kw_parser<'src, C: text::Char, I: crate::StrInput<'src, C>>( + s: &'src C::Str, + ) -> impl Parser<'src, I, ()> where C::Str: PartialEq, { text::unicode::keyword(s).ignored() } - fn test_ok<'a, P: Parser<'a, &'a str, &'a str>>(parser: P, input: &'a str) { + fn test_ok<'src, P: Parser<'src, &'src str, &'src str>>(parser: P, input: &'src str) { assert_eq!( parser.parse(input), ParseResult { @@ -556,7 +569,7 @@ mod tests { ); } - fn test_err<'a, P: Parser<'a, &'a str, &'a str>>(parser: P, input: &'a str) { + fn test_err<'src, P: Parser<'src, &'src str, &'src str>>(parser: P, input: &'src str) { assert_eq!( parser.parse(input), ParseResult {

where - I: Input<'a>, - E: ParserExtra<'a, I>, - P: ExtParser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + P: ExtParser<'src, I, O, E>, { #[inline(always)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); match M::choose(&mut *inp, |inp| self.0.parse(inp), |inp| self.0.check(inp)) { Ok(out) => Ok(out), diff --git a/src/label.rs b/src/label.rs index be2b81bf..f2bf165e 100644 --- a/src/label.rs +++ b/src/label.rs @@ -3,7 +3,7 @@ use super::*; /// A trait implemented by [`Error`]s that can originate from labelled parsers. See [`Parser::labelled`]. -pub trait LabelError<'a, I: Input<'a>, L>: Error<'a, I> { +pub trait LabelError<'src, I: Input<'src>, L>: Error<'src, I> { /// Annotate the expected patterns within this parser with the given label. /// /// In practice, this usually removes all other labels and expected tokens in favor of a single label that @@ -38,16 +38,16 @@ impl Labelled { } } -impl<'a, I, O, E, A, L> Parser<'a, I, O, E> for Labelled +impl<'src, I, O, E, A, L> Parser<'src, I, O, E> for Labelled where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, E>, L: Clone, - E::Error: LabelError<'a, I, L>, + E::Error: LabelError<'src, I, L>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let old_alt = inp.errors.alt.take(); let before = inp.save(); let res = self.parser.go::(inp); diff --git a/src/lib.rs b/src/lib.rs index f6789aa7..02203bcd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,11 +23,11 @@ extern crate core; macro_rules! go_extra { ( $O :ty ) => { #[inline(always)] - fn go_emit(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go_emit(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { Parser::::go::(self, inp) } #[inline(always)] - fn go_check(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go_check(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { Parser::::go::(self, inp) } }; @@ -38,7 +38,7 @@ macro_rules! go_cfg_extra { #[inline(always)] fn go_emit_cfg( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, cfg: Self::Config, ) -> PResult { ConfigParser::::go_cfg::(self, inp, cfg) @@ -46,7 +46,7 @@ macro_rules! go_cfg_extra { #[inline(always)] fn go_check_cfg( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, cfg: Self::Config, ) -> PResult { ConfigParser::::go_cfg::(self, inp, cfg) @@ -182,10 +182,10 @@ mod sync { pub(crate) type RefC = alloc::sync::Arc; pub(crate) type RefW = alloc::sync::Weak; - pub(crate) type DynParser<'a, 'b, I, O, E> = dyn Parser<'a, I, O, E> + Send + Sync + 'b; + pub(crate) type DynParser<'src, 'b, I, O, E> = dyn Parser<'src, I, O, E> + Send + Sync + 'b; #[cfg(feature = "pratt")] - pub(crate) type DynOperator<'a, 'b, I, O, E> = - dyn pratt::Operator<'a, I, O, E> + Send + Sync + 'b; + pub(crate) type DynOperator<'src, 'b, I, O, E> = + dyn pratt::Operator<'src, I, O, E> + Send + Sync + 'b; /// A trait that requires either nothing or `Send` and `Sync` bounds depending on whether the `sync` feature is /// enabled. Used to constrain API usage succinctly and easily. @@ -199,9 +199,9 @@ mod sync { pub(crate) type RefC = alloc::rc::Rc; pub(crate) type RefW = alloc::rc::Weak; - pub(crate) type DynParser<'a, 'b, I, O, E> = dyn Parser<'a, I, O, E> + 'b; + pub(crate) type DynParser<'src, 'b, I, O, E> = dyn Parser<'src, I, O, E> + 'b; #[cfg(feature = "pratt")] - pub(crate) type DynOperator<'a, 'b, I, O, E> = dyn pratt::Operator<'a, I, O, E> + 'b; + pub(crate) type DynOperator<'src, 'b, I, O, E> = dyn pratt::Operator<'src, I, O, E> + 'b; /// A trait that requires either nothing or `Send` and `Sync` bounds depending on whether the `sync` feature is /// enabled. Used to constrain API usage succinctly and easily. @@ -317,6 +317,8 @@ impl ParseResult { /// and returned values or parser state may take advantage of this to borrow tokens or slices of the /// input and hold on to them, if the input supports this. /// +/// # Stability +/// /// This trait is not intended to be implemented by downstream users of `chumsky`. While you can technically implement /// it, doing so is considered to be outside the stability guarantees of the crate. Your code may break with a future, /// semver-compatible release! Instead of implementing this trait, you should consider other options: @@ -337,16 +339,16 @@ impl ParseResult { note = "You should check that the output types of your parsers are consistent with the combinators you're using", ) )] -pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { +pub trait Parser<'src, I: Input<'src>, O, E: ParserExtra<'src, I> = extra::Default> { #[doc(hidden)] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized; #[doc(hidden)] - fn go_emit(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult; + fn go_emit(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult; #[doc(hidden)] - fn go_check(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult; + fn go_check(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult; /// Parse a stream of tokens, yielding an output if possible, and any errors encountered along the way. /// @@ -357,7 +359,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// [`&[T]`], a [`&str`], [`Stream`], or anything implementing [`Input`] to it. fn parse(&self, input: I) -> ParseResult where - I: Input<'a>, + I: Input<'src>, E::State: Default, E::Context: Default, { @@ -374,7 +376,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// [`&[T]`], a [`&str`], [`Stream`], or anything implementing [`Input`] to it. fn parse_with_state(&self, input: I, state: &mut E::State) -> ParseResult where - I: Input<'a>, + I: Input<'src>, E::Context: Default, { let mut own = InputOwn::new_state(input, state); @@ -402,7 +404,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { fn check(&self, input: I) -> ParseResult<(), E::Error> where Self: Sized, - I: Input<'a>, + I: Input<'src>, E::State: Default, E::Context: Default, { @@ -419,7 +421,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { fn check_with_state(&self, input: I, state: &mut E::State) -> ParseResult<(), E::Error> where Self: Sized, - I: Input<'a>, + I: Input<'src>, E::Context: Default, { let mut own = InputOwn::new_state(input, state); @@ -581,7 +583,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// ``` /// # use chumsky::{prelude::*, error::Simple}; /// - /// fn palindrome_parser<'a>() -> impl Parser<'a, &'a str, String> { + /// fn palindrome_parser<'src>() -> impl Parser<'src, &'src str, String> { /// recursive(|chain| { /// choice(( /// just(String::new()) @@ -599,7 +601,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// assert_eq!(palindrome_parser().parse("hello olleh").into_result().as_deref(), Ok(" olleh")); /// assert!(palindrome_parser().parse("abccb").into_result().is_err()); /// ``` - fn map_with) -> U>(self, f: F) -> MapWith + fn map_with) -> U>(self, f: F) -> MapWith where Self: Sized, { @@ -626,7 +628,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// Three(u8, u8, u8), /// } /// - /// fn parser<'a>() -> impl Parser<'a, &'a [u8], Vec> { + /// fn parser<'src>() -> impl Parser<'src, &'src [u8], Vec> { /// choice(( /// just(1).ignore_then(any()).map(Value::One), /// just(2) @@ -677,10 +679,10 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// /// // It's common for AST nodes to use a wrapper type that allows attaching span information to them /// #[derive(Debug, PartialEq)] - /// pub enum Expr<'a> { - /// Int(&'a str, SimpleSpan), + /// pub enum Expr<'src> { + /// Int(&'src str, SimpleSpan), /// // The span is that of the operator, '+' - /// Add(Box>, SimpleSpan, Box>), + /// Add(Box>, SimpleSpan, Box>), /// } /// /// let int = text::int::<_, _, extra::Err>>(10) @@ -753,7 +755,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// [`Parser::validate`] instead. /// /// The output type of this parser is `U`, the [`Ok`] return value of the function. - fn try_map_with) -> Result>( + fn try_map_with) -> Result>( self, f: F, ) -> TryMapWith @@ -858,7 +860,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { fn labelled(self, label: L) -> Labelled where Self: Sized, - E::Error: LabelError<'a, I, L>, + E::Error: LabelError<'src, I, L>, { Labelled { parser: self, @@ -888,7 +890,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// assert_eq!(two_words.parse("dog cat").into_result(), Ok(("dog".to_string(), "cat".to_string()))); /// assert!(two_words.parse("hedgehog").has_errors()); /// ``` - fn then>(self, other: B) -> Then + fn then>(self, other: B) -> Then where Self: Sized, { @@ -922,7 +924,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// assert_eq!(integer.parse("00064").into_result(), Ok(64)); /// assert_eq!(integer.parse("32").into_result(), Ok(32)); /// ``` - fn ignore_then>(self, other: B) -> IgnoreThen + fn ignore_then>(self, other: B) -> IgnoreThen where Self: Sized, { @@ -968,7 +970,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// ]), /// ); /// ``` - fn then_ignore>(self, other: B) -> ThenIgnore + fn then_ignore>(self, other: B) -> ThenIgnore where Self: Sized, { @@ -997,11 +999,11 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// ``` /// # use chumsky::{prelude::*, util::MaybeRef, error::Simple}; /// #[derive(Debug, Clone, PartialEq)] - /// enum Token<'a> { + /// enum Token<'src> { /// Struct, - /// Ident(&'a str), - /// Item(&'a str), - /// Group(Vec>), + /// Ident(&'src str), + /// Item(&'src str), + /// Group(Vec>), /// } /// /// let group = select_ref! { Token::Group(g) => g.as_slice() }; @@ -1032,12 +1034,12 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// /// assert_eq!(tl.parse(&tokens).into_result(), Ok(vec![("foo", vec!["a", "b"])])); /// ``` - fn nested_in, J, F>(self, other: B) -> NestedIn + fn nested_in, J, F>(self, other: B) -> NestedIn where Self: Sized, - I: 'a, - J: Input<'a>, - F: ParserExtra<'a, J>, + I: 'src, + J: Input<'src>, + F: ParserExtra<'src, J>, { NestedIn { parser_a: self, @@ -1075,8 +1077,8 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { ) -> IgnoreWithCtx> where Self: Sized, - O: 'a, - P: Parser<'a, I, U, extra::Full>, + O: 'src, + P: Parser<'src, I, U, extra::Full>, { IgnoreWithCtx { parser: self, @@ -1101,8 +1103,8 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { ) -> ThenWithCtx> where Self: Sized, - O: 'a, - P: Parser<'a, I, U, extra::Full>, + O: 'src, + P: Parser<'src, I, U, extra::Full>, { ThenWithCtx { parser: self, @@ -1130,7 +1132,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { fn with_ctx(self, ctx: Ctx) -> WithCtx where Self: Sized, - Ctx: 'a + Clone, + Ctx: 'src + Clone, { WithCtx { parser: self, ctx } } @@ -1139,7 +1141,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { fn with_state(self, state: State) -> WithState where Self: Sized, - State: 'a + Clone, + State: 'src + Clone, { WithState { parser: self, @@ -1184,7 +1186,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { fn and_is(self, other: B) -> AndIs where Self: Sized, - B: Parser<'a, I, U, E>, + B: Parser<'src, I, U, E>, { AndIs { parser_a: self, @@ -1244,8 +1246,8 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { fn delimited_by(self, start: B, end: C) -> DelimitedBy where Self: Sized, - B: Parser<'a, I, U, E>, - C: Parser<'a, I, V, E>, + B: Parser<'src, I, U, E>, + C: Parser<'src, I, V, E>, { DelimitedBy { parser: self, @@ -1274,7 +1276,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { fn padded_by(self, padding: B) -> PaddedBy where Self: Sized, - B: Parser<'a, I, U, E>, + B: Parser<'src, I, U, E>, { PaddedBy { parser: self, @@ -1316,7 +1318,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { fn or(self, other: B) -> Or where Self: Sized, - B: Parser<'a, I, O, E>, + B: Parser<'src, I, O, E>, { Or { choice: choice((self, other)), @@ -1368,8 +1370,8 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// # use chumsky::{prelude::*, error::Simple}; /// /// #[derive(Debug, PartialEq)] - /// enum Tree<'a> { - /// Text(&'a str), + /// enum Tree<'src> { + /// Text(&'src str), /// Group(Vec), /// } /// @@ -1485,7 +1487,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { fn separated_by(self, separator: B) -> SeparatedBy where Self: Sized, - B: Parser<'a, I, U, E>, + B: Parser<'src, I, U, E>, { SeparatedBy { parser: self, @@ -1525,7 +1527,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { fn foldl(self, other: B, f: F) -> Foldl where F: Fn(O, OB) -> O, - B: IterParser<'a, I, OB, E>, + B: IterParser<'src, I, OB, E>, Self: Sized, { Foldl { @@ -1614,8 +1616,8 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { #[cfg_attr(debug_assertions, track_caller)] fn foldl_with(self, other: B, f: F) -> FoldlWith where - F: Fn(O, OB, &mut MapExtra<'a, '_, I, E>) -> O, - B: IterParser<'a, I, OB, E>, + F: Fn(O, OB, &mut MapExtra<'src, '_, I, E>) -> O, + B: IterParser<'src, I, OB, E>, Self: Sized, { FoldlWith { @@ -1673,10 +1675,10 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// /// assert_eq!(digits.parse("12345abcde").into_result().as_deref(), Ok("12345")); /// ``` - fn lazy(self) -> Lazy<'a, Self, I, E> + fn lazy(self) -> Lazy<'src, Self, I, E> where Self: Sized, - I: ValueInput<'a>, + I: ValueInput<'src>, { self.then_ignore(any().repeated()) } @@ -1699,7 +1701,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { fn padded(self) -> Padded where Self: Sized, - I: Input<'a>, + I: Input<'src>, I::Token: Char, { Padded { parser: self } @@ -1739,10 +1741,10 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// ``` /// # use chumsky::{prelude::*, error::Simple}; /// #[derive(Debug, PartialEq)] - /// enum Expr<'a> { + /// enum Expr<'src> { /// Error, - /// Int(&'a str), - /// List(Vec>), + /// Int(&'src str), + /// List(Vec>), /// } /// /// let recovery = just::<_, _, extra::Err>>('[') @@ -1771,7 +1773,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// // Additionally, the AST we get back still has useful information. /// assert_eq!(res.output(), Some(&Expr::List(vec![Expr::Error, Expr::Error]))); /// ``` - fn recover_with>(self, strategy: S) -> RecoverWith + fn recover_with>(self, strategy: S) -> RecoverWith where Self: Sized, { @@ -1930,7 +1932,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { fn validate(self, f: F) -> Validate where Self: Sized, - F: Fn(O, &mut MapExtra<'a, '_, I, E>, &mut Emitter) -> U, + F: Fn(O, &mut MapExtra<'src, '_, I, E>, &mut Emitter) -> U, { Validate { parser: self, @@ -2064,17 +2066,17 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// # use chumsky::prelude::*; /// /// pub trait Parseable: Sized { - /// type Parser<'a>: Parser<'a, &'a str, Self>; + /// type Parser<'src>: Parser<'src, &'src str, Self>; /// - /// fn parser<'a>() -> Self::Parser<'a>; + /// fn parser<'src>() -> Self::Parser<'src>; /// } /// /// impl Parseable for i32 { /// // We *can* write this type, but it will be very impractical, and change on any alterations /// // to the implementation - /// type Parser<'a> = ???; + /// type Parser<'src> = ???; /// - /// fn parser<'a>() -> Self::Parser<'a> { + /// fn parser<'src>() -> Self::Parser<'src> { /// todo() /// } /// } @@ -2082,7 +2084,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// /// ```compile_fail /// # use chumsky::prelude::*; - /// # fn user_input<'a>() -> impl IntoIterator> { [just('b')] } + /// # fn user_input<'src>() -> impl IntoIterator> { [just('b')] } /// /// let user_input = user_input(); /// @@ -2102,11 +2104,11 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// use chumsky::prelude::*; /// /// pub trait Parseable: Sized { - /// fn parser<'a>() -> Boxed<'a, 'a, &'a str, Self, extra::Default>; + /// fn parser<'src>() -> Boxed<'src, 'src, &'src str, Self, extra::Default>; /// } /// /// impl Parseable for i32 { - /// fn parser<'a>() -> Boxed<'a, 'a, &'a str, Self, extra::Default> { + /// fn parser<'src>() -> Boxed<'src, 'src, &'src str, Self, extra::Default> { /// todo().boxed() /// } /// } @@ -2114,7 +2116,7 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// /// ``` /// # use chumsky::prelude::*; - /// # fn user_input<'a>() -> impl IntoIterator> { [just('b'), just('c')] } + /// # fn user_input<'src>() -> impl IntoIterator> { [just('b'), just('c')] } /// let user_input = user_input(); /// let mut parser = just('a').boxed(); /// for i in user_input { @@ -2125,9 +2127,9 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { /// parser.parse("az").into_result().unwrap(); /// ``` /// - fn boxed<'b>(self) -> Boxed<'a, 'b, I, O, E> + fn boxed<'b>(self) -> Boxed<'src, 'b, I, O, E> where - Self: MaybeSync + Sized + 'a + 'b, + Self: MaybeSync + Sized + 'src + 'b, { Boxed { inner: RefC::new(self), @@ -2179,12 +2181,12 @@ pub trait Parser<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default> { } #[cfg(feature = "nightly")] -impl<'a, I, O, E> Parser<'a, I, O, E> for ! +impl<'src, I, O, E> Parser<'src, I, O, E> for ! where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { - fn go(&self, _inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, _inp: &mut InputRef<'src, '_, I, E>) -> PResult { *self } @@ -2207,25 +2209,33 @@ where /// /// Not all parsers currently support configuration. If you feel like you need a parser to be configurable /// and it isn't currently, please open an issue on the issue tracker of the main repository. -pub trait ConfigParser<'a, I, O, E>: Parser<'a, I, O, E> +pub trait ConfigParser<'src, I, O, E>: Parser<'src, I, O, E> where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { /// A type describing the configurable aspects of the parser. type Config: Default; #[doc(hidden)] - fn go_cfg(&self, inp: &mut InputRef<'a, '_, I, E>, cfg: Self::Config) -> PResult + fn go_cfg( + &self, + inp: &mut InputRef<'src, '_, I, E>, + cfg: Self::Config, + ) -> PResult where Self: Sized; #[doc(hidden)] - fn go_emit_cfg(&self, inp: &mut InputRef<'a, '_, I, E>, cfg: Self::Config) -> PResult; + fn go_emit_cfg( + &self, + inp: &mut InputRef<'src, '_, I, E>, + cfg: Self::Config, + ) -> PResult; #[doc(hidden)] fn go_check_cfg( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, cfg: Self::Config, ) -> PResult; @@ -2275,19 +2285,26 @@ where /// An iterator that wraps an iterable parser. See [`IterParser::parse_iter`]. #[cfg(test)] -pub struct ParserIter<'a, 'iter, P: IterParser<'a, I, O, E>, I: Input<'a>, O, E: ParserExtra<'a, I>> -{ +pub struct ParserIter< + 'src, + 'iter, + P: IterParser<'src, I, O, E>, + I: Input<'src>, + O, + E: ParserExtra<'src, I>, +> { parser: P, - own: InputOwn<'a, 'iter, I, E>, + own: InputOwn<'src, 'iter, I, E>, iter_state: Option>, #[allow(dead_code)] - phantom: EmptyPhantom<(&'a (), O)>, + phantom: EmptyPhantom<(&'src (), O)>, } #[cfg(test)] -impl<'a, P, I: Input<'a>, O, E: ParserExtra<'a, I>> Iterator for ParserIter<'a, '_, P, I, O, E> +impl<'src, P, I: Input<'src>, O, E: ParserExtra<'src, I>> Iterator + for ParserIter<'src, '_, P, I, O, E> where - P: IterParser<'a, I, O, E>, + P: IterParser<'src, I, O, E>, { type Item = O; @@ -2312,15 +2329,15 @@ where } /// An iterable equivalent of [`Parser`], i.e: a parser that generates a sequence of outputs. -pub trait IterParser<'a, I, O, E = extra::Default> +pub trait IterParser<'src, I, O, E = extra::Default> where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { #[doc(hidden)] type IterState where - I: 'a; + I: 'src; // Determines whether this iter parser is expected to not consume input on each iteration #[doc(hidden)] @@ -2329,12 +2346,12 @@ where #[doc(hidden)] fn make_iter( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, ) -> PResult>; #[doc(hidden)] fn next( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, state: &mut Self::IterState, ) -> IPResult; @@ -2476,7 +2493,7 @@ where fn foldr(self, other: B, f: F) -> Foldr where F: Fn(O, OA) -> OA, - B: Parser<'a, I, OA, E>, + B: Parser<'src, I, OA, E>, Self: Sized, { Foldr { @@ -2523,8 +2540,8 @@ where #[cfg_attr(debug_assertions, track_caller)] fn foldr_with(self, other: B, f: F) -> FoldrWith where - F: Fn(O, OA, &mut MapExtra<'a, '_, I, E>) -> OA, - B: Parser<'a, I, OA, E>, + F: Fn(O, OA, &mut MapExtra<'src, '_, I, E>) -> OA, + B: Parser<'src, I, OA, E>, Self: Sized, { FoldrWith { @@ -2555,9 +2572,9 @@ where /// Warning: Trailing errors will be ignored // TODO: Stabilize once error handling is properly decided on #[cfg(test)] - fn parse_iter(self, input: I) -> ParseResult, E::Error> + fn parse_iter(self, input: I) -> ParseResult, E::Error> where - Self: IterParser<'a, I, O, E> + Sized, + Self: IterParser<'src, I, O, E> + Sized, E::State: Default, E::Context: Default, { @@ -2581,9 +2598,9 @@ where self, input: I, state: &'parse mut E::State, - ) -> ParseResult, E::Error> + ) -> ParseResult, E::Error> where - Self: IterParser<'a, I, O, E> + Sized, + Self: IterParser<'src, I, O, E> + Sized, E::Context: Default, { ParseResult::new( @@ -2600,10 +2617,10 @@ where /// An iterable equivalent of [`ConfigParser`], i.e: a parser that generates a sequence of outputs and /// can be configured at runtime. -pub trait ConfigIterParser<'a, I, O, E = extra::Default>: IterParser<'a, I, O, E> +pub trait ConfigIterParser<'src, I, O, E = extra::Default>: IterParser<'src, I, O, E> where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { /// A trait describing the configurable aspects of the iterable parser. type Config: Default; @@ -2611,7 +2628,7 @@ where #[doc(hidden)] fn next_cfg( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, state: &mut Self::IterState, cfg: &Self::Config, ) -> IPResult; @@ -2650,11 +2667,11 @@ where /// efficient cloning. This is likely to change in the future. Unlike [`Box`], [`Rc`](std::rc::Rc) has no size guarantees: although /// it is *currently* the same size as a raw pointer. // TODO: Don't use an Rc -pub struct Boxed<'a, 'b, I: Input<'a>, O, E: ParserExtra<'a, I>> { - inner: RefC>, +pub struct Boxed<'src, 'b, I: Input<'src>, O, E: ParserExtra<'src, I>> { + inner: RefC>, } -impl<'a, I: Input<'a>, O, E: ParserExtra<'a, I>> Clone for Boxed<'a, '_, I, O, E> { +impl<'src, I: Input<'src>, O, E: ParserExtra<'src, I>> Clone for Boxed<'src, '_, I, O, E> { fn clone(&self) -> Self { Self { inner: self.inner.clone(), @@ -2662,19 +2679,19 @@ impl<'a, I: Input<'a>, O, E: ParserExtra<'a, I>> Clone for Boxed<'a, '_, I, O, E } } -impl<'a, I, O, E> Parser<'a, I, O, E> for Boxed<'a, '_, I, O, E> +impl<'src, I, O, E> Parser<'src, I, O, E> for Boxed<'src, '_, I, O, E> where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { M::invoke(&*self.inner, inp) } - fn boxed<'c>(self) -> Boxed<'a, 'c, I, O, E> + fn boxed<'c>(self) -> Boxed<'src, 'c, I, O, E> where - Self: MaybeSync + Sized + 'a + 'c, + Self: MaybeSync + Sized + 'src + 'c, { // Never double-box parsers self @@ -2683,14 +2700,14 @@ where go_extra!(O); } -impl<'a, I, O, E, T> Parser<'a, I, O, E> for ::alloc::boxed::Box +impl<'src, I, O, E, T> Parser<'src, I, O, E> for ::alloc::boxed::Box where - I: Input<'a>, - E: ParserExtra<'a, I>, - T: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + T: Parser<'src, I, O, E>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized, { @@ -2700,14 +2717,14 @@ where go_extra!(O); } -impl<'a, I, O, E, T> Parser<'a, I, O, E> for ::alloc::rc::Rc +impl<'src, I, O, E, T> Parser<'src, I, O, E> for ::alloc::rc::Rc where - I: Input<'a>, - E: ParserExtra<'a, I>, - T: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + T: Parser<'src, I, O, E>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized, { @@ -2717,14 +2734,14 @@ where go_extra!(O); } -impl<'a, I, O, E, T> Parser<'a, I, O, E> for ::alloc::sync::Arc +impl<'src, I, O, E, T> Parser<'src, I, O, E> for ::alloc::sync::Arc where - I: Input<'a>, - E: ParserExtra<'a, I>, - T: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + T: Parser<'src, I, O, E>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult where Self: Sized, { @@ -2755,9 +2772,9 @@ where /// ``` /// # use chumsky::{prelude::*, error::Simple}; /// #[derive(Clone)] -/// enum Token<'a> { Ident(&'a str) } +/// enum Token<'src> { Ident(&'src str) } /// -/// enum Expr<'a> { Local(&'a str), Null, True, False } +/// enum Expr<'src> { Local(&'src str), Null, True, False } /// /// # let _: chumsky::primitive::Select<_, &[Token], Expr, extra::Default> = /// select! { @@ -2775,13 +2792,13 @@ where /// ``` /// # use chumsky::{prelude::*, error::Simple}; /// #[derive(Clone)] -/// enum Token<'a> { Num(f64), Str(&'a str) } +/// enum Token<'src> { Num(f64), Str(&'src str) } /// -/// enum Expr<'a> { Num(f64), Str(&'a str) } +/// enum Expr<'src> { Num(f64), Str(&'src str) } /// /// type Span = SimpleSpan; /// -/// impl<'a> Expr<'a> { +/// impl<'src> Expr<'src> { /// fn spanned(self, span: Span) -> (Self, Span) { (self, span) } /// } /// @@ -2880,15 +2897,16 @@ mod tests { use crate::prelude::*; #[derive(PartialEq, Debug)] - enum Token<'a> { - Ident(&'a str), - String(&'a str), + enum Token<'src> { + Ident(&'src str), + String(&'src str), } type FileId = u32; type Span = SimpleSpan; - fn parser<'a>() -> impl Parser<'a, WithContext, [(Span, Token<'a>); 6]> { + fn parser<'src>( + ) -> impl Parser<'src, WithContext, [(Span, Token<'src>); 6]> { let ident = any() .filter(|c: &char| c.is_alphanumeric()) .repeated() @@ -2931,16 +2949,17 @@ mod tests { use crate::prelude::*; #[derive(PartialEq, Debug)] - enum Token<'a> { - Ident(&'a str), - String(&'a str), + enum Token<'src> { + Ident(&'src str), + String(&'src str), } - type FileId<'a> = &'a str; - type Span<'a> = SimpleSpan>; + type FileId<'src> = &'src str; + type Span<'src> = SimpleSpan>; - fn parser<'a, F: Fn(SimpleSpan) -> Span<'a> + 'a>( - ) -> impl Parser<'a, MappedSpan, &'a str, F>, [(Span<'a>, Token<'a>); 6]> { + fn parser<'src, F: Fn(SimpleSpan) -> Span<'src> + 'src>( + ) -> impl Parser<'src, MappedSpan, &'src str, F>, [(Span<'src>, Token<'src>); 6]> + { let ident = any() .filter(|c: &char| c.is_alphanumeric()) .repeated() @@ -2987,7 +3006,7 @@ mod tests { fn zero_copy_repetition() { use crate::prelude::*; - fn parser<'a>() -> impl Parser<'a, &'a str, Vec> { + fn parser<'src>() -> impl Parser<'src, &'src str, Vec> { any() .filter(|c: &char| c.is_ascii_digit()) .repeated() @@ -3024,7 +3043,7 @@ mod tests { fn zero_copy_group() { use crate::prelude::*; - fn parser<'a>() -> impl Parser<'a, &'a str, (&'a str, u64, char)> { + fn parser<'src>() -> impl Parser<'src, &'src str, (&'src str, u64, char)> { group(( any() .filter(|c: &char| c.is_ascii_alphabetic()) @@ -3065,7 +3084,7 @@ mod tests { fn zero_copy_group_array() { use crate::prelude::*; - fn parser<'a>() -> impl Parser<'a, &'a str, [char; 3]> { + fn parser<'src>() -> impl Parser<'src, &'src str, [char; 3]> { group([just('a'), just('b'), just('c')]) } @@ -3086,7 +3105,7 @@ mod tests { fn iter() { use crate::prelude::*; - fn parser<'a>() -> impl IterParser<'a, &'a str, char> { + fn parser<'src>() -> impl IterParser<'src, &'src str, char> { any().repeated() } @@ -3103,7 +3122,7 @@ mod tests { fn exponential() { use crate::prelude::*; - fn parser<'a>() -> impl Parser<'a, &'a str, String> { + fn parser<'src>() -> impl Parser<'src, &'src str, String> { recursive(|expr| { let atom = any() .filter(|c: &char| c.is_alphabetic()) @@ -3133,7 +3152,7 @@ mod tests { fn left_recursive() { use crate::prelude::*; - fn parser<'a>() -> impl Parser<'a, &'a str, String> { + fn parser<'src>() -> impl Parser<'src, &'src str, String> { recursive(|expr| { let atom = any() .filter(|c: &char| c.is_alphabetic()) @@ -3314,7 +3333,7 @@ mod tests { fn arc_impl() { use alloc::sync::Arc; - fn parser<'a>() -> impl Parser<'a, &'a str, Vec> { + fn parser<'src>() -> impl Parser<'src, &'src str, Vec> { Arc::new( any() .filter(|c: &char| c.is_ascii_digit()) @@ -3347,7 +3366,7 @@ mod tests { #[test] fn box_impl() { - fn parser<'a>() -> impl Parser<'a, &'a str, Vec> { + fn parser<'src>() -> impl Parser<'src, &'src str, Vec> { Box::new( any() .filter(|c: &char| c.is_ascii_digit()) @@ -3382,7 +3401,7 @@ mod tests { fn rc_impl() { use alloc::rc::Rc; - fn parser<'a>() -> impl Parser<'a, &'a str, Vec> { + fn parser<'src>() -> impl Parser<'src, &'src str, Vec> { Rc::new( any() .filter(|c: &char| c.is_ascii_digit()) @@ -3416,13 +3435,13 @@ mod tests { #[derive(Copy, Clone, Debug, PartialEq, Eq)] struct MyErr(&'static str); - impl<'a, I> crate::Error<'a, I> for MyErr + impl<'src, I> crate::Error<'src, I> for MyErr where - I: Input<'a>, + I: Input<'src>, { - fn expected_found>>>( + fn expected_found>>>( _expected: E, - _found: Option>, + _found: Option>, _span: I::Span, ) -> Self { MyErr("expected found") @@ -3440,7 +3459,7 @@ mod tests { #[test] fn err_prio_0() { #[allow(dead_code)] - fn always_err<'a>() -> impl Parser<'a, &'a str, (), extra::Err> { + fn always_err<'src>() -> impl Parser<'src, &'src str, (), extra::Err> { empty().try_map(|_, _| Err(MyErr("special"))) } @@ -3453,7 +3472,7 @@ mod tests { #[test] fn err_prio_1() { #[allow(dead_code)] - fn always_err_choice<'a>() -> impl Parser<'a, &'a str, (), extra::Err> { + fn always_err_choice<'src>() -> impl Parser<'src, &'src str, (), extra::Err> { choice((just("something").ignored(), empty())).try_map(|_, _| Err(MyErr("special"))) } @@ -3465,7 +3484,7 @@ mod tests { #[test] fn into_iter_no_error() { - fn parser<'a>() -> impl Parser<'a, &'a str, (), extra::Err> { + fn parser<'src>() -> impl Parser<'src, &'src str, (), extra::Err> { let many_as = just('a') .ignored() .repeated() @@ -3481,7 +3500,7 @@ mod tests { #[cfg(feature = "nightly")] #[test] fn flatten() { - fn parser<'a>() -> impl Parser<'a, &'a str, Vec, extra::Err> { + fn parser<'src>() -> impl Parser<'src, &'src str, Vec, extra::Err> { let many_as = just('a') .map(Some) .or(any().to(None)) @@ -3501,7 +3520,7 @@ mod tests { #[test] #[cfg(feature = "unstable")] fn cached() { - fn my_parser<'a>() -> impl Parser<'a, &'a str, &'a str, extra::Default> { + fn my_parser<'src>() -> impl Parser<'src, &'src str, &'src str, extra::Default> { any().repeated().exactly(5).to_slice() } diff --git a/src/number.rs b/src/number.rs index 16276276..08c4c030 100644 --- a/src/number.rs +++ b/src/number.rs @@ -26,15 +26,15 @@ pub const fn number() -> Number { } } -impl<'a, const F: u128, I, O, E> Parser<'a, I, O, E> for Number +impl<'src, const F: u128, I, O, E> Parser<'src, I, O, E> for Number where O: FromLexical, - I: SliceInput<'a, Cursor = usize>, - >::Slice: AsRef<[u8]>, - E: ParserExtra<'a, I>, + I: SliceInput<'src, Cursor = usize>, + >::Slice: AsRef<[u8]>, + E: ParserExtra<'src, I>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); match parse_partial(inp.slice_trailing_inner().as_ref()) { Ok((out, skip)) => { diff --git a/src/pratt.rs b/src/pratt.rs index 22c74f06..655b1f03 100644 --- a/src/pratt.rs +++ b/src/pratt.rs @@ -511,7 +511,7 @@ impl Clone for Infix<'_, A, F, Atom, Op, I, /// expression. It must have the following signature: /// /// ```ignore -/// impl Fn(Atom, Op, Atom, &mut MapExtra<'a, '_, I, E>) -> O +/// impl Fn(Atom, Op, Atom, &mut MapExtra<'src, '_, I, E>) -> O /// ``` pub const fn infix<'src, A, F, Atom, Op, I, E>( associativity: Associativity, @@ -607,7 +607,7 @@ impl Clone for Prefix<'_, A, F, Atom, Op, I, /// expression. It must have the following signature: /// /// ```ignore -/// impl Fn(Atom, Op, &mut MapExtra<'a, '_, I, E>) -> O +/// impl Fn(Atom, Op, &mut MapExtra<'src, '_, I, E>) -> O /// ``` pub const fn prefix<'src, A, F, Atom, Op, I, E>( binding_power: u16, @@ -692,7 +692,7 @@ impl Clone for Postfix<'_, A, F, Atom, Op, I /// expression. It must have the following signature: /// /// ```ignore -/// impl Fn(Op, Atom, &mut MapExtra<'a, '_, I, E>) -> O +/// impl Fn(Op, Atom, &mut MapExtra<'src, '_, I, E>) -> O /// ``` pub const fn postfix<'src, A, F, Atom, Op, I, E>( binding_power: u16, @@ -912,18 +912,18 @@ where } #[allow(unused_variables, non_snake_case)] -impl<'a, Atom, Ops> Pratt { +impl<'src, Atom, Ops> Pratt { #[inline] fn pratt_go( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, min_power: u32, ) -> PResult where - I: Input<'a>, - E: ParserExtra<'a, I>, - Atom: Parser<'a, I, O, E>, - Ops: Operator<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + Atom: Parser<'src, I, O, E>, + Ops: Operator<'src, I, O, E>, { let pre_expr = inp.save(); // Prefix unary operators @@ -978,14 +978,14 @@ impl<'a, Atom, Ops> Pratt { } #[allow(unused_variables, non_snake_case)] -impl<'a, I, O, E, Atom, Ops> Parser<'a, I, O, E> for Pratt +impl<'src, I, O, E, Atom, Ops> Parser<'src, I, O, E> for Pratt where - I: Input<'a>, - E: ParserExtra<'a, I>, - Atom: Parser<'a, I, O, E>, - Ops: Operator<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + Atom: Parser<'src, I, O, E>, + Ops: Operator<'src, I, O, E>, { - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { self.pratt_go::(inp, 0) } @@ -1005,7 +1005,7 @@ mod tests { } } - fn parser<'a>() -> impl Parser<'a, &'a str, i64> { + fn parser<'src>() -> impl Parser<'src, &'src str, i64> { let atom = text::int(10).padded().from_str::().unwrapped(); atom.pratt(( @@ -1032,19 +1032,19 @@ mod tests { assert_eq!(parser().parse("-2 + 2").into_result(), Ok(0)); } - // TODO: Make this work - // fn parser_dynamic<'a>() -> impl Parser<'a, &'a str, i64> { - // let atom = text::int(10).padded().from_str::().unwrapped(); + #[allow(dead_code)] + fn parser_dynamic<'src>() -> impl Parser<'src, &'src str, i64> { + let atom = text::int(10).padded().from_str::().unwrapped(); - // atom.pratt(vec![ - // prefix(2, just('-'), |x: i64| -x).into(), - // postfix(2, just('!'), factorial).into(), - // infix(left(0), just('+'), |l, r| l + r).into(), - // infix(left(0), just('-'), |l, r| l - r).into(), - // infix(left(1), just('*'), |l, r| l * r).into(), - // infix(left(1), just('/'), |l, _, r| l / r).into(), - // ]) - // } + atom.pratt(vec![ + prefix(2, just('-'), |_, x: i64, _| -x).boxed(), + postfix(2, just('!'), |x, _, _| factorial(x)).boxed(), + infix(left(0), just('+'), |l, _, r, _| l + r).boxed(), + infix(left(0), just('-'), |l, _, r, _| l - r).boxed(), + infix(left(1), just('*'), |l, _, r, _| l * r).boxed(), + infix(left(1), just('/'), |l, _, r, _| l / r).boxed(), + ]) + } enum Expr { Literal(i64), @@ -1083,7 +1083,7 @@ mod tests { e(Box::new(l), Box::new(r)) } - fn expr_parser<'a>() -> impl Parser<'a, &'a str, String, Err>> { + fn expr_parser<'src>() -> impl Parser<'src, &'src str, String, Err>> { let atom = text::int(10).from_str().unwrapped().map(Expr::Literal); atom.pratt(( @@ -1095,7 +1095,7 @@ mod tests { .map(|x| x.to_string()) } - fn complete_parser<'a>() -> impl Parser<'a, &'a str, String, Err>> { + fn complete_parser<'src>() -> impl Parser<'src, &'src str, String, Err>> { expr_parser().then_ignore(end()) } @@ -1107,10 +1107,10 @@ mod tests { expr_parser().lazy().parse(input) } - fn unexpected<'a, C: Into>>, S: Into>( + fn unexpected<'src, C: Into>>, S: Into>( c: C, span: S, - ) -> Simple<'a, char> { + ) -> Simple<'src, char> { as Error<'_, &'_ str>>::expected_found(None, c.into(), span.into()) } diff --git a/src/primitive.rs b/src/primitive.rs index 7fd0c3bb..9d1a5a90 100644 --- a/src/primitive.rs +++ b/src/primitive.rs @@ -23,7 +23,7 @@ pub struct End(EmptyPhantom<(E, I)>); /// A parser that accepts only the end of input. /// /// The output type of this parser is `()`. -pub const fn end<'a, I: Input<'a>, E: ParserExtra<'a, I>>() -> End { +pub const fn end<'src, I: Input<'src>, E: ParserExtra<'src, I>>() -> End { End(EmptyPhantom::new()) } @@ -34,13 +34,13 @@ impl Clone for End { } } -impl<'a, I, E> Parser<'a, I, (), E> for End +impl<'src, I, E> Parser<'src, I, (), E> for End where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); match inp.next_maybe_inner() { None => Ok(M::bind(|| ())), @@ -72,13 +72,13 @@ impl Clone for Empty { } } -impl<'a, I, E> Parser<'a, I, (), E> for Empty +impl<'src, I, E> Parser<'src, I, (), E> for Empty where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { #[inline] - fn go(&self, _: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, _: &mut InputRef<'src, '_, I, E>) -> PResult { Ok(M::bind(|| ())) } @@ -139,12 +139,12 @@ impl Clone for Just { /// // This fails because the parser expects an end to the input after the '?' /// assert!(question.parse("?!").has_errors()); /// ``` -pub const fn just<'a, T, I, E>(seq: T) -> Just +pub const fn just<'src, T, I, E>(seq: T) -> Just where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, I::Token: PartialEq, - T: OrderedSeq<'a, I::Token> + Clone, + T: OrderedSeq<'src, I::Token> + Clone, { Just { seq, @@ -152,34 +152,34 @@ where } } -impl<'a, I, E, T> Parser<'a, I, T, E> for Just +impl<'src, I, E, T> Parser<'src, I, T, E> for Just where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, I::Token: PartialEq, - T: OrderedSeq<'a, I::Token> + Clone, + T: OrderedSeq<'src, I::Token> + Clone, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { Self::go_cfg::(self, inp, JustCfg::default()) } go_extra!(T); } -impl<'a, I, E, T> ConfigParser<'a, I, T, E> for Just +impl<'src, I, E, T> ConfigParser<'src, I, T, E> for Just where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, I::Token: PartialEq, - T: OrderedSeq<'a, I::Token> + Clone, + T: OrderedSeq<'src, I::Token> + Clone, { type Config = JustCfg; #[inline] fn go_cfg( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, cfg: Self::Config, ) -> PResult { let seq = cfg.seq.as_ref().unwrap_or(&self.seq); @@ -239,12 +239,12 @@ impl Clone for OneOf { /// assert_eq!(digits.parse("48791").into_result(), Ok("48791".to_string())); /// assert!(digits.parse("421!53").has_errors()); /// ``` -pub const fn one_of<'a, T, I, E>(seq: T) -> OneOf +pub const fn one_of<'src, T, I, E>(seq: T) -> OneOf where - I: ValueInput<'a>, - E: ParserExtra<'a, I>, + I: ValueInput<'src>, + E: ParserExtra<'src, I>, I::Token: PartialEq, - T: Seq<'a, I::Token>, + T: Seq<'src, I::Token>, { OneOf { seq, @@ -252,15 +252,15 @@ where } } -impl<'a, I, E, T> Parser<'a, I, I::Token, E> for OneOf +impl<'src, I, E, T> Parser<'src, I, I::Token, E> for OneOf where - I: ValueInput<'a>, - E: ParserExtra<'a, I>, + I: ValueInput<'src>, + E: ParserExtra<'src, I>, I::Token: PartialEq, - T: Seq<'a, I::Token>, + T: Seq<'src, I::Token>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); match inp.next_inner() { #[allow(suspicious_double_ref_op)] // Is this a clippy bug? @@ -313,12 +313,12 @@ impl Clone for NoneOf { /// assert_eq!(string.parse("\"world\"").into_result(), Ok("world".to_string())); /// assert!(string.parse("\"421!53").has_errors()); /// ``` -pub const fn none_of<'a, T, I, E>(seq: T) -> NoneOf +pub const fn none_of<'src, T, I, E>(seq: T) -> NoneOf where - I: ValueInput<'a>, - E: ParserExtra<'a, I>, + I: ValueInput<'src>, + E: ParserExtra<'src, I>, I::Token: PartialEq, - T: Seq<'a, I::Token>, + T: Seq<'src, I::Token>, { NoneOf { seq, @@ -326,15 +326,15 @@ where } } -impl<'a, I, E, T> Parser<'a, I, I::Token, E> for NoneOf +impl<'src, I, E, T> Parser<'src, I, I::Token, E> for NoneOf where - I: ValueInput<'a>, - E: ParserExtra<'a, I>, + I: ValueInput<'src>, + E: ParserExtra<'src, I>, I::Token: PartialEq, - T: Seq<'a, I::Token>, + T: Seq<'src, I::Token>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); match inp.next_inner() { // #[allow(suspicious_double_ref_op)] // Is this a clippy bug? @@ -381,11 +381,11 @@ impl Clone for Custom { /// /// assert_eq!(x.parse("!").into_result(), Ok(())); /// ``` -pub const fn custom<'a, F, I, O, E>(f: F) -> Custom +pub const fn custom<'src, F, I, O, E>(f: F) -> Custom where - I: Input<'a>, - E: ParserExtra<'a, I>, - F: Fn(&mut InputRef<'a, '_, I, E>) -> Result, + I: Input<'src>, + E: ParserExtra<'src, I>, + F: Fn(&mut InputRef<'src, '_, I, E>) -> Result, { Custom { f, @@ -393,14 +393,14 @@ where } } -impl<'a, I, O, E, F> Parser<'a, I, O, E> for Custom +impl<'src, I, O, E, F> Parser<'src, I, O, E> for Custom where - I: Input<'a>, - E: ParserExtra<'a, I>, - F: Fn(&mut InputRef<'a, '_, I, E>) -> Result, + I: Input<'src>, + E: ParserExtra<'src, I>, + F: Fn(&mut InputRef<'src, '_, I, E>) -> Result, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); match (self.f)(inp) { Ok(out) => Ok(M::bind(|| out)), @@ -432,12 +432,12 @@ impl Clone for Select { } /// See [`select!`]. -pub const fn select<'a, F, I, O, E>(filter: F) -> Select +pub const fn select<'src, F, I, O, E>(filter: F) -> Select where - I: Input<'a>, - I::Token: Clone + 'a, - E: ParserExtra<'a, I>, - F: Fn(I::Token, &mut MapExtra<'a, '_, I, E>) -> Option, + I: Input<'src>, + I::Token: Clone + 'src, + E: ParserExtra<'src, I>, + F: Fn(I::Token, &mut MapExtra<'src, '_, I, E>) -> Option, { Select { filter, @@ -445,15 +445,15 @@ where } } -impl<'a, I, O, E, F> Parser<'a, I, O, E> for Select +impl<'src, I, O, E, F> Parser<'src, I, O, E> for Select where - I: ValueInput<'a>, - I::Token: Clone + 'a, - E: ParserExtra<'a, I>, - F: Fn(I::Token, &mut MapExtra<'a, '_, I, E>) -> Option, + I: ValueInput<'src>, + I::Token: Clone + 'src, + E: ParserExtra<'src, I>, + F: Fn(I::Token, &mut MapExtra<'src, '_, I, E>) -> Option, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); let next = inp.next_inner(); let err_span = inp.span_since(&before); @@ -489,12 +489,12 @@ impl Clone for SelectRef { } /// See [`select_ref!`]. -pub const fn select_ref<'a, F, I, O, E>(filter: F) -> SelectRef +pub const fn select_ref<'src, F, I, O, E>(filter: F) -> SelectRef where - I: BorrowInput<'a>, - I::Token: 'a, - E: ParserExtra<'a, I>, - F: Fn(&'a I::Token, &mut MapExtra<'a, '_, I, E>) -> Option, + I: BorrowInput<'src>, + I::Token: 'src, + E: ParserExtra<'src, I>, + F: Fn(&'src I::Token, &mut MapExtra<'src, '_, I, E>) -> Option, { SelectRef { filter, @@ -502,15 +502,15 @@ where } } -impl<'a, I, O, E, F> Parser<'a, I, O, E> for SelectRef +impl<'src, I, O, E, F> Parser<'src, I, O, E> for SelectRef where - I: BorrowInput<'a>, - I::Token: 'a, - E: ParserExtra<'a, I>, - F: Fn(&'a I::Token, &mut MapExtra<'a, '_, I, E>) -> Option, + I: BorrowInput<'src>, + I::Token: 'src, + E: ParserExtra<'src, I>, + F: Fn(&'src I::Token, &mut MapExtra<'src, '_, I, E>) -> Option, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); let next = inp.next_ref_inner(); let found = match next { @@ -541,13 +541,13 @@ impl Clone for Any { } } -impl<'a, I, E> Parser<'a, I, I::Token, E> for Any +impl<'src, I, E> Parser<'src, I, I::Token, E> for Any where - I: ValueInput<'a>, - E: ParserExtra<'a, I>, + I: ValueInput<'src>, + E: ParserExtra<'src, I>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); match inp.next_inner() { Some(tok) => Ok(M::bind(|| tok)), @@ -577,7 +577,7 @@ where /// assert_eq!(any.parse("\t").into_result(), Ok('\t')); /// assert!(any.parse("").has_errors()); /// ``` -pub const fn any<'a, I: Input<'a>, E: ParserExtra<'a, I>>() -> Any { +pub const fn any<'src, I: Input<'src>, E: ParserExtra<'src, I>>() -> Any { Any { phantom: EmptyPhantom::new(), } @@ -596,13 +596,13 @@ impl Clone for AnyRef { } } -impl<'a, I, E> Parser<'a, I, &'a I::Token, E> for AnyRef +impl<'src, I, E> Parser<'src, I, &'src I::Token, E> for AnyRef where - I: BorrowInput<'a>, - E: ParserExtra<'a, I>, + I: BorrowInput<'src>, + E: ParserExtra<'src, I>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.cursor(); match inp.next_ref_inner() { Some(tok) => Ok(M::bind(|| tok)), @@ -614,12 +614,12 @@ where } } - go_extra!(&'a I::Token); + go_extra!(&'src I::Token); } /// A parser that accepts any input (but not the end of input). /// -/// The output type of this parser is `&'a I::Token`, the input that was found. +/// The output type of this parser is `&'src I::Token`, the input that was found. /// /// This function is the borrowing equivalent of [any]. Where possible, it's recommended to use [any] instead. /// @@ -635,7 +635,7 @@ where /// assert_eq!(any_ref_1.parse(&['\t'; 1]).into_result(), Ok(&'\t')); /// assert!(any_ref_0.parse(&[]).has_errors()); /// ``` -pub const fn any_ref<'a, I: BorrowInput<'a>, E: ParserExtra<'a, I>>() -> AnyRef { +pub const fn any_ref<'src, I: BorrowInput<'src>, E: ParserExtra<'src, I>>() -> AnyRef { AnyRef { phantom: EmptyPhantom::new(), } @@ -660,17 +660,17 @@ impl Clone for MapCtx { } } -impl<'a, I, O, E, EI, A, F> Parser<'a, I, O, E> for MapCtx +impl<'src, I, O, E, EI, A, F> Parser<'src, I, O, E> for MapCtx where - I: Input<'a>, - E: ParserExtra<'a, I>, - EI: ParserExtra<'a, I, Error = E::Error, State = E::State>, - A: Parser<'a, I, O, EI>, + I: Input<'src>, + E: ParserExtra<'src, I>, + EI: ParserExtra<'src, I, Error = E::Error, State = E::State>, + A: Parser<'src, I, O, EI>, F: Fn(&E::Context) -> EI::Context, - EI::Context: 'a, + EI::Context: 'src, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { inp.with_ctx(&(self.mapper)(inp.ctx()), |inp| self.parser.go::(inp)) } @@ -713,32 +713,32 @@ where /// ConfigParser, Parser, /// }; /// -/// fn string_ctx<'a>() -> impl Parser<'a, &'a str, (), extra::Context> { +/// fn string_ctx<'src>() -> impl Parser<'src, &'src str, (), extra::Context> { /// just("".to_owned()) /// .configure(|cfg, s: &String| cfg.seq(s.clone())) /// .ignored() /// } /// -/// fn usize_ctx<'a>() -> impl Parser<'a, &'a str, (), extra::Context> { +/// fn usize_ctx<'src>() -> impl Parser<'src, &'src str, (), extra::Context> { /// map_ctx::<_, _, _, extra::Context, extra::Context, _>( /// |num: &usize| num.to_string(), /// string_ctx(), /// ) /// } /// -/// fn specific_usize<'a>(num: usize) -> impl Parser<'a, &'a str, ()> { +/// fn specific_usize<'src>(num: usize) -> impl Parser<'src, &'src str, ()> { /// usize_ctx().with_ctx(num) /// } /// assert!(!specific_usize(10).parse("10").has_errors()); /// ``` -pub const fn map_ctx<'a, P, OP, I, E, EP, F>(mapper: F, parser: P) -> MapCtx +pub const fn map_ctx<'src, P, OP, I, E, EP, F>(mapper: F, parser: P) -> MapCtx where F: Fn(&E::Context) -> EP::Context, - I: Input<'a>, - P: Parser<'a, I, OP, EP>, - E: ParserExtra<'a, I>, - EP: ParserExtra<'a, I>, - EP::Context: 'a, + I: Input<'src>, + P: Parser<'src, I, OP, EP>, + E: ParserExtra<'src, I>, + EP: ParserExtra<'src, I>, + EP::Context: 'src, { MapCtx { parser, @@ -787,20 +787,20 @@ impl Clone for Todo { /// int.parse("0xd4"); /// ``` #[track_caller] -pub fn todo<'a, I: Input<'a>, O, E: ParserExtra<'a, I>>() -> Todo { +pub fn todo<'src, I: Input<'src>, O, E: ParserExtra<'src, I>>() -> Todo { Todo { location: *Location::caller(), phantom: EmptyPhantom::new(), } } -impl<'a, I, O, E> Parser<'a, I, O, E> for Todo +impl<'src, I, O, E> Parser<'src, I, O, E> for Todo where - I: Input<'a>, - E: ParserExtra<'a, I>, + I: Input<'src>, + E: ParserExtra<'src, I>, { #[inline] - fn go(&self, _inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, _inp: &mut InputRef<'src, '_, I, E>) -> PResult { todo!( "Attempted to use an unimplemented parser at {}", self.location @@ -835,13 +835,13 @@ pub struct Choice { /// ``` /// # use chumsky::prelude::*; /// #[derive(Clone, Debug, PartialEq)] -/// enum Token<'a> { +/// enum Token<'src> { /// If, /// For, /// While, /// Fn, /// Int(u64), -/// Ident(&'a str), +/// Ident(&'src str), /// } /// /// let tokens = choice(( @@ -874,15 +874,15 @@ macro_rules! impl_choice_for_tuple { }; (~ $Head:ident $($X:ident)+) => { #[allow(unused_variables, non_snake_case)] - impl<'a, I, E, $Head, $($X),*, O> Parser<'a, I, O, E> for Choice<($Head, $($X,)*)> + impl<'src, I, E, $Head, $($X),*, O> Parser<'src, I, O, E> for Choice<($Head, $($X,)*)> where - I: Input<'a>, - E: ParserExtra<'a, I>, - $Head: Parser<'a, I, O, E>, - $($X: Parser<'a, I, O, E>),* + I: Input<'src>, + E: ParserExtra<'src, I>, + $Head: Parser<'src, I, O, E>, + $($X: Parser<'src, I, O, E>),* { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.save(); let Choice { parsers: ($Head, $($X,)*), .. } = self; @@ -906,14 +906,14 @@ macro_rules! impl_choice_for_tuple { } }; (~ $Head:ident) => { - impl<'a, I, E, $Head, O> Parser<'a, I, O, E> for Choice<($Head,)> + impl<'src, I, E, $Head, O> Parser<'src, I, O, E> for Choice<($Head,)> where - I: Input<'a>, - E: ParserExtra<'a, I>, - $Head: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + $Head: Parser<'src, I, O, E>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { self.parsers.0.go::(inp) } @@ -924,14 +924,14 @@ macro_rules! impl_choice_for_tuple { impl_choice_for_tuple!(A_ B_ C_ D_ E_ F_ G_ H_ I_ J_ K_ L_ M_ N_ O_ P_ Q_ R_ S_ T_ U_ V_ W_ X_ Y_ Z_); -impl<'a, A, I, O, E> Parser<'a, I, O, E> for Choice<&[A]> +impl<'src, A, I, O, E> Parser<'src, I, O, E> for Choice<&[A]> where - A: Parser<'a, I, O, E>, - I: Input<'a>, - E: ParserExtra<'a, I>, + A: Parser<'src, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { if self.parsers.is_empty() { let offs = inp.cursor(); let err_span = inp.span_since(&offs); @@ -952,27 +952,27 @@ where go_extra!(O); } -impl<'a, A, I, O, E> Parser<'a, I, O, E> for Choice> +impl<'src, A, I, O, E> Parser<'src, I, O, E> for Choice> where - A: Parser<'a, I, O, E>, - I: Input<'a>, - E: ParserExtra<'a, I>, + A: Parser<'src, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { choice(&self.parsers[..]).go::(inp) } go_extra!(O); } -impl<'a, A, I, O, E, const N: usize> Parser<'a, I, O, E> for Choice<[A; N]> +impl<'src, A, I, O, E, const N: usize> Parser<'src, I, O, E> for Choice<[A; N]> where - A: Parser<'a, I, O, E>, - I: Input<'a>, - E: ParserExtra<'a, I>, + A: Parser<'src, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { choice(&self.parsers[..]).go::(inp) } go_extra!(O); @@ -992,14 +992,14 @@ pub const fn group(parsers: T) -> Group { Group { parsers } } -impl<'a, I, O, E, P, const N: usize> Parser<'a, I, [O; N], E> for Group<[P; N]> +impl<'src, I, O, E, P, const N: usize> Parser<'src, I, [O; N], E> for Group<[P; N]> where - I: Input<'a>, - E: ParserExtra<'a, I>, - P: Parser<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + P: Parser<'src, I, O, E>, { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let mut arr: [MaybeUninit<_>; N] = MaybeUninitExt::uninit_array(); self.parsers .iter() @@ -1053,14 +1053,14 @@ macro_rules! impl_group_for_tuple { }; (~ $($X:ident $O:ident)*) => { #[allow(unused_variables, non_snake_case)] - impl<'a, I, E, $($X),*, $($O),*> Parser<'a, I, ($($O,)*), E> for Group<($($X,)*)> + impl<'src, I, E, $($X),*, $($O),*> Parser<'src, I, ($($O,)*), E> for Group<($($X,)*)> where - I: Input<'a>, - E: ParserExtra<'a, I>, - $($X: Parser<'a, I, $O, E>),* + I: Input<'src>, + E: ParserExtra<'src, I>, + $($X: Parser<'src, I, $O, E>),* { #[inline] - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let Group { parsers: ($($X,)*) } = self; $( diff --git a/src/recovery.rs b/src/recovery.rs index b683d41e..0b4614d3 100644 --- a/src/recovery.rs +++ b/src/recovery.rs @@ -7,13 +7,15 @@ use super::*; /// This trait is sealed and so cannot be implemented by other crates because it has an unstable API. This may /// eventually change. For now, if you wish to implement a new strategy, consider using [`via_parser`] or /// [opening an issue/PR](https://github.com/zesterer/chumsky/issues/new). -pub trait Strategy<'a, I: Input<'a>, O, E: ParserExtra<'a, I> = extra::Default>: Sealed { +pub trait Strategy<'src, I: Input<'src>, O, E: ParserExtra<'src, I> = extra::Default>: + Sealed +{ // Attempt to recover from a parsing failure. // The strategy should properly handle the alt error but is not required to handle rewinding. #[doc(hidden)] - fn recover>( + fn recover>( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, parser: &P, ) -> PResult; } @@ -28,15 +30,15 @@ pub fn via_parser(parser: A) -> ViaParser { } impl Sealed for ViaParser {} -impl<'a, I, O, E, A> Strategy<'a, I, O, E> for ViaParser +impl<'src, I, O, E, A> Strategy<'src, I, O, E> for ViaParser where - I: Input<'a>, - A: Parser<'a, I, O, E>, - E: ParserExtra<'a, I>, + I: Input<'src>, + A: Parser<'src, I, O, E>, + E: ParserExtra<'src, I>, { - fn recover>( + fn recover>( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, _parser: &P, ) -> PResult { let alt = inp.take_alt(); @@ -59,14 +61,14 @@ pub struct RecoverWith { pub(crate) strategy: S, } -impl<'a, I, O, E, A, S> Parser<'a, I, O, E> for RecoverWith +impl<'src, I, O, E, A, S> Parser<'src, I, O, E> for RecoverWith where - I: Input<'a>, - E: ParserExtra<'a, I>, - A: Parser<'a, I, O, E>, - S: Strategy<'a, I, O, E>, + I: Input<'src>, + E: ParserExtra<'src, I>, + A: Parser<'src, I, O, E>, + S: Strategy<'src, I, O, E>, { - fn go(&self, inp: &mut InputRef<'a, '_, I, E>) -> PResult { + fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let before = inp.save(); match self.parser.go::(inp) { Ok(out) => Ok(out), @@ -96,16 +98,16 @@ pub struct SkipThenRetryUntil { } impl Sealed for SkipThenRetryUntil {} -impl<'a, I, O, E, S, U> Strategy<'a, I, O, E> for SkipThenRetryUntil +impl<'src, I, O, E, S, U> Strategy<'src, I, O, E> for SkipThenRetryUntil where - I: Input<'a>, - S: Parser<'a, I, (), E>, - U: Parser<'a, I, (), E>, - E: ParserExtra<'a, I>, + I: Input<'src>, + S: Parser<'src, I, (), E>, + U: Parser<'src, I, (), E>, + E: ParserExtra<'src, I>, { - fn recover>( + fn recover>( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, parser: &P, ) -> PResult { let alt = inp.take_alt(); @@ -155,17 +157,17 @@ pub struct SkipUntil { } impl Sealed for SkipUntil {} -impl<'a, I, O, E, S, U, F> Strategy<'a, I, O, E> for SkipUntil +impl<'src, I, O, E, S, U, F> Strategy<'src, I, O, E> for SkipUntil where - I: Input<'a>, - S: Parser<'a, I, (), E>, - U: Parser<'a, I, (), E>, + I: Input<'src>, + S: Parser<'src, I, (), E>, + U: Parser<'src, I, (), E>, F: Fn() -> O, - E: ParserExtra<'a, I>, + E: ParserExtra<'src, I>, { - fn recover>( + fn recover>( &self, - inp: &mut InputRef<'a, '_, I, E>, + inp: &mut InputRef<'src, '_, I, E>, _parser: &P, ) -> PResult { let alt = inp.take_alt(); @@ -205,16 +207,16 @@ pub fn skip_until(skip: S, until: U, fallback: F) -> SkipUntil /// /// A function that generates a fallback output on recovery is also required. // TODO: Make this a strategy, add an unclosed_delimiter error -pub fn nested_delimiters<'a, I, O, E, F, const N: usize>( +pub fn nested_delimiters<'src, I, O, E, F, const N: usize>( start: I::Token, end: I::Token, others: [(I::Token, I::Token); N], fallback: F, -) -> impl Parser<'a, I, O, E> + Clone +) -> impl Parser<'src, I, O, E> + Clone where - I: ValueInput<'a>, + I: ValueInput<'src>, I::Token: PartialEq + Clone + MaybeSync, - E: extra::ParserExtra<'a, I> + MaybeSync, + E: extra::ParserExtra<'src, I> + MaybeSync, F: Fn(I::Span) -> O + Clone, { // TODO: Does this actually work? TESTS! diff --git a/src/recursive.rs b/src/recursive.rs index 4e038f71..a12b8795 100644 --- a/src/recursive.rs +++ b/src/recursive.rs @@ -68,12 +68,12 @@ enum RecursiveInner { /// Type for recursive parsers that are defined through a call to `recursive`, and as such /// need no internal indirection -pub type Direct<'a, 'b, I, O, Extra> = DynParser<'a, 'b, I, O, Extra>; +pub type Direct<'src, 'b, I, O, Extra> = DynParser<'src, 'b, I, O, Extra>; /// Type for recursive parsers that are defined through a call to [`Recursive::declare`], and as /// such require an additional layer of allocation. -pub struct Indirect<'a, 'b, I: Input<'a>, O, Extra: ParserExtra<'a, I>> { - inner: OnceCell>>, +pub struct Indirect<'src, 'b, I: Input<'src>, O, Extra: ParserExtra<'src, I>> { + inner: OnceCell>>, } /// A parser that can be defined in terms of itself by separating its [declaration](Recursive::declare) from its @@ -84,7 +84,7 @@ pub struct Recursive { inner: RecursiveInner