[][src]Crate glue

Glue is a parser combinator framework that is designed for parsing text based formats, it is easy to use and relatively efficient.

Usage

Use the test method to see if your input matches a parser:

use glue::prelude::*;

if take(1.., is(alphabetic)).test("foobar") {
    println!("One or more alphabetic characters found!");
}

Use the parse method to extract information from your input:

assert_eq!(take(1.., is(alphabetic)).parse("foobar"), Ok((
    ParserContext {
        input: "foobar",
        bounds: 0..6,
    },
    "foobar"
)))

Write your own parser functions:

#[derive(Debug, PartialEq)]
enum Token<'a> {
    Identifier(&'a str),
}

fn identifier<'a>() -> impl Parser<'a, Token<'a>> {
    move |ctx| {
        take(1.., is(alphabetic)).parse(ctx)
            .map_result(|token| Token::Identifier(token))
    }
}

assert_eq!(identifier().parse("foobar"), Ok((
    ParserContext {
        input: "foobar",
        bounds: 0..6,
    },
    Token::Identifier("foobar")
)));

For more information, look in the examples directory in the git repository.

Modules

characters

Character matching methods that implement Tester for use with the is and isnt parser combinators.

combinators

Additional parser combinators.

prelude
types

Parser implementations and traits.