Trait parser_combinators::ParserExt
[−]
[src]
pub trait ParserExt: Parser + Sized { fn with<P2>(self, p: P2) -> With<Self, P2> where P2: Parser<Input=Self::Input> { ... } fn skip<P2>(self, p: P2) -> Skip<Self, P2> where P2: Parser<Input=Self::Input> { ... } fn and<P2>(self, p: P2) -> And<Self, P2> where P2: Parser<Input=Self::Input> { ... } fn or<P2>(self, p: P2) -> Or<Self, P2> where P2: Parser<Input=Self::Input> { ... } fn then<N, F>(self, f: F) -> Then<Self, F> where F: FnMut(Self::Output) -> N, N: Parser<Input=Self::Input> { ... } fn map<F, B>(self, f: F) -> Map<Self, F> where F: FnMut(Self::Output) -> B { ... } fn message<S>(self, msg: S) -> Message<Self> where S: Into<Cow<'static, str>> { ... } fn expected<S>(self, msg: S) -> Expected<Self> where S: Into<Cow<'static, str>> { ... } }
Extension trait which provides functions that are more conveniently used through method calls
Provided Methods
fn with<P2>(self, p: P2) -> With<Self, P2> where P2: Parser<Input=Self::Input>
Discards the value of the self
parser and returns the value of p
Fails if any of the parsers fails
fn skip<P2>(self, p: P2) -> Skip<Self, P2> where P2: Parser<Input=Self::Input>
Discards the value of the p
parser and returns the value of self
Fails if any of the parsers fails
fn and<P2>(self, p: P2) -> And<Self, P2> where P2: Parser<Input=Self::Input>
Parses with self
followed by p
Succeds if both parsers succed, otherwise fails
Returns a tuple with both values on success
let result = digit() .and(satisfy(|c| c == 'i')) .parse("9i") .map(|x| x.0); assert_eq!(result, Ok(('9', 'i')));
fn or<P2>(self, p: P2) -> Or<Self, P2> where P2: Parser<Input=Self::Input>
Tries to parse using self
and if it fails returns the result of parsing p
let result = digit().map(|_| "") .or(string("let")) .parse("let") .map(|x| x.0); assert_eq!(result, Ok("let"));
fn then<N, F>(self, f: F) -> Then<Self, F> where F: FnMut(Self::Output) -> N, N: Parser<Input=Self::Input>
Parses using self
and then passes the value to f
which returns the parser used to parse
the rest of the input
fn map<F, B>(self, f: F) -> Map<Self, F> where F: FnMut(Self::Output) -> B
Uses f
to map over the parsed value
fn message<S>(self, msg: S) -> Message<Self> where S: Into<Cow<'static, str>>
Parses with self
and if it fails, adds the message msg
to the error
fn expected<S>(self, msg: S) -> Expected<Self> where S: Into<Cow<'static, str>>
Parses with self
and if it fails without consuming any input any expected errors are replaced by
msg
. msg
is then used in error messages as "Expected msg
".
Implementors
impl<P: Parser> ParserExt for P