glue 0.8.7

Glue is a parser combinator framework for parsing text based formats, it is easy to use and relatively fast too.
Documentation
//! Parser combinators for working with whitespace.

use crate::characters::*;
use crate::combinators::*;
use crate::types::*;
use std::ops::RangeBounds;

#[inline]
/// A shorthand for matching whitespace characters.
///
/// ```
/// # use glue::combinators::whitespace::space;
/// # use glue::prelude::*;
/// assert_eq!(
///     take(1.., is(whitespace)).parse(" foobar"),
///     space(1..).parse(" foobar")
/// );
/// ```
pub fn space<'a, Rng>(range: Rng) -> impl Parser<'a, &'a str>
where
    Rng: RangeBounds<usize> + Clone,
{
    move |ctx| take(range.clone(), is(whitespace)).parse(ctx)
}

#[inline]
/// Trim preceding and following whitespace from a parser.
///
/// ```
/// # use glue::combinators::whitespace::trim;
/// # use glue::prelude::*;
/// assert!(trim(is("foobar")).test(" foobar "));
/// ```
pub fn trim<'a, Par, Res>(mut parser: Par) -> impl Parser<'a, Res>
where
    Par: Parser<'a, Res>,
{
    move |ctx| {
        let ctx = space(0..).parse(ctx).unwrap();

        match parser.parse(ctx)? {
            (ctx, res) => match space(0..).parse(ctx).unwrap() {
                (ctx, _) => Ok(ctx.with_data(res)),
            },
        }
    }
}