glue 0.6.1

Glue is a parser combinator framework for parsing text based formats, it is easy to use and relatively fast too.
Documentation
glue-0.6.1 has been yanked.

Glue v0.6.0

Build Status codecov Latest Version Documentation Minimum rustc version License:MIT lines of code

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

Usage

use glue::prelude::*;

fn main() {
    match take(1.., is(alphabetic)).parse("foobar") {
        Ok((result, _)) => {
            println!("Found: {}", result);
        },
        Err(_) => {
            println!("Nothing found!");
        }
    }
}

Writing your own parser functions

use glue::prelude::*;

#[derive(Debug, PartialEq)]
enum Token {
    Identifier(String),
}

fn identifier<I: Parsable>() -> impl Parser<I, Token> {
    move |input: I| {
        let (token, input) = take(1.., is(alphabetic)).parse(input)?;

        Ok((Token::Identifier(token.to_string()), input))
    }
}

fn main() {
    assert_eq!(identifier().parse("foobar"), Ok((
        Token::Identifier("foobar".into()),
        ""
    )));
}

Pretty human readable error messages

Glue does the hard work of implementing error messages for you, have a look at this example which created the following message:

   1 │ foo xxx
   · │       ┃
   · ┢━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
   · ┃ Unexpected 'xxx'                                                       ┃
   · ┃ Expected bar                                                           ┃
   · ┃ At 1:7 of path/to/file                                                 ┃
     ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

For more information, read the tutorial, check the cheat sheet, look in the examples directory in the git repository.