left

Function left 

Source
pub fn left<'a, Toks, T, A, P, Q, B>(p: P, q: Q) -> impl Parser<'a, Toks, T, A>
where Toks: Tokens<T> + 'a, T: Clone + Debug, A: 'a, P: Parser<'a, Toks, T, A> + 'a, Q: Parser<'a, Toks, T, B> + 'a, B: 'a,
Expand description

Parses with two parsers in series, returns the first value.

This parser will first try to parse a value with p. If p succeeds, the parser will try to then parse a value with q (from the returned input from p). If q succeeds, then the value parsed by q is returned. If either p or q fail, then the parser fails.

Both parsers must succeed in the order that they are provided. They must also operate on the same input type, though they are free to have different return types.

When called directly, p will be used first and q second. When called as a method of Parser, the receiving parser (the self) is used first and the other parser is used second.

This combinator may also be expressed with the << operator if both p and q are BoxedParsers.

See also: plus, right, trailing.

ยงExamples

use bad_parsers::{Parser, token};

let p = token('a').left(token('b').convert::<u32>());

assert_eq!(("", 'a'), p.parse("ab").unwrap());
assert!(p.parse("a").is_err());
assert!(p.parse("b").is_err());
assert!(p.parse("ba").is_err());
assert!(p.parse("at").is_err());