Trait combine::Parser
[−]
[src]
pub trait Parser { type Input: Stream; type Output; fn parse(&mut self, input: Self::Input) -> Result<(Self::Output, Self::Input), ParseError<Self::Input>> { ... } fn parse_state(&mut self, input: State<Self::Input>) -> ParseResult<Self::Output, Self::Input> { ... } fn parse_lazy(&mut self, input: State<Self::Input>) -> ParseResult<Self::Output, Self::Input> { ... } fn add_error(&mut self, _error: &mut ParseError<Self::Input>) { ... } }
By implementing the Parser
trait a type says that it can be used to parse an input stream into
the type Output
.
All methods have a default implementation but there needs to be at least an implementation of
parse_state
orparse_lazy
. If parse_lazy
is implemented an implementation of add_error
is
also recommended to improve error reporting.
Associated Types
type Input: Stream
The type which is take as input for the parser. The type must implement the Stream
trait
which allows the parser to read item from the type.
type Output
The type which is returned if the parser is successful.
Provided Methods
fn parse(&mut self, input: Self::Input) -> Result<(Self::Output, Self::Input), ParseError<Self::Input>>
Entrypoint of the parser
Takes some input and tries to parse it returning a ParseResult
fn parse_state(&mut self, input: State<Self::Input>) -> ParseResult<Self::Output, Self::Input>
Parses using the state input
by calling Stream::uncons one or more times
On success returns Ok((value, new_state))
on failure it returns Err(error)
fn parse_lazy(&mut self, input: State<Self::Input>) -> ParseResult<Self::Output, Self::Input>
Specialized version of parse_state where the parser does not need to add an error to the
ParseError
when it does not consume any input before encountering the error.
Instead the error can be added later through the add_error
method
fn add_error(&mut self, _error: &mut ParseError<Self::Input>)
Adds the first error that would normally be returned by this parser if it failed
Implementors
impl<'a, I, O, P: ?Sized> Parser for &'a mut P where I: Stream, P: Parser<Input=I, Output=O>
impl<I, O, P: ?Sized> Parser for Box<P> where I: Stream, P: Parser<Input=I, Output=O>
impl<I> Parser for Any<I> where I: Stream
impl<I, P> Parser for Satisfy<I, P> where I: Stream, P: FnMut(I::Item) -> bool
impl<I> Parser for Token<I> where I: Stream, I::Item: PartialEq
impl<I, O, S, P> Parser for Choice<S, P> where I: Stream, S: AsMut<[P]>, P: Parser<Input=I, Output=O>
impl<I> Parser for Unexpected<I> where I: Stream
impl<I, T> Parser for Value<I, T> where I: Stream, T: Clone
impl<P> Parser for NotFollowedBy<P> where P: Parser
impl<F, P> Parser for Many<F, P> where P: Parser, F: FromIterator<P::Output>
impl<F, P> Parser for Many1<F, P> where F: FromIterator<P::Output>, P: Parser
impl<P> Parser for SkipMany<P> where P: Parser
impl<P> Parser for SkipMany1<P> where P: Parser
impl<F, P, S> Parser for SepBy<F, P, S> where F: FromIterator<P::Output>, P: Parser, S: Parser<Input=P::Input>
impl<F, P, S> Parser for SepBy1<F, P, S> where F: FromIterator<P::Output>, P: Parser, S: Parser<Input=P::Input>
impl<F, P, S> Parser for SepEndBy<F, P, S> where F: FromIterator<P::Output>, P: Parser, S: Parser<Input=P::Input>
impl<F, P, S> Parser for SepEndBy1<F, P, S> where F: FromIterator<P::Output>, P: Parser, S: Parser<Input=P::Input>
impl<'a, I: Stream, O> Parser for FnMut(State<I>) -> ParseResult<O, I> + 'a
impl<I, O, F> Parser for FnParser<I, F> where I: Stream, F: FnMut(State<I>) -> ParseResult<O, I>
impl<I, O> Parser for fn(State<I>) -> ParseResult<O, I> where I: Stream
impl<P> Parser for Optional<P> where P: Parser
impl<L, R, P> Parser for Between<L, R, P> where L: Parser, R: Parser<Input=L::Input>, P: Parser<Input=L::Input>
impl<I, P, Op> Parser for Chainl1<P, Op> where I: Stream, P: Parser<Input=I>, Op: Parser<Input=I>, Op::Output: FnOnce(P::Output, P::Output) -> P::Output
impl<I, P, Op> Parser for Chainr1<P, Op> where I: Stream, P: Parser<Input=I>, Op: Parser<Input=I>, Op::Output: FnOnce(P::Output, P::Output) -> P::Output
impl<I, O, P> Parser for Try<P> where I: Stream, P: Parser<Input=I, Output=O>
impl<I, P1, P2> Parser for And<P1, P2> where I: Stream, P1: Parser<Input=I>, P2: Parser<Input=I>
impl<I, P1, P2> Parser for With<P1, P2> where I: Stream, P1: Parser<Input=I>, P2: Parser<Input=I>
impl<I, P1, P2> Parser for Skip<P1, P2> where I: Stream, P1: Parser<Input=I>, P2: Parser<Input=I>
impl<I, P> Parser for Message<P> where I: Stream, P: Parser<Input=I>
impl<I, O, P1, P2> Parser for Or<P1, P2> where I: Stream, P1: Parser<Input=I, Output=O>, P2: Parser<Input=I, Output=O>
impl<I, A, B, P, F> Parser for Map<P, F> where I: Stream, P: Parser<Input=I, Output=A>, F: FnMut(A) -> B
impl<P, N, F> Parser for Then<P, F> where F: FnMut(P::Output) -> N, P: Parser, N: Parser<Input=P::Input>
impl<P> Parser for Expected<P> where P: Parser
impl<P, F, O, E> Parser for AndThen<P, F> where P: Parser, F: FnMut(P::Output) -> Result<O, E>, E: Into<Error<P::Input::Item, P::Input::Range>>
impl<Input: Stream, A: Parser<Input=Input>, B: Parser<Input=Input>> Parser for (A, B)
impl<Input: Stream, A: Parser<Input=Input>, B: Parser<Input=Input>, C: Parser<Input=Input>> Parser for (A, B, C)
impl<Input: Stream, A: Parser<Input=Input>, B: Parser<Input=Input>, C: Parser<Input=Input>, D: Parser<Input=Input>> Parser for (A, B, C, D)
impl<Input: Stream, A: Parser<Input=Input>, B: Parser<Input=Input>, C: Parser<Input=Input>, D: Parser<Input=Input>, E: Parser<Input=Input>> Parser for (A, B, C, D, E)
impl<Input: Stream, A: Parser<Input=Input>, B: Parser<Input=Input>, C: Parser<Input=Input>, D: Parser<Input=Input>, E: Parser<Input=Input>, F: Parser<Input=Input>> Parser for (A, B, C, D, E, F)
impl<Input: Stream, A: Parser<Input=Input>, B: Parser<Input=Input>, C: Parser<Input=Input>, D: Parser<Input=Input>, E: Parser<Input=Input>, F: Parser<Input=Input>, G: Parser<Input=Input>> Parser for (A, B, C, D, E, F, G)
impl<Input: Stream, A: Parser<Input=Input>, B: Parser<Input=Input>, C: Parser<Input=Input>, D: Parser<Input=Input>, E: Parser<Input=Input>, F: Parser<Input=Input>, G: Parser<Input=Input>, H: Parser<Input=Input>> Parser for (A, B, C, D, E, F, G, H)
impl<Input: Stream, A: Parser<Input=Input>, B: Parser<Input=Input>, C: Parser<Input=Input>, D: Parser<Input=Input>, E: Parser<Input=Input>, F: Parser<Input=Input>, G: Parser<Input=Input>, H: Parser<Input=Input>, I: Parser<Input=Input>> Parser for (A, B, C, D, E, F, G, H, I)
impl<Input: Stream, A: Parser<Input=Input>, B: Parser<Input=Input>, C: Parser<Input=Input>, D: Parser<Input=Input>, E: Parser<Input=Input>, F: Parser<Input=Input>, G: Parser<Input=Input>, H: Parser<Input=Input>, I: Parser<Input=Input>, J: Parser<Input=Input>> Parser for (A, B, C, D, E, F, G, H, I, J)
impl<Input: Stream, A: Parser<Input=Input>, B: Parser<Input=Input>, C: Parser<Input=Input>, D: Parser<Input=Input>, E: Parser<Input=Input>, F: Parser<Input=Input>, G: Parser<Input=Input>, H: Parser<Input=Input>, I: Parser<Input=Input>, J: Parser<Input=Input>, K: Parser<Input=Input>> Parser for (A, B, C, D, E, F, G, H, I, J, K)
impl<Input: Stream, A: Parser<Input=Input>, B: Parser<Input=Input>, C: Parser<Input=Input>, D: Parser<Input=Input>, E: Parser<Input=Input>, F: Parser<Input=Input>, G: Parser<Input=Input>, H: Parser<Input=Input>, I: Parser<Input=Input>, J: Parser<Input=Input>, K: Parser<Input=Input>, L: Parser<Input=Input>> Parser for (A, B, C, D, E, F, G, H, I, J, K, L)
impl<I> Parser for Digit<I> where I: Stream<Item=char>
impl<I> Parser for Space<I> where I: Stream<Item=char>
impl<I> Parser for Spaces<I> where I: Stream<Item=char>
impl<I> Parser for NewLine<I> where I: Stream<Item=char>
impl<I> Parser for CrLf<I> where I: Stream<Item=char>
impl<I> Parser for Tab<I> where I: Stream<Item=char>
impl<I> Parser for Upper<I> where I: Stream<Item=char>
impl<I> Parser for Lower<I> where I: Stream<Item=char>
impl<I> Parser for AlphaNum<I> where I: Stream<Item=char>
impl<I> Parser for Letter<I> where I: Stream<Item=char>
impl<I> Parser for OctDigit<I> where I: Stream<Item=char>
impl<I> Parser for HexDigit<I> where I: Stream<Item=char>
impl<I> Parser for String<I> where I: Stream<Item=char>