1use core::mem::MaybeUninit;
2
3use hybrid_arraydeque::{ArrayDeque, ArraySize, array::Array, typenum};
4
5use crate::{
6 Emitter, Lexer, Source, Token,
7 cache::Peeked,
8 combinator::*,
9 emitter::EmitterView,
10 input::{Complete, Completeness, DelimClass, InputRef, SurfaceIncomplete},
11 located::Located,
12 parse::try_parse::input::ParseAttempt,
13 punct::*,
14 slice::Sliced,
15 span::Spanned,
16 utils::{PhantomLocated, PhantomSliced, PhantomSpan, Trimmed},
17};
18
19#[cfg(feature = "many")]
21use crate::token::PunctuatorToken;
22
23use super::*;
24
25mod sealed {
26 pub trait Sealed {}
27}
28
29pub trait Window: sealed::Sealed {
34 type CAPACITY: ArraySize;
36
37 #[inline(always)]
39 fn array<T>() -> Array<MaybeUninit<T>, Self::CAPACITY> {
40 Array::uninit()
41 }
42
43 #[inline(always)]
45 fn deque<T>() -> ArrayDeque<MaybeUninit<T>, Self::CAPACITY> {
46 ArrayDeque::new()
47 }
48}
49
50macro_rules! peek_buf_capacity_impl_for_typenum {
51 ($($size:literal), + $(,)?) => {
52 paste::paste! {
53 $(
54 impl sealed::Sealed for typenum::[< U $size >] {}
55
56 impl Window for typenum::[< U $size >] {
57 type CAPACITY = typenum::[< U $size >];
58 }
59 )*
60 }
61 };
62}
63
64seq_macro::seq!(N in 1..=32 {
66 peek_buf_capacity_impl_for_typenum! {
67 #(N,)*
68 }
69});
70
71pub trait Decision<'inp, L, E, W, Lang: ?Sized = ()> {
87 fn decide(
89 &mut self,
90 toks: Peeked<'_, 'inp, L, W>,
91 emitter: EmitterView<'_, 'inp, L, E, Lang>,
92 ) -> Result<Action, E::Error>
93 where
94 L: Lexer<'inp>,
95 E: Emitter<'inp, L, Lang>,
96 W: Window;
97}
98
99impl<'inp, F, L, E, W, Lang: ?Sized> Decision<'inp, L, E, W, Lang> for F
100where
101 F: FnMut(Peeked<'_, 'inp, L, W>, EmitterView<'_, 'inp, L, E, Lang>) -> Result<Action, E::Error>,
102 L: Lexer<'inp>,
103 E: Emitter<'inp, L, Lang>,
104 W: Window,
105{
106 #[inline(always)]
107 fn decide(
108 &mut self,
109 toks: Peeked<'_, 'inp, L, W>,
110 emitter: EmitterView<'_, 'inp, L, E, Lang>,
111 ) -> Result<Action, E::Error>
112 where
113 W: Window,
114 {
115 (self)(toks, emitter)
116 }
117}
118
119mod decision_adapters {
130 use super::*;
131
132 pub struct WhileHead<F>(pub(super) F);
134 pub struct WhileKind<K>(pub(super) K);
136
137 impl<F> core::fmt::Debug for WhileHead<F> {
138 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
139 f.debug_struct("WhileHead").finish_non_exhaustive()
140 }
141 }
142
143 impl<K: core::fmt::Debug> core::fmt::Debug for WhileKind<K> {
144 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
145 f.debug_struct("WhileKind").field("kind", &self.0).finish()
146 }
147 }
148
149 impl<'inp, F, L, E, Lang: ?Sized> Decision<'inp, L, E, typenum::U1, Lang> for WhileHead<F>
150 where
151 F: FnMut(&L::Token) -> bool,
152 L: Lexer<'inp>,
153 E: Emitter<'inp, L, Lang>,
154 {
155 #[inline(always)]
156 fn decide(
157 &mut self,
158 mut toks: Peeked<'_, 'inp, L, typenum::U1>,
159 _emitter: EmitterView<'_, 'inp, L, E, Lang>,
160 ) -> Result<Action, E::Error> {
161 use crate::cache::PeekedTokenExt as _;
162 Ok(match toks.pop_front() {
163 Some(t) if (self.0)(t.token()) => Action::Continue,
164 _ => Action::Stop,
165 })
166 }
167 }
168
169 impl<'inp, K, L, E, Lang: ?Sized> Decision<'inp, L, E, typenum::U1, Lang> for WhileKind<K>
170 where
171 K: PartialEq<<L::Token as Token<'inp>>::Kind>,
172 L: Lexer<'inp>,
173 E: Emitter<'inp, L, Lang>,
174 {
175 #[inline(always)]
176 fn decide(
177 &mut self,
178 mut toks: Peeked<'_, 'inp, L, typenum::U1>,
179 _emitter: EmitterView<'_, 'inp, L, E, Lang>,
180 ) -> Result<Action, E::Error> {
181 use crate::cache::PeekedTokenExt as _;
182 Ok(match toks.pop_front() {
183 Some(t) if self.0 == t.token().kind() => Action::Continue,
184 _ => Action::Stop,
185 })
186 }
187 }
188}
189pub use decision_adapters::{WhileHead, WhileKind};
190
191#[inline(always)]
199pub fn while_head<F>(pred: F) -> WhileHead<F> {
200 decision_adapters::WhileHead(pred)
201}
202
203#[inline(always)]
205pub fn while_kind<K>(kind: K) -> WhileKind<K> {
206 decision_adapters::WhileKind(kind)
207}
208
209pub struct Pinned<P, O> {
218 inner: P,
219 _pin: core::marker::PhantomData<fn() -> O>,
224}
225
226impl<P: core::fmt::Debug, O> core::fmt::Debug for Pinned<P, O> {
227 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
228 f.debug_struct("Pinned")
229 .field("inner", &self.inner)
230 .finish()
231 }
232}
233
234#[inline(always)]
263pub fn pinned<O2, P>(parser: P) -> Pinned<P, O2> {
264 Pinned {
265 inner: parser,
266 _pin: core::marker::PhantomData,
267 }
268}
269
270impl<'inp, L, O, Ctx, Lang: ?Sized, Cmpl, P> ParseInput<'inp, L, O, Ctx, Lang, Cmpl>
271 for Pinned<P, O>
272where
273 P: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
274{
275 #[inline(always)]
276 fn parse_input(
277 &mut self,
278 input: &mut InputRef<'inp, '_, L, Ctx, Lang, Cmpl>,
279 ) -> Result<O, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>
280 where
281 L: Lexer<'inp>,
282 Ctx: ParseContext<'inp, L, Lang>,
283 Cmpl: Completeness,
284 {
285 self.inner.parse_input(input)
286 }
287}
288
289impl<'inp, L, O, Ctx, Lang: ?Sized, Cmpl, P> crate::TryParseInput<'inp, L, O, Ctx, Lang, Cmpl>
290 for Pinned<P, O>
291where
292 P: crate::TryParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
293{
294 #[inline(always)]
295 fn try_parse_input(
296 &mut self,
297 input: &mut InputRef<'inp, '_, L, Ctx, Lang, Cmpl>,
298 ) -> Result<ParseAttempt<O>, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>
299 where
300 L: Lexer<'inp>,
301 Ctx: ParseContext<'inp, L, Lang>,
302 Cmpl: Completeness,
303 {
304 self.inner.try_parse_input(input)
305 }
306}
307
308pub trait Accumulator<'inp, L, Container, Ctx, Lang: ?Sized = (), Cmpl = Complete> {
310 #[inline(always)]
312 fn collect(self) -> Collect<Self, Container, Ctx, Lang, Cmpl>
313 where
314 Self: Sized,
315 Container: Default,
316 Collect<Self, Container, Ctx, Lang, Cmpl>: ParseInput<'inp, L, Container, Ctx, Lang, Cmpl>,
317 {
318 Collect::new(self, Container::default())
319 }
320
321 #[inline(always)]
328 fn collect_with(self, container: Container) -> Collect<Self, Container, Ctx, Lang, Cmpl>
329 where
330 Self: Sized,
331 Collect<Self, Container, Ctx, Lang, Cmpl>: ParseInput<'inp, L, Container, Ctx, Lang, Cmpl>,
332 {
333 Collect::new(self, container)
334 }
335}
336
337impl<'inp, P, Container, L, Ctx, Lang: ?Sized, Cmpl>
338 Accumulator<'inp, L, Container, Ctx, Lang, Cmpl> for P
339where
340 Collect<P, Container, Ctx, Lang, Cmpl>: ParseInput<'inp, L, Container, Ctx, Lang, Cmpl>,
341{
342}
343
344macro_rules! define_separated_by {
345 ($($name:ident),+$(,)?) => {
346 paste::paste! {
347 $(
348 #[doc = "Creates a `SeparatedWhile` combinator which separates elements by the `" $name:snake "` separator and applies this parser repeatedly."]
349 #[cfg(feature = "many")]
352 #[cfg_attr(docsrs, doc(cfg(feature = "many")))]
353 #[inline(always)]
354 fn [< separated_by_ $name:snake _while>]<Condition, W>(
355 self,
356 condition: Condition,
357 ) -> SeparatedWhile<Self, $name<(), (), Lang>, Condition, O, W, L, Ctx, Lang, Cmpl>
358 where
359 Self: Sized,
360 L: Lexer<'inp>,
361 L::Token: PunctuatorToken<'inp>,
362 Ctx: ParseContext<'inp, L, Lang>,
363 Condition: Decision<'inp, L, Ctx::Emitter, W, Lang>,
364 W: Window,
365 {
366 SeparatedWhile::new::<$name<(), (), Lang>>(self, condition)
367 }
368 )*
369 }
370 };
371}
372
373macro_rules! define_delimited_by {
374 ($($method:ident => $delimiter:ident),+$(,)?) => {
375 $(
376 #[doc = concat!(
377 "Wraps this parser in a committed `",
378 stringify!($delimiter),
379 "` delimiter pair by delegating to `ParseInput::delimited`."
380 )]
381 #[inline(always)]
382 fn $method(
383 self,
384 ) -> impl for<'c> FnMut(
385 &mut InputRef<'inp, 'c, L, Ctx, Lang, Cmpl>,
386 ) -> crate::combinator::DelimitedOf<'inp, $delimiter<(), (), Lang>, L, Ctx, Lang, O>
387 where
388 Self: Sized,
389 $delimiter<(), (), Lang>: crate::delimiter::TypedDelimiter<'inp, L, Lang>,
390 L: Lexer<'inp>,
391 Ctx: ComposableParseContext<'inp, L, Lang>,
392 Cmpl: SurfaceIncomplete<'inp, L, Ctx, Lang>,
393 {
394 self.delimited::<$delimiter<(), (), Lang>>()
395 }
396 )+
397 };
398}
399
400macro_rules! define_try_delimited_by {
401 ($($method:ident => $delimiter:ident),+$(,)?) => {
402 $(
403 #[doc = concat!(
404 "Wraps this parser in an attempted `",
405 stringify!($delimiter),
406 "` delimiter pair by delegating to `ParseInput::try_delimited`."
407 )]
408 #[inline(always)]
413 fn $method(
414 self,
415 ) -> impl for<'c> FnMut(
416 &mut InputRef<'inp, 'c, L, Ctx, Lang, Cmpl>,
417 ) -> crate::combinator::TryDelimitedOf<'inp, $delimiter<(), (), Lang>, L, Ctx, Lang, O>
418 where
419 Self: Sized,
420 $delimiter<(), (), Lang>: crate::delimiter::TypedDelimiter<'inp, L, Lang>,
421 L: Lexer<'inp>,
422 Ctx: ComposableParseContext<'inp, L, Lang>,
423 Cmpl: SurfaceIncomplete<'inp, L, Ctx, Lang>,
424 {
425 self.try_delimited::<$delimiter<(), (), Lang>>()
426 }
427 )+
428 };
429}
430
431pub trait ParseInput<'inp, L, O, Ctx, Lang: ?Sized = (), Cmpl = Complete> {
445 fn parse_input(
447 &mut self,
448 input: &mut InputRef<'inp, '_, L, Ctx, Lang, Cmpl>,
449 ) -> Result<O, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>
450 where
451 L: Lexer<'inp>,
452 Ctx: ParseContext<'inp, L, Lang>,
453 Cmpl: Completeness;
454
455 #[inline(always)]
460 fn delimited<D>(
461 self,
462 ) -> impl for<'c> FnMut(
463 &mut InputRef<'inp, 'c, L, Ctx, Lang, Cmpl>,
464 ) -> crate::combinator::DelimitedOf<'inp, D, L, Ctx, Lang, O>
465 where
466 Self: Sized,
467 D: crate::delimiter::TypedDelimiter<'inp, L, Lang>,
468 L: Lexer<'inp>,
469 Ctx: ComposableParseContext<'inp, L, Lang>,
470 Cmpl: SurfaceIncomplete<'inp, L, Ctx, Lang>,
471 {
472 crate::combinator::delimited::<D, L, Ctx, Lang, Self, O, Cmpl>(self)
473 }
474
475 define_delimited_by! {
476 delimited_by_parens => Paren,
477 delimited_by_braces => Brace,
478 delimited_by_brackets => Bracket,
479 delimited_by_angles => Angle,
480 }
481
482 #[inline(always)]
499 fn try_delimited<D>(
500 self,
501 ) -> impl for<'c> FnMut(
502 &mut InputRef<'inp, 'c, L, Ctx, Lang, Cmpl>,
503 ) -> crate::combinator::TryDelimitedOf<'inp, D, L, Ctx, Lang, O>
504 where
505 Self: Sized,
506 D: crate::delimiter::TypedDelimiter<'inp, L, Lang>,
507 L: Lexer<'inp>,
508 Ctx: ComposableParseContext<'inp, L, Lang>,
509 Cmpl: SurfaceIncomplete<'inp, L, Ctx, Lang>,
510 {
511 crate::combinator::try_delimited::<D, L, Ctx, Lang, Self, O, Cmpl>(self)
512 }
513
514 define_try_delimited_by! {
515 try_delimited_by_parens => Paren,
516 try_delimited_by_braces => Brace,
517 try_delimited_by_brackets => Bracket,
518 try_delimited_by_angles => Angle,
519 }
520
521 #[inline(always)]
527 fn spanned(self) -> With<PhantomSpan, Self, Cmpl>
528 where
529 Self: Sized,
530 L: Lexer<'inp>,
531 {
532 With::new(PhantomSpan::phantom(), self)
533 }
534
535 #[inline(always)]
540 fn sliced(self) -> With<PhantomSliced, Self, Cmpl>
541 where
542 Self: Sized,
543 L: Lexer<'inp>,
544 {
545 With::new(PhantomSliced::phantom(), self)
546 }
547
548 #[inline(always)]
553 fn located(self) -> With<PhantomLocated, Self, Cmpl>
554 where
555 Self: Sized,
556 L: Lexer<'inp>,
557 {
558 With::new(PhantomLocated::phantom(), self)
559 }
560
561 #[inline(always)]
695 fn spanned_trimmed(self) -> With<Trimmed<PhantomSpan>, Self, Cmpl>
696 where
697 Self: Sized,
698 L: Lexer<'inp>,
699 {
700 With::new(Trimmed(PhantomSpan::phantom()), self)
701 }
702
703 #[inline(always)]
715 fn sliced_trimmed(self) -> With<Trimmed<PhantomSliced>, Self, Cmpl>
716 where
717 Self: Sized,
718 L: Lexer<'inp>,
719 {
720 With::new(Trimmed(PhantomSliced::phantom()), self)
721 }
722
723 #[inline(always)]
735 fn located_trimmed(self) -> With<Trimmed<PhantomLocated>, Self, Cmpl>
736 where
737 Self: Sized,
738 L: Lexer<'inp>,
739 {
740 With::new(Trimmed(PhantomLocated::phantom()), self)
741 }
742
743 #[inline(always)]
745 fn ignored(self) -> Ignore<Self, O, L, Ctx, Lang, Cmpl>
746 where
747 Self: Sized,
748 L: Lexer<'inp>,
749 Ignore<Self, O, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, (), Ctx, Lang, Cmpl>,
750 {
751 Ignore::new(self)
752 }
753
754 #[inline(always)]
756 fn by_ref(&mut self) -> &mut ByRef<Self> {
757 ByRef::from_ref_mut(self)
758 }
759
760 #[cfg(feature = "fold")]
762 #[cfg_attr(docsrs, doc(cfg(feature = "fold")))]
763 #[inline(always)]
764 fn fold_while<Condition, Init, Acc, W>(
765 self,
766 pred: Condition,
767 init: Init,
768 acc: Acc,
769 ) -> FoldWhile<Self, Condition, Init, Acc, O, W, L, Ctx, Lang, Cmpl>
770 where
771 Self: Sized,
772 L: Lexer<'inp>,
773 Ctx: ParseContext<'inp, L, Lang>,
774 Condition: Decision<'inp, L, Ctx::Emitter, W, Lang>,
775 W: Window,
776 FoldWhile<Self, Condition, Init, Acc, O, W, L, Ctx, Lang, Cmpl>:
777 ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
778 {
779 FoldWhile::new(self, pred, init, acc)
780 }
781
782 #[cfg(feature = "fold")]
786 #[cfg_attr(docsrs, doc(cfg(feature = "fold")))]
787 #[inline(always)]
788 fn try_fold_while<Condition, Init, Acc, W>(
789 self,
790 pred: Condition,
791 init: Init,
792 acc: Acc,
793 ) -> TryFoldWhile<Self, Condition, Init, Acc, O, W, L, Ctx, Lang, Cmpl>
794 where
795 Self: Sized,
796 L: Lexer<'inp>,
797 Ctx: ParseContext<'inp, L, Lang>,
798 Init: FnMut() -> O,
799 Acc: FnMut(O, O) -> Result<O, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
800 Condition: Decision<'inp, L, Ctx::Emitter, W, Lang>,
801 W: Window,
802 TryFoldWhile<Self, Condition, Init, Acc, O, W, L, Ctx, Lang, Cmpl>:
803 ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
804 {
805 TryFoldWhile::new(self, pred, init, acc)
806 }
807
808 #[cfg(feature = "fold")]
811 #[cfg_attr(docsrs, doc(cfg(feature = "fold")))]
812 #[inline(always)]
813 fn try_fold_while_with<Condition, Init, Acc, W>(
814 self,
815 pred: Condition,
816 init: Init,
817 acc: Acc,
818 ) -> TryFoldWhileWith<Self, Condition, Init, Acc, O, W, L, Ctx, Lang, Cmpl>
819 where
820 Self: Sized,
821 L: Lexer<'inp>,
822 Ctx: ParseContext<'inp, L, Lang>,
823 Init: FnMut() -> O,
824 Acc: FnMut(
825 O,
826 O,
827 ParseState<'_, 'inp, '_, L, Ctx, Lang, Cmpl>,
828 ) -> Result<O, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
829 Condition: Decision<'inp, L, Ctx::Emitter, W, Lang>,
830 W: Window,
831 TryFoldWhileWith<Self, Condition, Init, Acc, O, W, L, Ctx, Lang, Cmpl>:
832 ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
833 {
834 TryFoldWhileWith::new(self, pred, init, acc)
835 }
836
837 #[cfg(all(feature = "fold", any(feature = "alloc", feature = "std")))]
844 #[cfg_attr(
845 docsrs,
846 doc(cfg(all(feature = "fold", any(feature = "alloc", feature = "std"))))
847 )]
848 #[inline(always)]
849 fn rfold_while<Condition, Init, Acc, W>(
850 self,
851 condition: Condition,
852 init: Init,
853 acc: Acc,
854 ) -> RFoldWhile<Self, Condition, Init, Acc, L, O, W, Ctx, Lang, Cmpl>
855 where
856 Self: Sized,
857 L: Lexer<'inp>,
858 Ctx: ParseContext<'inp, L, Lang>,
859 Init: FnMut() -> O,
860 Acc: FnMut(O, O) -> O,
861 Condition: Decision<'inp, L, Ctx::Emitter, W, Lang>,
862 W: Window,
863 RFoldWhile<Self, Condition, Init, Acc, L, O, W, Ctx, Lang, Cmpl>:
864 ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
865 {
866 RFoldWhile::new(self, condition, init, acc)
867 }
868
869 #[cfg(feature = "many")]
893 #[cfg_attr(docsrs, doc(cfg(feature = "many")))]
894 #[inline(always)]
895 fn repeated_while<Condition, W>(
896 self,
897 condition: Condition,
898 ) -> RepeatedWhile<Self, Condition, O, W, L, Ctx, Lang, Cmpl>
899 where
900 Self: Sized,
901 L: Lexer<'inp>,
902 Ctx: ParseContext<'inp, L, Lang>,
903 Condition: Decision<'inp, L, Ctx::Emitter, W, Lang>,
904 W: Window,
905 {
906 RepeatedWhile::new(self, condition)
907 }
908
909 #[cfg(feature = "many")]
935 #[cfg_attr(docsrs, doc(cfg(feature = "many")))]
936 #[inline(always)]
937 fn separated_while<Sep, Condition, W>(
938 self,
939 condition: Condition,
940 ) -> SeparatedWhile<Self, Sep, Condition, O, W, L, Ctx, Lang, Cmpl>
941 where
942 Self: Sized,
943 L: Lexer<'inp>,
944 Ctx: ParseContext<'inp, L, Lang>,
945 Condition: Decision<'inp, L, Ctx::Emitter, W, Lang>,
946 Sep: Punctuator<'inp, L, Lang>,
947 W: Window,
948 {
949 SeparatedWhile::new::<Sep>(self, condition)
950 }
951
952 define_separated_by!(
953 Comma,
954 Semicolon,
955 Dot,
956 Colon,
957 Pipe,
958 Ampersand,
959 Hyphen,
960 Underscore,
961 DoubleColon,
962 Arrow,
963 FatArrow,
964 Tilde,
965 Slash,
966 Backslash,
967 Percent,
968 Dollar,
969 Hash,
970 At,
971 );
972
973 #[inline(always)]
975 fn labelled(self, name: &'static str) -> crate::combinator::Labelled<Self>
976 where
977 Self: Sized,
978 {
979 crate::combinator::labelled(name, self)
980 }
981
982 #[cfg(feature = "trace")]
984 #[cfg_attr(docsrs, doc(cfg(feature = "trace")))]
985 #[inline(always)]
986 fn traced(self, name: &'static str) -> crate::trace::Traced<Self>
987 where
988 Self: Sized,
989 {
990 crate::trace::traced(name, self)
991 }
992
993 #[cfg(not(feature = "trace"))]
997 #[cfg_attr(docsrs, doc(cfg(not(feature = "trace"))))]
998 #[inline(always)]
999 fn traced(self, _name: &'static str) -> Self
1000 where
1001 Self: Sized,
1002 {
1003 self
1004 }
1005
1006 #[cfg(all(feature = "many", any(feature = "alloc", feature = "std")))]
1021 #[cfg_attr(
1022 docsrs,
1023 doc(cfg(all(feature = "many", any(feature = "alloc", feature = "std"))))
1024 )]
1025 #[inline(always)]
1026 fn list_until<Until>(
1027 self,
1028 until: Until,
1029 ) -> impl for<'c> FnMut(
1030 &mut InputRef<'inp, 'c, L, Ctx, Lang>,
1031 ) -> crate::combinator::ListOf<'inp, L, Ctx, Lang, O>
1032 where
1033 Self: Sized + ParseInput<'inp, L, O, Ctx, Lang>,
1034 L: Lexer<'inp>,
1035 Ctx: ComposableParseContext<'inp, L, Lang>,
1036 Until: FnMut(&L::Token) -> bool,
1037 {
1038 crate::combinator::list(self, until)
1039 }
1040
1041 #[cfg(all(feature = "many", any(feature = "alloc", feature = "std")))]
1051 #[cfg_attr(
1052 docsrs,
1053 doc(cfg(all(feature = "many", any(feature = "alloc", feature = "std"))))
1054 )]
1055 #[inline(always)]
1056 fn separated1_by<Sep, Peek>(
1057 self,
1058 peek: Peek,
1059 ) -> impl for<'c> FnMut(
1060 &mut InputRef<'inp, 'c, L, Ctx, Lang>,
1061 ) -> crate::combinator::Separated1Of<'inp, L, Ctx, Lang, O>
1062 where
1063 Self: Sized + ParseInput<'inp, L, O, Ctx, Lang>,
1064 L: Lexer<'inp>,
1065 Ctx: ComposableParseContext<'inp, L, Lang>,
1066 Sep: Punctuator<'inp, L, Lang>,
1067 Peek: FnMut(&L::Token) -> bool,
1068 {
1069 crate::combinator::separated1::<Sep, L, Ctx, Lang, Self, O, Peek>(self, peek)
1070 }
1071
1072 #[cfg(feature = "peek")]
1077 #[cfg_attr(docsrs, doc(cfg(feature = "peek")))]
1078 fn peek_then<C, W>(self, condition: C) -> PeekThen<Self, C, L::Token, W, Cmpl>
1079 where
1080 Self: Sized,
1081 L: Lexer<'inp>,
1082 Ctx: ParseContext<'inp, L, Lang>,
1083 C: FnMut(
1084 Peeked<'_, 'inp, L, W>,
1085 EmitterView<'_, 'inp, L, Ctx::Emitter, Lang>,
1086 ) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
1087 W: Window,
1088 PeekThen<Self, C, L::Token, W, Cmpl>: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1089 {
1090 PeekThen::of(self, condition)
1091 }
1092
1093 #[cfg(feature = "peek")]
1098 #[cfg_attr(docsrs, doc(cfg(feature = "peek")))]
1099 #[doc(alias = "or_not")]
1100 fn peek_then_try<C, W>(self, condition: C) -> PeekThen<Self, C, L::Token, W, Cmpl>
1101 where
1102 Self: Sized,
1103 L: Lexer<'inp>,
1104 Ctx: ParseContext<'inp, L, Lang>,
1105 C: Decision<'inp, L, Ctx::Emitter, W, Lang>,
1106 W: Window,
1107 PeekThen<Self, C, L::Token, W, Cmpl>: crate::TryParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1108 {
1109 PeekThen::of(self, condition)
1110 }
1111
1112 #[cfg(feature = "peek")]
1118 #[cfg_attr(docsrs, doc(cfg(feature = "peek")))]
1119 #[inline(always)]
1120 fn peek_then_head<C>(
1121 self,
1122 mut condition: C,
1123 ) -> PeekThen<
1124 Self,
1125 impl FnMut(
1126 Peeked<'_, 'inp, L, typenum::U1>,
1127 EmitterView<'_, 'inp, L, Ctx::Emitter, Lang>,
1128 ) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
1129 L::Token,
1130 typenum::U1,
1131 Cmpl,
1132 >
1133 where
1134 Self: Sized,
1135 L: Lexer<'inp>,
1136 Ctx: ParseContext<'inp, L, Lang>,
1137 C: FnMut(
1138 Option<Spanned<&L::Token, &L::Span>>,
1139 ) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
1140 {
1141 PeekThen::of(
1142 self,
1143 move |mut toks: Peeked<'_, 'inp, L, typenum::U1>,
1144 _emitter: EmitterView<'_, 'inp, L, Ctx::Emitter, Lang>| {
1145 use crate::cache::PeekedTokenExt as _;
1146 match toks.pop_front() {
1147 Some(t) => condition(Some(Spanned::new(t.span(), t.token()))),
1148 None => condition(None),
1149 }
1150 },
1151 )
1152 }
1153
1154 #[cfg(feature = "map")]
1156 #[cfg_attr(docsrs, doc(cfg(feature = "map")))]
1157 #[inline(always)]
1158 fn map<U, F>(self, f: F) -> Map<Self, F, L, Ctx, O, U, Lang, Cmpl>
1159 where
1160 Self: Sized,
1161 F: FnMut(O) -> U,
1162 L: Lexer<'inp>,
1163 Map<Self, F, L, Ctx, O, U, Lang, Cmpl>: ParseInput<'inp, L, U, Ctx, Lang, Cmpl>,
1164 {
1165 Map::new(self, f)
1166 }
1167
1168 #[cfg(feature = "map")]
1170 #[cfg_attr(docsrs, doc(cfg(feature = "map")))]
1171 #[inline(always)]
1172 fn map_with<U, F>(self, f: F) -> MapWith<Self, F, L, Ctx, O, U, Lang, Cmpl>
1173 where
1174 Self: Sized,
1175 L: Lexer<'inp>,
1176 F: FnMut(O, ParseState<'_, 'inp, '_, L, Ctx, Lang, Cmpl>) -> U,
1177 MapWith<Self, F, L, Ctx, O, U, Lang, Cmpl>: ParseInput<'inp, L, U, Ctx, Lang, Cmpl>,
1178 {
1179 MapWith::new(self, f)
1180 }
1181
1182 #[cfg(feature = "filter")]
1184 #[cfg_attr(docsrs, doc(cfg(feature = "filter")))]
1185 #[inline(always)]
1186 fn filter<F>(self, validator: F) -> Filter<Self, F, O, L, Ctx, Lang, Cmpl>
1187 where
1188 Self: Sized,
1189 L: Lexer<'inp>,
1190 F: FnMut(&O) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
1191 Ctx: ParseContext<'inp, L, Lang>,
1192 Filter<Self, F, O, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1193 {
1194 Filter::of(self, validator)
1195 }
1196
1197 #[cfg(feature = "filter")]
1199 #[cfg_attr(docsrs, doc(cfg(feature = "filter")))]
1200 #[inline(always)]
1201 fn filter_with<F>(self, validator: F) -> FilterWith<Self, F, O, L, Ctx, Lang, Cmpl>
1202 where
1203 Self: Sized,
1204 L: Lexer<'inp>,
1205 F: FnMut(
1206 &O,
1207 ParseState<'_, 'inp, '_, L, Ctx, Lang, Cmpl>,
1208 ) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
1209 Ctx: ParseContext<'inp, L, Lang>,
1210 FilterWith<Self, F, O, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1211 {
1212 FilterWith::of(self, validator)
1213 }
1214
1215 #[cfg(feature = "filter")]
1220 #[cfg_attr(docsrs, doc(cfg(feature = "filter")))]
1221 #[inline(always)]
1222 fn filter_map<U, F>(self, mapper: F) -> FilterMap<Self, F, O, U, L, Ctx, Lang, Cmpl>
1223 where
1224 Self: Sized,
1225 L: Lexer<'inp>,
1226 F: FnMut(O) -> Result<U, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
1227 Ctx: ParseContext<'inp, L, Lang>,
1228 FilterMap<Self, F, O, U, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, U, Ctx, Lang, Cmpl>,
1229 {
1230 FilterMap::of(self, mapper)
1231 }
1232
1233 #[cfg(feature = "filter")]
1238 #[cfg_attr(docsrs, doc(cfg(feature = "filter")))]
1239 #[inline(always)]
1240 fn filter_map_with<U, F>(self, mapper: F) -> FilterMapWith<Self, F, O, U, L, Ctx, Lang, Cmpl>
1241 where
1242 Self: Sized,
1243 L: Lexer<'inp>,
1244 F: FnMut(
1245 O,
1246 ParseState<'_, 'inp, '_, L, Ctx, Lang, Cmpl>,
1247 ) -> Result<U, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
1248 Ctx: ParseContext<'inp, L, Lang>,
1249 FilterMapWith<Self, F, O, U, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, U, Ctx, Lang, Cmpl>,
1250 {
1251 FilterMapWith::of(self, mapper)
1252 }
1253
1254 #[cfg(feature = "validate")]
1256 #[cfg_attr(docsrs, doc(cfg(feature = "validate")))]
1257 #[inline(always)]
1258 fn validate<F>(self, validator: F) -> Validate<Self, F, O, L, Ctx, Lang, Cmpl>
1259 where
1260 Self: Sized,
1261 L: Lexer<'inp>,
1262 F: FnMut(&O) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
1263 Ctx: ParseContext<'inp, L, Lang>,
1264 {
1265 Validate::of(self, validator)
1266 }
1267
1268 #[cfg(feature = "validate")]
1270 #[cfg_attr(docsrs, doc(cfg(feature = "validate")))]
1271 #[inline(always)]
1272 fn validate_with<F>(self, validator: F) -> ValidateWith<Self, F, O, L, Ctx, Lang, Cmpl>
1273 where
1274 Self: Sized,
1275 L: Lexer<'inp>,
1276 F: FnMut(
1277 &O,
1278 ParseState<'_, 'inp, '_, L, Ctx, Lang, Cmpl>,
1279 ) -> Result<(), <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
1280 Ctx: ParseContext<'inp, L, Lang>,
1281 {
1282 ValidateWith::of(self, validator)
1283 }
1284
1285 #[cfg(feature = "then")]
1287 #[cfg_attr(docsrs, doc(cfg(feature = "then")))]
1288 #[inline(always)]
1289 fn then_ignore<G, U>(self, second: G) -> ThenIgnore<Self, G, O, U, L, Ctx, Lang, Cmpl>
1290 where
1291 Self: Sized,
1292 L: Lexer<'inp>,
1293 G: ParseInput<'inp, L, U, Ctx, Lang, Cmpl>,
1294 Ctx: ParseContext<'inp, L, Lang>,
1295 ThenIgnore<Self, G, O, U, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1296 {
1297 ThenIgnore::new(self, second)
1298 }
1299
1300 #[cfg(feature = "then")]
1302 #[cfg_attr(docsrs, doc(cfg(feature = "then")))]
1303 #[inline(always)]
1304 fn then_value<F, U>(self, value: F) -> ThenValue<Self, F, O, U, L, Ctx, Lang, Cmpl>
1305 where
1306 Self: Sized,
1307 L: Lexer<'inp>,
1308 Ctx: ParseContext<'inp, L, Lang>,
1309 F: FnMut() -> U,
1310 {
1311 ThenValue::new(self, value)
1312 }
1313
1314 #[cfg(feature = "then")]
1316 #[cfg_attr(docsrs, doc(cfg(feature = "then")))]
1317 #[inline(always)]
1318 fn and_then<T, U>(self, then: T) -> AndThen<Self, T, O, U, L, Ctx, Lang, Cmpl>
1319 where
1320 Self: Sized,
1321 T: FnMut(O) -> Result<U, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
1322 L: Lexer<'inp>,
1323 Ctx: ParseContext<'inp, L, Lang>,
1324 AndThen<Self, T, O, U, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, U, Ctx, Lang, Cmpl>,
1325 {
1326 AndThen::new(self, then)
1327 }
1328
1329 #[cfg(feature = "then")]
1331 #[cfg_attr(docsrs, doc(cfg(feature = "then")))]
1332 #[inline(always)]
1333 fn and_then_with<T, U>(self, then: T) -> AndThenWith<Self, T, O, U, L, Ctx, Lang, Cmpl>
1334 where
1335 Self: Sized,
1336 T: FnMut(
1337 O,
1338 ParseState<'_, 'inp, '_, L, Ctx, Lang, Cmpl>,
1339 ) -> Result<U, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
1340 Ctx: ParseContext<'inp, L, Lang>,
1341 L: Lexer<'inp>,
1342 AndThenWith<Self, T, O, U, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, U, Ctx, Lang, Cmpl>,
1343 {
1344 AndThenWith::new(self, then)
1345 }
1346
1347 #[cfg(feature = "then")]
1349 #[cfg_attr(docsrs, doc(cfg(feature = "then")))]
1350 #[inline(always)]
1351 fn then<T, U>(self, then: T) -> Then<Self, T, O, U, L, Ctx, Lang, Cmpl>
1352 where
1353 Self: Sized,
1354 L: Lexer<'inp>,
1355 T: ParseInput<'inp, L, U, Ctx, Lang, Cmpl>,
1356 Ctx: ParseContext<'inp, L, Lang>,
1357 Then<Self, T, O, U, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, (O, U), Ctx, Lang, Cmpl>,
1358 {
1359 Then::new(self, then)
1360 }
1361
1362 #[cfg(feature = "then")]
1364 #[cfg_attr(docsrs, doc(cfg(feature = "then")))]
1365 #[inline(always)]
1366 fn ignore_then<G, U>(self, second: G) -> IgnoreThen<Self, G, O, U, L, Ctx, Lang, Cmpl>
1367 where
1368 Self: Sized,
1369 L: Lexer<'inp>,
1370 G: ParseInput<'inp, L, U, Ctx, Lang, Cmpl>,
1371 IgnoreThen<Self, G, O, U, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, U, Ctx, Lang, Cmpl>,
1372 {
1373 IgnoreThen::new(self, second)
1374 }
1375
1376 #[inline(always)]
1406 fn recover<R>(self, recovery: R) -> Recover<Self, R, O, L, Ctx, Lang, Cmpl>
1407 where
1408 Self: Sized,
1409 L: Lexer<'inp>,
1410 R: RecoverInput<'inp, L, O, Ctx, Lang, Cmpl>,
1411 Ctx: ParseContext<'inp, L, Lang>,
1412 Recover<Self, R, O, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1413 {
1414 Recover::new(self, recovery)
1415 }
1416
1417 #[inline(always)]
1453 fn inplace_recover<R>(self, recovery: R) -> InplaceRecover<Self, R, O, L, Ctx, Lang, Cmpl>
1454 where
1455 Self: Sized,
1456 L: Lexer<'inp>,
1457 R: InplaceRecoverInput<'inp, L, O, Ctx, Lang, Cmpl>,
1458 Ctx: ParseContext<'inp, L, Lang>,
1459 InplaceRecover<Self, R, O, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1460 {
1461 InplaceRecover::new(self, recovery)
1462 }
1463
1464 #[inline(always)]
1496 fn skip_then_retry<D, F>(
1497 self,
1498 classifier: D,
1499 pred: F,
1500 ) -> SkipThenRetry<Self, D, F, O, L, Ctx, Lang, Cmpl>
1501 where
1502 Self: Sized,
1503 L: Lexer<'inp>,
1504 D: DelimClass<<L::Token as Token<'inp>>::Kind>,
1505 F: FnMut(Spanned<&L::Token, &L::Span>) -> bool,
1506 Ctx: ParseContext<'inp, L, Lang>,
1507 SkipThenRetry<Self, D, F, O, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1508 {
1509 SkipThenRetry::new(self, classifier, pred)
1510 }
1511
1512 #[inline(always)]
1514 fn padded(self) -> Padded<Self, O, L, Ctx, Lang, Cmpl>
1515 where
1516 Self: Sized,
1517 L: Lexer<'inp>,
1518 Padded<Self, O, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1519 {
1520 Padded::new(self)
1521 }
1522
1523 #[inline(always)]
1525 fn padded_left(self) -> PaddedLeft<Self, O, L, Ctx, Lang, Cmpl>
1526 where
1527 Self: Sized,
1528 L: Lexer<'inp>,
1529 PaddedLeft<Self, O, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1530 {
1531 PaddedLeft::new(self)
1532 }
1533
1534 #[inline(always)]
1536 fn padded_right(self) -> PaddedRight<Self, O, L, Ctx, Lang, Cmpl>
1537 where
1538 Self: Sized,
1539 L: Lexer<'inp>,
1540 PaddedRight<Self, O, L, Ctx, Lang, Cmpl>: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1541 {
1542 PaddedRight::new(self)
1543 }
1544}
1545
1546impl<'inp, F, L, O, Ctx, Lang: ?Sized, Cmpl> ParseInput<'inp, L, O, Ctx, Lang, Cmpl> for F
1547where
1548 F: FnMut(
1549 &mut InputRef<'inp, '_, L, Ctx, Lang, Cmpl>,
1550 ) -> Result<O, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error>,
1551 L: Lexer<'inp>,
1552 Ctx: ParseContext<'inp, L, Lang>,
1553 Cmpl: Completeness,
1554{
1555 #[inline(always)]
1556 fn parse_input(
1557 &mut self,
1558 input: &mut InputRef<'inp, '_, L, Ctx, Lang, Cmpl>,
1559 ) -> Result<O, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error> {
1560 (self)(input)
1561 }
1562}
1563
1564impl<'inp, F, L, O, Ctx, Lang: ?Sized, Cmpl> ParseInput<'inp, L, O, Ctx, Lang, Cmpl>
1565 for &mut ByRef<F>
1566where
1567 F: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1568 L: Lexer<'inp>,
1569 Ctx: ParseContext<'inp, L, Lang>,
1570 Cmpl: Completeness,
1571{
1572 #[inline(always)]
1573 fn parse_input(
1574 &mut self,
1575 input: &mut InputRef<'inp, '_, L, Ctx, Lang, Cmpl>,
1576 ) -> Result<O, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error> {
1577 (**self).parse_input(input)
1578 }
1579}
1580
1581impl<'inp, L, O, Ctx, P, Lang: ?Sized, Cmpl>
1582 ParseInput<'inp, L, Spanned<O, L::Span>, Ctx, Lang, Cmpl> for With<PhantomSpan, P, Cmpl>
1583where
1584 P: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1585 L: Lexer<'inp>,
1586 Ctx: ParseContext<'inp, L, Lang>,
1587 Cmpl: Completeness,
1588{
1589 #[inline(always)]
1590 fn parse_input(
1591 &mut self,
1592 inp: &mut InputRef<'inp, '_, L, Ctx, Lang, Cmpl>,
1593 ) -> Result<Spanned<O, L::Span>, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error> {
1594 let cursor = inp.cursor().clone();
1595 self
1596 .secondary
1597 .parse_input(inp)
1598 .map(|output| Spanned::new(inp.span_since(&cursor), output))
1599 }
1600}
1601
1602impl<'inp, L, O, Ctx, P, Lang: ?Sized, Cmpl>
1603 ParseInput<'inp, L, Sliced<O, <L::Source as Source<L::Offset>>::Slice<'inp>>, Ctx, Lang, Cmpl>
1604 for With<PhantomSliced, P, Cmpl>
1605where
1606 P: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1607 L: Lexer<'inp>,
1608 Ctx: ParseContext<'inp, L, Lang>,
1609 Cmpl: Completeness,
1610{
1611 #[inline(always)]
1612 fn parse_input(
1613 &mut self,
1614 inp: &mut InputRef<'inp, '_, L, Ctx, Lang, Cmpl>,
1615 ) -> Result<
1616 Sliced<O, <L::Source as Source<L::Offset>>::Slice<'inp>>,
1617 <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error,
1618 > {
1619 let cursor = inp.cursor().clone();
1620 self.secondary.parse_input(inp).map(|output| {
1621 Sliced::new(
1622 inp
1623 .slice_since(&cursor)
1624 .expect("parser should guarantee slice"),
1625 output,
1626 )
1627 })
1628 }
1629}
1630
1631impl<'inp, L, O, Ctx, P, Lang: ?Sized, Cmpl>
1632 ParseInput<
1633 'inp,
1634 L,
1635 Located<O, L::Span, <L::Source as Source<L::Offset>>::Slice<'inp>>,
1636 Ctx,
1637 Lang,
1638 Cmpl,
1639 > for With<PhantomLocated, P, Cmpl>
1640where
1641 P: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1642 L: Lexer<'inp>,
1643 Ctx: ParseContext<'inp, L, Lang>,
1644 Cmpl: Completeness,
1645{
1646 #[inline(always)]
1647 fn parse_input(
1648 &mut self,
1649 inp: &mut InputRef<'inp, '_, L, Ctx, Lang, Cmpl>,
1650 ) -> Result<
1651 Located<O, L::Span, <L::Source as Source<L::Offset>>::Slice<'inp>>,
1652 <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error,
1653 > {
1654 let cursor = inp.cursor().clone();
1655 self.secondary.parse_input(inp).map(|output| {
1656 Located::new(
1657 inp
1658 .slice_since(&cursor)
1659 .expect("parser should guarantee slice"),
1660 inp.span_since(&cursor),
1661 output,
1662 )
1663 })
1664 }
1665}
1666
1667impl<'inp, L, O, Ctx, P, Lang: ?Sized, Cmpl>
1668 ParseInput<'inp, L, Spanned<O, L::Span>, Ctx, Lang, Cmpl> for With<Trimmed<PhantomSpan>, P, Cmpl>
1669where
1670 P: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1671 L: Lexer<'inp>,
1672 Ctx: ParseContext<'inp, L, Lang>,
1673 Cmpl: Completeness,
1674{
1675 #[inline(always)]
1676 fn parse_input(
1677 &mut self,
1678 inp: &mut InputRef<'inp, '_, L, Ctx, Lang, Cmpl>,
1679 ) -> Result<Spanned<O, L::Span>, <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error> {
1680 let start = inp.cursor_trimmed()?;
1681 self
1682 .secondary
1683 .parse_input(inp)
1684 .map(|output| Spanned::new(inp.span_since_trimmed(&start), output))
1685 }
1686}
1687
1688impl<'inp, L, O, Ctx, P, Lang: ?Sized, Cmpl>
1689 ParseInput<'inp, L, Sliced<O, <L::Source as Source<L::Offset>>::Slice<'inp>>, Ctx, Lang, Cmpl>
1690 for With<Trimmed<PhantomSliced>, P, Cmpl>
1691where
1692 P: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1693 L: Lexer<'inp>,
1694 Ctx: ParseContext<'inp, L, Lang>,
1695 Cmpl: Completeness,
1696{
1697 #[inline(always)]
1698 fn parse_input(
1699 &mut self,
1700 inp: &mut InputRef<'inp, '_, L, Ctx, Lang, Cmpl>,
1701 ) -> Result<
1702 Sliced<O, <L::Source as Source<L::Offset>>::Slice<'inp>>,
1703 <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error,
1704 > {
1705 let start = inp.cursor_trimmed()?;
1706 self.secondary.parse_input(inp).map(|output| {
1707 Sliced::new(
1708 inp
1709 .slice_since_trimmed(&start)
1710 .expect("parser should guarantee slice"),
1711 output,
1712 )
1713 })
1714 }
1715}
1716
1717impl<'inp, L, O, Ctx, P, Lang: ?Sized, Cmpl>
1718 ParseInput<
1719 'inp,
1720 L,
1721 Located<O, L::Span, <L::Source as Source<L::Offset>>::Slice<'inp>>,
1722 Ctx,
1723 Lang,
1724 Cmpl,
1725 > for With<Trimmed<PhantomLocated>, P, Cmpl>
1726where
1727 P: ParseInput<'inp, L, O, Ctx, Lang, Cmpl>,
1728 L: Lexer<'inp>,
1729 Ctx: ParseContext<'inp, L, Lang>,
1730 Cmpl: Completeness,
1731{
1732 #[inline(always)]
1733 fn parse_input(
1734 &mut self,
1735 inp: &mut InputRef<'inp, '_, L, Ctx, Lang, Cmpl>,
1736 ) -> Result<
1737 Located<O, L::Span, <L::Source as Source<L::Offset>>::Slice<'inp>>,
1738 <Ctx::Emitter as Emitter<'inp, L, Lang>>::Error,
1739 > {
1740 let start = inp.cursor_trimmed()?;
1741 self.secondary.parse_input(inp).map(|output| {
1742 Located::new(
1743 inp
1744 .slice_since_trimmed(&start)
1745 .expect("parser should guarantee slice"),
1746 inp.span_since_trimmed(&start),
1747 output,
1748 )
1749 })
1750 }
1751}
1752
1753pub trait ParseInputUnwrapExt<'inp, L, O, Ctx, Lang: ?Sized, Cmpl = Complete> {
1755 #[inline(always)]
1757 #[track_caller]
1758 fn unwrap(self) -> Unwrapped<Self, O, Ctx, Lang, Cmpl>
1759 where
1760 Self: Sized + ParseInput<'inp, L, Option<O>, Ctx, Lang, Cmpl>,
1761 {
1762 Unwrapped::new(self)
1763 }
1764}
1765
1766impl<'inp, F, L, O, Ctx, Lang: ?Sized, Cmpl> ParseInputUnwrapExt<'inp, L, O, Ctx, Lang, Cmpl> for F
1767where
1768 F: ParseInput<'inp, L, Option<O>, Ctx, Lang, Cmpl>,
1769 L: Lexer<'inp>,
1770 Ctx: ParseContext<'inp, L, Lang>,
1771{
1772}