nommy_derive

Crates.ionommy_derive
lib.rsnommy_derive
version0.4.1
sourcesrc
created_at2021-01-27 13:21:42.415326
updated_at2021-02-08 09:47:53.742403
descriptionderive(Parse)
homepage
repositoryhttps://github.com/conradludgate/nommy
max_upload_size
id347256
size39,876
Conrad Ludgate (conradludgate)

documentation

README

nommy

A type based parsing library with convenient macros

use nommy::{parse, text::*, Parse};

type Letters = AnyOf1<"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ">;

#[derive(Debug, Parse, PartialEq)]
#[nommy(prefix = Tag<"struct">)]
#[nommy(ignore = WhiteSpace)]
struct StructNamed {
    #[nommy(parser = Letters)]
    name: String,

    #[nommy(prefix = Tag<"{">, suffix = Tag<"}">)]
    fields: Vec<NamedField>,
}

#[derive(Debug, Parse, PartialEq)]
#[nommy(suffix = Tag<",">)]
#[nommy(ignore = WhiteSpace)]
struct NamedField {
    #[nommy(parser = Letters)]
    name: String,

    #[nommy(prefix = Tag<":">, parser = Letters)]
    ty: String,
}
let input = "struct Foo {
    bar: Abc,
    baz: Xyz,
}";

let struct_: StructNamed = parse(input.chars()).unwrap();
assert_eq!(
    struct_,
    StructNamed {
        name: "Foo".to_string(),
        fields: vec![
            NamedField {
                name: "bar".to_string(),
                ty: "Abc".to_string(),
            },
            NamedField {
                name: "baz".to_string(),
                ty: "Xyz".to_string(),
            },
        ]
    }
);
Commit count: 54

cargo fmt