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

Cursor is a Buffer that non-destructively reads from it's parent's buffer using Buffer::peek_ahead See Buffer documentation for example usage

Vec1

Vec1 is similar to Vec but implements Parse such that it will error if it fails to parse at least once

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

Functions

parse

parse takes the given iterator, putting it through P::parse

parse_terminated

parse_terminated takes the given iterator, putting it through P::parse, erroring if the full input was not consumed

Derive Macros

Parse

Derive Parse for structs or enums