pub struct Parser<'input, Inside: Parse<'input>>(/* private fields */);Expand description
Wrapper around a parser to work with the orphan rule.
Implementations§
Source§impl<'input, Inside: Parse<'input>> Parser<'input, Inside>
impl<'input, Inside: Parse<'input>> Parser<'input, Inside>
Sourcepub const fn new(inside: Inside) -> Self
pub const fn new(inside: Inside) -> Self
Create a Parser without worrying about workarounds like PhantomData.
Sourcepub fn parse(
&self,
input: &'input [Inside::Input],
) -> Result<Inside::Output, String>
pub fn parse( &self, input: &'input [Inside::Input], ) -> Result<Inside::Output, String>
Parse a list of items (usually characters, in which case this “list of characters” is effectively a string).
§Errors
If parsing fails, if we run out of input, or if we have leftover input afterward.
Sourcepub fn parse_or_panic(&self, slice: &'input [Inside::Input]) -> Inside::Output
pub fn parse_or_panic(&self, slice: &'input [Inside::Input]) -> Inside::Output
Parse a list of items (usually characters, in which case this “list of characters” is effectively a string).
§Panics
If parsing fails, if we run out of input, or if we have leftover input afterward.
Sourcepub const fn discard_left<Right: Parse<'input, Input = Inside::Input>>(
self,
right: Parser<'input, Right>,
) -> Parser<'input, DiscardLeft<'input, Inside, Right>>
pub const fn discard_left<Right: Parse<'input, Input = Inside::Input>>( self, right: Parser<'input, Right>, ) -> Parser<'input, DiscardLeft<'input, Inside, Right>>
Consume this parser and integrate it into a two-part parser that returns only the second result.
Sourcepub const fn discard_right<Right: Parse<'input, Input = Inside::Input>>(
self,
right: Parser<'input, Right>,
) -> Parser<'input, DiscardRight<'input, Inside, Right>>
pub const fn discard_right<Right: Parse<'input, Input = Inside::Input>>( self, right: Parser<'input, Right>, ) -> Parser<'input, DiscardRight<'input, Inside, Right>>
Consume this parser and integrate it into a two-part parser that returns only the first result.
Sourcepub const fn both<Right: Parse<'input, Input = Inside::Input>>(
self,
right: Parser<'input, Right>,
) -> Parser<'input, Both<'input, Inside, Right>>
pub const fn both<Right: Parse<'input, Input = Inside::Input>>( self, right: Parser<'input, Right>, ) -> Parser<'input, Both<'input, Inside, Right>>
Consume this parser and integrate it into a two-part parser that returns both results as a tuple.
Sourcepub const fn either<Right: Parse<'input, Input = Inside::Input, Output = Inside::Output>>(
self,
right: Parser<'input, Right>,
) -> Parser<'input, Either<'input, Inside, Right>>
pub const fn either<Right: Parse<'input, Input = Inside::Input, Output = Inside::Output>>( self, right: Parser<'input, Right>, ) -> Parser<'input, Either<'input, Inside, Right>>
Consume this parser and integrate it into a two-part parser that returns the first one to succeed, or the second error if neither succeed.
Sourcepub const fn pipe<FinalOutput, Right: Fn(Inside::Output) -> Result<FinalOutput, String>>(
self,
right: Right,
) -> Parser<'input, Pipe<'input, Inside, FinalOutput, Right>>
pub const fn pipe<FinalOutput, Right: Fn(Inside::Output) -> Result<FinalOutput, String>>( self, right: Right, ) -> Parser<'input, Pipe<'input, Inside, FinalOutput, Right>>
Consume this parser and integrate it into a two-part parser that pipes parsed output into a normal function and returns its output.