banjin

Build Status Crates.io Documentation dependency status

Simple code generator for string parsing

Attributes

There are several attributes that control behaviour of parser Each, attached to struct's field

Formats

Usage

```rust use std::str::FromStr;

[derive(banjin::Parser)]

pub struct Data { #[startswith = "prefix"] #[skip(ws)] #[startswith = "+"] #[skip(ws)] #[format(ascii)] #[format(digit(10))] pub first: u32, #[skip(ws)] #[format(not("d"))] #[format("13")] #[endswith = "d"] #[endswith = ""] pub second: String, }

fn main() { let data = Data::fromstr("prefix + 666 13d").expect("Parse"); asserteq!(data.first, 666); assert_eq!(data.second, "13");

let data = Data::from_str("prefix + 666   13");
assert!(data.is_err());

let data = Data::from_str("prefix 666   13d");
assert!(data.is_err());

let data = Data::from_str("prefix + 666   13dg");
assert!(data.is_err());

let data = Data::from_str("");
assert!(data.is_err());

}

```