Module chomp::combinators::bounded [] [src]

Bounded versions of combinators.

This module provides bounded versions of many, many_till and skip_many.

The core range types are used to describe a half-open range of successive applications of a parser. usize is used to specify an exact number of iterations:

use chomp::combinators::bounded::many;
use chomp::{parse_only, any};

// Read any character 2 or 3 times
let r: Result<Vec<_>, _> = parse_only(|i| many(i, 2..4, any), b"abcd");

assert_eq!(r, Ok(vec![b'a', b'b', b'c']));

Traits

BoundedRange

Trait for applying a parser multiple times based on a range.

Functions

many

Applies the parser F multiple times until it fails or the maximum value of the range has been reached, collecting the successful values into a T: FromIterator.

many_till

Applies the parser P multiple times until the parser F succeeds and returns a value populated by the values yielded by P. Consumes the matched part of F. If F does not succeed within the given range R this combinator will propagate any failure from P.

skip_many

Applies the parser F multiple times until it fails or the maximum value of the range has been reached, throwing away any produced value.