pub fn take_while_n_m<'a, I, F>(
n: usize,
m: usize,
f: F,
) -> Parser<'a, I, &'a [I]>
Expand description
クロージャの結果が真である間は要素を返すParserを返す。
Returns a Parser that returns elements, while the result of the closure is true.
解析結果の長さはn要素以上m要素以下である必要があります。
The length of the analysis result should be between n and m elements.
§Example
use std::iter::FromIterator;
use oni_comb_parser_rs::prelude::*;
let text: &str = "abcdef";
let input = text.chars().collect::<Vec<_>>();
let parser: Parser<char, String> = take_while_n_m(1, 3, |e| match *e {
'a'..='c' => true,
_ => false
}).map(String::from_iter);
let result: ParseResult<char, String> = parser.parse(&input);
assert!(result.is_success());
assert_eq!(result.success().unwrap(), "abc");
use std::iter::FromIterator;
use oni_comb_parser_rs::prelude::*;
let text: &str = "def";
let input = text.chars().collect::<Vec<_>>();
let parser: Parser<char, String> = take_while_n_m(1, 3, |e| match *e {
'a'..='c' => true,
_ => false
}).map(String::from_iter);
let result: ParseResult<char, String> = parser.parse(&input);
assert!(result.is_failure());
assert_eq!(result.failure().unwrap(), ParseError::of_in_complete());