glue 0.5.4

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

Glue

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

Usage

use glue::prelude::*;

match merge_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) = merge_1(is(alphabetic)).parse(input)?;

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

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 detailed examples, look in the examples directory in the git repository.

List of parsers and combinators

Branches

Matches

Repeaters

Sequences

Structures