Parser Compose
DEPRECATED. See bparse
⚠️ Warning ☣️
Homemade, hand-rolled code ahead. Experimental. May not function as advertised.
What?
parser-compose
is a crate for writing parsers for arbitrary data formats. You
can use it to parse string slices and slice
s whose elements implement
Clone
.
Similar projects
How is this different?
parser-compose
does nothing for error handling or reporting. If the parser
suceeds you get a Some(..)
with the value. If the parser fails you get a
None
. Many parsing tasks do not require knowing why parsing fails, only
that it did. For example, when parsing an HTTP message header, you just want to
know if it is valid or not. This crate focuses on this use case, and in so
doing sheds all the ceremony involved in supporting parser error handling.
Examples
Parsing a IMF http date.
use ;
let input = "Sun, 06 Nov 1994 08:49:37 GMT";
let = imfdate.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// missing comma after day name
assert!;
Validating an http quoted string:
use ;
/// Tries to parse a quoted string out of `input`.
/// If it succeeds, the returned tuple contains the quoted string (without
/// quotes) along with the rest of the input
// 3 quoted strings one after the other "1", "a" and "\""
let input = r##""1""a""\"""##.as_bytes;
let = quoted_string.unwrap;
assert_eq!;
// Notice that because of its signature, `quoted_string` can be treated as a parser
let = quoted_string.accumulate.try_parse.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
Thanks
This crate would not have been possible without:
- This post called You could have invented Parser Combinators, which brought the concept of parser combinators down from "academic sounding term, no thank you" to "wow, i can understand this"
- This guide to writing parser combinators in rust
- This
article
by the author of
pom
, which lays out the various approaches to writing parser combinators in rust.