Glue is a parser combinator framework for parsing text based formats, it is easy to use and relatively fast too.


Keywords
parsing, parser-combinators, parser
License
MIT

Documentation

Glue v0.9

Glue is a parser combinator framework for parsing text based formats, it is easy to use and relatively fast too.

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:

use glue::prelude::*;

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

Write your own parser functions:

use glue::prelude::*;

#[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.