Glue is a parser combinator framework that is designed for parsing text based formats, it is easy to use and relatively efficient.
```rust use glue::prelude::*;
match merge(oneormore(is(alphabetic))).parse("foobar") { Ok((result, )) => { println!("Found: {}", result); }, Err() => { println!("Nothing found!"); } } ```
```rust use glue::prelude::*;
enum Token { Identifier(String), }
fn identifier
Ok((Token::Identifier(token.to_string()), input))
}
}
assert_eq!(identifier().parse("foobar"), Ok(( Token::Identifier("foobar".into()), "" ))); ```
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].
all((Parser, ...))either(Parser, Parser)optional()empty()is(Testable)isnt(Testable)literal(match: &str)take(number: usize)min_to_max(minimum: usize, maximum: usize, Parser)min_or_more(minimum: usize, Parser)zero_to_max(maximum: usize, Parser)zero_or_more(Parser)one_to_max(maximum: usize, Parser)one_or_more(Parser)merge(Parser)both(Parser, Parser)all((Parser, ...))separated_list(separator: Parser, Parser)