#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

10 releases (6 breaking)

✓ Uses Rust 2018 edition

0.7.0 Jul 11, 2019
0.6.0 May 24, 2019
0.5.2 May 6, 2019
0.4.0 Apr 30, 2019
0.1.0 Apr 24, 2019

#66 in Parser tooling

Download history 15/week @ 2019-04-18 51/week @ 2019-04-25 50/week @ 2019-05-02 13/week @ 2019-05-09 29/week @ 2019-05-16 31/week @ 2019-05-23 19/week @ 2019-05-30 19/week @ 2019-06-06 1/week @ 2019-06-13 31/week @ 2019-06-20 56/week @ 2019-06-27 43/week @ 2019-07-04

120 downloads per month
Used in 3 crates

MIT license

72KB
1.5K SLoC

Glue v0.7.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.into()), 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.

Dependencies

~764KB
~17K SLoC