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;
use chomp::parsers::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.

sep_by

Applies the parser p multiple times, separated by the parser sep and returns a value populated with the values yielded by p. If the number of items yielded by p does not fall into the range r and the separator or parser registers error or incomplete failure is propagated.

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.