p-arse

Crates.iop-arse
lib.rsp-arse
version0.0.1
sourcesrc
created_at2021-12-27 19:58:55.177862
updated_at2021-12-27 19:58:55.177862
descriptionthe inelegant parser
homepage
repositoryhttps://github.com/micouy/p-arse
max_upload_size
id503858
size44,656
Mikołaj Powierża (micouy)

documentation

README

p-( ㅅ ) — the inelegant parser

p-arse is a PEG parser library focused on readability and type safety • it follows the syntax from the original paper as closely as possible • the parsers are point-free (they're (mostly) variables, not functions), as opposed to nom's parsers which are functions or compositions of functions • this encourages the user to bind and name many intermediate parsers • it is similar to pest in this regard

warning: the project is in an early stage

example

let parse_hex_dd = |s: &str| {
    u8::from_str_radix(s, 16).unwrap()
};
let construct_color = |(r, g, b)| Color { r, g, b };

let hex_d = ('0'.to('9')).or('a'.to('f'));
let hex_dd = (hex_d, hex_d).maps(parse_hex_dd);
let color = ("#", hex_dd, hex_dd, hex_dd).r0().map(construct_color);

let (color, _tail) = color.p_arse("#defec8").unwrap();

check out other examples • i've some replicated examples from the other parser libaries, i.e. nom's hex color (mine), pest's ident list (mine) and pom's json (mine)

todo

  • add docs

  • add verbose error messages

  • allow access to the string slice captured by the parser (its children's captures concatenated) (kinda works, except where .rn() is used)

reference

  1. https://bford.info/pub/lang/peg.pdf
Commit count: 37

cargo fmt