pub struct ParserHelper<'a> { /* private fields */ }Expand description
Wraps a slice of input bytes to provide methods for advancing through the input, tracking position, signaling parse errors, looking ahead, etc.
Implementations§
Source§impl<'a> ParserHelper<'a>
impl<'a> ParserHelper<'a>
Sourcepub fn slice<I: SliceIndex<[u8]>>(&self, i: I) -> &'a I::Output
pub fn slice<I: SliceIndex<[u8]>>(&self, i: I) -> &'a I::Output
Obtain a slice into the original input.
Sourcepub fn fail<T, E>(&self, reason: E) -> Result<T, Error<E>>
pub fn fail<T, E>(&self, reason: E) -> Result<T, Error<E>>
Produce an error at the current position.
Sourcepub fn fail_at_position<T, E>(
&self,
reason: E,
position: usize,
) -> Result<T, Error<E>>
pub fn fail_at_position<T, E>( &self, reason: E, position: usize, ) -> Result<T, Error<E>>
Produce an error at the given position.
Sourcepub fn unexpected_end_of_input<T, E: Eoi>(&self) -> Result<T, Error<E>>
pub fn unexpected_end_of_input<T, E: Eoi>(&self) -> Result<T, Error<E>>
Produce an error indicating the unexpected end of the input at the current position.
Sourcepub fn advance_over(&mut self, expected: &[u8]) -> bool
pub fn advance_over(&mut self, expected: &[u8]) -> bool
Advance the input but only if it matches the given bytes, returns whether it did advance.
Sourcepub fn advance_or<E>(&mut self, offset: usize, e: E) -> Result<(), Error<E>>
pub fn advance_or<E>(&mut self, offset: usize, e: E) -> Result<(), Error<E>>
Advance the input slice by some number of bytes, returning the given error if not enough input is available.
Sourcepub fn next<E: Eoi>(&mut self) -> Result<u8, Error<E>>
pub fn next<E: Eoi>(&mut self) -> Result<u8, Error<E>>
Consumes the next byte and returns it. Signals unexpected end of the input if no next byte is available.
Sourcepub fn next_or_end(&mut self) -> Option<u8>
pub fn next_or_end(&mut self) -> Option<u8>
Consumes the next byte and returns it, or signals end of input as None.
Sourcepub fn expect<E: Eoi>(&mut self, expected: u8, err: E) -> Result<(), Error<E>>
pub fn expect<E: Eoi>(&mut self, expected: u8, err: E) -> Result<(), Error<E>>
Consumes the expected byte, gives the given error if it is something else.
Sourcepub fn expect_bytes<E>(&mut self, exp: &[u8], err: E) -> Result<(), Error<E>>
pub fn expect_bytes<E>(&mut self, exp: &[u8], err: E) -> Result<(), Error<E>>
Same as expect, but for multiple consecutive bytes.
Sourcepub fn expect_pred<E: Eoi>(
&mut self,
pred: fn(u8) -> bool,
err: E,
) -> Result<(), Error<E>>
pub fn expect_pred<E: Eoi>( &mut self, pred: fn(u8) -> bool, err: E, ) -> Result<(), Error<E>>
Same as expect, but using a predicate.
Sourcepub fn peek<E: Eoi>(&self) -> Result<u8, Error<E>>
pub fn peek<E: Eoi>(&self) -> Result<u8, Error<E>>
Returns the next byte without consuming it. Signals unexpected end of the input if no next byte is available.
Sourcepub fn peek_or_end(&self) -> Option<u8>
pub fn peek_or_end(&self) -> Option<u8>
Returns the next byte without consuming it, or signals end of input as None.