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 Buffer. It stores any peeked data into a VecDeque. Any values peeked will be stored into the VecDeque, and next will either call VecDeque::pop_front or Iterator::next on the inner iter |
Cursor | Cursors are a Buffer that non-destructively read from their parent buffers using Buffer::peek_ahead See Buffer documentation for example usage |
Vec1 | Vec1 is similar to |
Traits
Buffer | Buffer is an extension to an Iterator, with the ability to create a cursor over the iterator, which can infinitely read from the iterator, preserving the buffer's position |
IntoBuf | IntoBuf is the equivalent of IntoIterator for a basic implementation of Buffer |
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. |
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 |