oni_comb_parser_rs::prelude

Function failed

Source
pub fn failed<'a, I, A>(
    value: ParseError<'a, I>,
    commit: CommittedStatus,
) -> Parser<'a, I, A>
where I: Clone + 'a, A: 'a,
Expand description

Returns a Parser that represents the result of the failed parsing.
失敗した解析結果を表すParserを返します。

§Example

use oni_comb_parser_rs::prelude::*;

let text: &str = "x";
let input: Vec<char> = text.chars().collect::<Vec<_>>();

let parse_error: ParseError<char> = ParseError::of_in_complete();

let parser: Parser<char, ()> = failed(parse_error.clone(), CommittedStatus::Committed);

let result: ParseResult<char, ()> = parser.parse(&input);

assert!(result.is_failure());
assert_eq!(result.failure().unwrap(), parse_error);