#parser #parsing #parser-combinators

glue

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

14 releases (7 breaking)

✓ Uses Rust 2018 edition

0.8.3 Aug 30, 2019
0.7.0 Jul 11, 2019

#92 in Parser tooling

Download history 32/week @ 2019-05-17 41/week @ 2019-05-24 2/week @ 2019-05-31 18/week @ 2019-06-07 2/week @ 2019-06-14 65/week @ 2019-06-21 21/week @ 2019-06-28 54/week @ 2019-07-05 18/week @ 2019-07-12 13/week @ 2019-07-19 10/week @ 2019-07-26 33/week @ 2019-08-02 23/week @ 2019-08-09 2/week @ 2019-08-16 110/week @ 2019-08-23

130 downloads per month
Used in 3 crates

MIT license

61KB
1.5K SLoC

Glue v0.8

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.

Dependencies

~0.6–1MB
~21K SLoC