[−][src]Function autumn::parsers::error
pub fn error<'p, T: Clone + 'p, E: Clone + 'p>(
value: T,
error: E
) -> Boxed<dyn Parser<T, E> + 'p>
Creates a parser that consumes no input and produces the given error as the result of parsing
See parsers that produce errors.
This can be used if a particular value will be produced within an
and_then
combinator.
fn alphabet(source: &str, location: Span) -> ParseResult<String, &'static str> { "abcde" .and(digit) .copy_string() .and_then(|text| { if text.ends_with("0") { error(text, "Token must not end with 0") } else { value(text) } }) .parse(source, location) }