pub struct OptionalPreceded<P1, P2> { /* private fields */ }
Expand description
Parser which gets an optional output from a prefix subparser before running the main subparser. Returns the output even if the prefix subparser returns error.
Trait Implementations§
Source§impl<P1: Clone, P2: Clone> Clone for OptionalPreceded<P1, P2>
impl<P1: Clone, P2: Clone> Clone for OptionalPreceded<P1, P2>
Source§fn clone(&self) -> OptionalPreceded<P1, P2>
fn clone(&self) -> OptionalPreceded<P1, P2>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<I, O1, O2, E, P1, P2> Parser<I, (Option<O1>, O2), E> for OptionalPreceded<P1, P2>
impl<I, O1, O2, E, P1, P2> Parser<I, (Option<O1>, O2), E> for OptionalPreceded<P1, P2>
Source§fn parse(&mut self, input: I) -> IResult<I, (Option<O1>, O2), E>
fn parse(&mut self, input: I) -> IResult<I, (Option<O1>, O2), E>
A parser takes in input type, and returns a
Result
containing
either the remaining input and the output value, or an errorSource§fn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O>
fn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O>
Creates a second parser from the output of the first one, then apply over the rest of the input
Source§fn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O>
fn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O>
Applies a second parser over the output of the first one
Source§fn and<G, O2>(self, g: G) -> And<Self, G>
fn and<G, O2>(self, g: G) -> And<Self, G>
Applies a second parser after the first one, return their results as a tuple
impl<P1: Copy, P2: Copy> Copy for OptionalPreceded<P1, P2>
Auto Trait Implementations§
impl<P1, P2> Freeze for OptionalPreceded<P1, P2>
impl<P1, P2> RefUnwindSafe for OptionalPreceded<P1, P2>where
P2: RefUnwindSafe,
P1: RefUnwindSafe,
impl<P1, P2> Send for OptionalPreceded<P1, P2>
impl<P1, P2> Sync for OptionalPreceded<P1, P2>
impl<P1, P2> Unpin for OptionalPreceded<P1, P2>
impl<P1, P2> UnwindSafe for OptionalPreceded<P1, P2>where
P2: UnwindSafe,
P1: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<I, T> ExtractContext<I, ()> for T
impl<I, T> ExtractContext<I, ()> for T
Source§fn extract_context(self, _original_input: I)
fn extract_context(self, _original_input: I)
Given the context attached to a nom error, and given the original
input to the nom parser, extract more the useful context information. Read more
Source§impl<I, O, E, P> ParserExt<I, O, E> for Pwhere
P: Parser<I, O, E>,
impl<I, O, E, P> ParserExt<I, O, E> for Pwhere
P: Parser<I, O, E>,
Source§fn by_ref(&mut self) -> RefParser<'_, Self>
fn by_ref(&mut self) -> RefParser<'_, Self>
Borrow a parser. This allows building parser combinators while still
retaining ownership of the original parser. This is necessary because
impl<T: Parser> Parser for &mut T
is impossible due to conflicts
with impl<T: FnMut> Parser for T
. Read moreSource§fn all_consuming(self) -> AllConsuming<Self>where
I: InputLength,
E: ParseError<I>,
fn all_consuming(self) -> AllConsuming<Self>where
I: InputLength,
E: ParseError<I>,
Create a parser that must consume all of the input, or else return an
error. Read more
Source§fn cut(self) -> Cut<Self>
fn cut(self) -> Cut<Self>
Create a parser that transforms
Error
into Failure
. This will
end the parse immediately, even if there are other branches that
could occur. Read moreSource§fn map_res<F, O2, E2>(self, func: F) -> MapRes<Self, F, O, E2>
fn map_res<F, O2, E2>(self, func: F) -> MapRes<Self, F, O, E2>
Create a parser that applies a mapping function
func
to the output
of the subparser. Any errors from func
will be transformed into
parse errors via FromExternalError
. Read moreSource§fn map_res_cut<F, O2, E2>(self, func: F) -> MapResCut<Self, F, O, E2>
fn map_res_cut<F, O2, E2>(self, func: F) -> MapResCut<Self, F, O, E2>
Create a parser that applies a mapping function
func
to the output
of the subparser. Any errors from func
will be transformed into
parse failures via FromExternalError
. This will
end the parse immediately, even if there are other branches that
could occur. Read moreSource§fn opt(self) -> Optional<Self>where
I: Clone,
fn opt(self) -> Optional<Self>where
I: Clone,
Make this parser optional; if it fails to parse, instead it returns
None
with the input in the original position. Read moreSource§fn recognize(self) -> Recognize<Self, O>
fn recognize(self) -> Recognize<Self, O>
Replace this parser’s output with the entire input that was consumed
by the parser. Read more
Source§fn with_recognized(self) -> WithRecognized<Self>
fn with_recognized(self) -> WithRecognized<Self>
Return the parsed value, but also return the entire input that was
consumed by the parse Read more
Source§fn value<T: Clone>(self, value: T) -> Value<T, Self, O>
fn value<T: Clone>(self, value: T) -> Value<T, Self, O>
Replace this parser’s output with a clone of
value
every time it
finishes successfully. Read moreSource§fn verify<F>(self, verifier: F) -> Verify<Self, F>
fn verify<F>(self, verifier: F) -> Verify<Self, F>
Require the output of this parser to pass a verifier function, or
else return a parse error. Read more
Source§fn context<C>(self, context: C) -> Context<Self, C>
fn context<C>(self, context: C) -> Context<Self, C>
Add some context to the parser. This context will be added to any
errors that are returned from the parser via
ContextError
. Read moreSource§fn terminated<F, O2>(self, terminator: F) -> Terminated<Self, F, O2>where
F: Parser<I, O2, E>,
fn terminated<F, O2>(self, terminator: F) -> Terminated<Self, F, O2>where
F: Parser<I, O2, E>,
Add a terminator parser. The terminator will run after this parser,
returning any errors, but its output will otherwise be discarded. Read more
Source§fn precedes<F, O2>(self, successor: F) -> Preceded<F, Self, O>where
F: Parser<I, O2, E>,
fn precedes<F, O2>(self, successor: F) -> Preceded<F, Self, O>where
F: Parser<I, O2, E>,
Make this parser precede another one. The successor parser will run
after this one succeeds, and the successor’s output will be returned. Read more
Source§fn preceded_by<F, O2>(self, prefix: F) -> Preceded<Self, F, O2>where
F: Parser<I, O2, E>,
fn preceded_by<F, O2>(self, prefix: F) -> Preceded<Self, F, O2>where
F: Parser<I, O2, E>,
Make this parser preceded by another one. The
prefix
will run first,
and if it succeeds, its output will be discard and this parser will
be run. Read moreSource§fn opt_precedes<F, O2>(self, successor: F) -> OptionalPreceded<Self, F>
fn opt_precedes<F, O2>(self, successor: F) -> OptionalPreceded<Self, F>
Make this parser optionally precede by another one.
self
will
run first, and then the successor
will run even if self
returns an
error. Both outputs will be returned. This is functionally equivalent
to self.opt().and(successor)
, but it has the added benefit that if
both parsers return an error, the error from the prefix
will be
retained, rather than discarded. Read moreSource§fn opt_preceded_by<F, O2>(self, prefix: F) -> OptionalPreceded<F, Self>
fn opt_preceded_by<F, O2>(self, prefix: F) -> OptionalPreceded<F, Self>
Make this parser optionally preceded by another one. The
prefix
will
run first, and then this parser will run even if the prefix
returned
an error. Both outputs will be returned. This is functionally equivalent
to prefix.opt().and(self)
, but it has the added benefit that if both
parsers return an error, the error from the prefix
will be retained,
rather than discarded. Read moreSource§fn delimited_by<D, O2>(self, delimiter: D) -> Delimited<Self, D, O2>where
D: Parser<I, O2, E>,
fn delimited_by<D, O2>(self, delimiter: D) -> Delimited<Self, D, O2>where
D: Parser<I, O2, E>,
Make this parser delimited, requiring a
delimiter
as both a prefix and
a suffix. The output of the delimiters is discarded. Read moreSource§fn peek(self) -> Peek<Self>where
I: Clone,
fn peek(self) -> Peek<Self>where
I: Clone,
Make this parser peeking: it runs normally but consumes no input. Read more
Source§fn not(self) -> Not<Self, O>where
I: Clone,
E: ParseError<I>,
fn not(self) -> Not<Self, O>where
I: Clone,
E: ParseError<I>,
Make this parser a negative lookahead: it will succeed if the subparser
fails, and fail if the subparser succeeds. Read more
Source§fn parse_from_str<'a, T>(self) -> FromStrParser<Self, T>
fn parse_from_str<'a, T>(self) -> FromStrParser<Self, T>
Source§fn parse_from_str_cut<'a, T>(self) -> FromStrCutParser<Self, T>
fn parse_from_str_cut<'a, T>(self) -> FromStrCutParser<Self, T>
Create a parser that parses something via
FromStr
, using this
parser as a recognizer for the string to pass to
from_str
. This parser transforms any errors
from FromStr
into Err::Failure
, which will
end the overall parse immediately, even if there are other branches
that could be tried. Read moreSource§fn array(self) -> ArrayParser<Self>
fn array(self) -> ArrayParser<Self>
Create a parser that parses a fixed-size array by running this parser
in a loop. Read more
Source§fn separated_array<F, O2>(
self,
separator: F,
) -> SeparatedArrayParser<Self, F, O2>where
F: Parser<I, O2, E>,
fn separated_array<F, O2>(
self,
separator: F,
) -> SeparatedArrayParser<Self, F, O2>where
F: Parser<I, O2, E>,
Create a parser that parses a fixed-size array by running this parser
in a loop, parsing a separator in between each element. Read more
Source§impl<I> RecreateContext<I> for I
impl<I> RecreateContext<I> for I
Source§fn recreate_context(_original_input: I, tail: I) -> I
fn recreate_context(_original_input: I, tail: I) -> I
Given the original input, as well as the context reported by nom,
recreate a context in the original string where the error occurred. Read more