micouy / p-arse

the inelegant parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 replicated some 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

About

the inelegant parser


Languages

Language:Rust 100.0%