oni_comb_parser_rs::prelude

Function failed_with_commit

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

Returns a Parser that returns and commits the failed parsing result.
失敗した解析結果を返しコミットする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_with_commit(parse_error.clone());

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

assert!(result.is_failure());
assert_eq!(result.committed_status().unwrap(), CommittedStatus::Committed);

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