2 ms·
Using parser combinator library "nom", this should probably do what you'd want: fn parse_abc(input: &str, n: usize) -> IResult<&str, (Vec<char>, Vec<char>,
by jeroenhd 2y ago
Using parser combinator library "nom", this should probably do what you'd want:
fn parse_abc(input: &str, n: usize) -> IResult<&str, (Vec<char>, Vec<char>, Vec<char>)> {
let (input, result) = tuple(( many_m_n(n, n, char('a')),
many_m_n(n, n, char('b')),
many_m_n(n, n, char('c'))
))(input)?;
Ok((input, result))
}
It parses (the beginning of) the input, ensuring `n` repetitions of 'a', 'b', and 'c'. Parse errors are reported through the return type, and the remaining characters are returned for the application to deal with as it sees fit.
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c641c407591e1eb7ce451f5865250f56 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- oguz-ismail 2y ago> this should probably do what you'd want If you have to specify N, no, it doesn't