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 = "all")] 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 impls::Vec1; |
pub use eyre; |
Modules
bytes | |
impls | |
surrounded | |
text |
Structs
Buf | Buffer is a wrapper around an Iterator, highly linked to Cursor |
Cursor | Cursors are heavily related to Buffers. Refer there for documentation |
Traits
Buffer | |
IntoBuf | |
Parse | An interface for creating and composing parsers Takes in a Buffer iterator and consumes a subset of it, Returning Self if it managed to parse ok, otherwise returning a meaningful error Parse can be derived for some types |
Peek | An interface with dealing with parser-peeking. The required function peek takes in a Cursor iterator and will attempt to loosely parse the data provided, asserting that if the equivalent Buffer is given to the Parse::parse function, it should succeed. |
Process | Process is a standard interface to map a generated AST from the output of Parse::parse. All types that implement Parse should implement this trait. |
Functions
parse | parse takes the given iterator, putting it through |
parse_terminated | parse_terminated takes the given iterator, putting it through |
Derive Macros
Parse | Derive Parse for structs or enums |