use crate::lib::marker::PhantomData; use crate::{ error::{ParseErrorInto, ParseResult, StreamErrorInto}, stream::{ResetStream, StreamErrorFor}, Positioned, RangeStream, RangeStreamOnce, StreamOnce, }; #[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct Span

{ pub start: P, pub end: P, } impl

From

for Span

where P: Clone, { #[inline] fn from(p: P) -> Self { Self { start: p.clone(), end: p, } } } impl

Span

{ pub fn map(self, mut f: impl FnMut(P) -> Q) -> Span { Span { start: f(self.start), end: f(self.end), } } } #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct Stream(pub S, PhantomData E>); impl From for Stream { fn from(stream: S) -> Self { Stream(stream, PhantomData) } } impl ResetStream for Stream where S: ResetStream + Positioned, S::Token: PartialEq, S::Range: PartialEq, E: crate::error::ParseError>, S::Error: ParseErrorInto, >::StreamError: StreamErrorInto, { type Checkpoint = S::Checkpoint; #[inline] fn checkpoint(&self) -> Self::Checkpoint { self.0.checkpoint() } #[inline] fn reset(&mut self, checkpoint: Self::Checkpoint) -> Result<(), Self::Error> { self.0 .reset(checkpoint) .map_err(ParseErrorInto::into_other_error) } } impl StreamOnce for Stream where S: StreamOnce + Positioned, S::Token: PartialEq, S::Range: PartialEq, E: crate::error::ParseError>, S::Error: ParseErrorInto, >::StreamError: StreamErrorInto, { type Token = S::Token; type Range = S::Range; type Position = Span; type Error = E; #[inline] fn uncons(&mut self) -> Result> { self.0.uncons().map_err(StreamErrorInto::into_other_error) } #[inline] fn is_partial(&self) -> bool { self.0.is_partial() } } impl RangeStreamOnce for Stream where S: RangeStream, S::Token: PartialEq, S::Range: PartialEq, E: crate::error::ParseError>, S::Error: ParseErrorInto, >::StreamError: StreamErrorInto, { #[inline] fn uncons_range(&mut self, size: usize) -> Result> { self.0 .uncons_range(size) .map_err(StreamErrorInto::into_other_error) } #[inline] fn uncons_while(&mut self, f: F) -> Result> where F: FnMut(Self::Token) -> bool, { self.0 .uncons_while(f) .map_err(StreamErrorInto::into_other_error) } #[inline] fn uncons_while1(&mut self, f: F) -> ParseResult> where F: FnMut(Self::Token) -> bool, { self.0 .uncons_while1(f) .map_err(StreamErrorInto::into_other_error) } #[inline] fn distance(&self, end: &Self::Checkpoint) -> usize { self.0.distance(end) } fn range(&self) -> Self::Range { self.0.range() } } impl Positioned for Stream where S: StreamOnce + Positioned, S::Token: PartialEq, S::Range: PartialEq, E: crate::error::ParseError>, S::Error: ParseErrorInto, >::StreamError: StreamErrorInto, { fn position(&self) -> Span { Span::from(self.0.position()) } }