Crate nommy[−][src]
Type based parsing library
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(), }, ] } );
Re-exports
pub use eyre; |
Modules
bytes | Basic Parsers over byte data |
text | Basic Parsers over string data |
Structs
Buf | Buf is the standard implementation of |
Cursor |
|
Vec1 | Vec1 is similar to |
Traits
Buffer |
|
IntoBuf |
|
Parse | An interface for creating and composing parsers
Takes in a |
Functions
parse |
|
parse_terminated |
|
Derive Macros
Parse | Derive Parse for structs or enums |