1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use syn::{self, braced, Token};
pub struct Definitions {
pub inner: syn::punctuated::Punctuated<Definition, Token![,]>,
}
pub type Attributes = syn::punctuated::Punctuated<Attribute, Token![,]>;
impl syn::parse::Parse for Definitions {
fn parse(input: syn::parse::ParseStream) -> syn::parse::Result<Self> {
Ok(Self {
inner: input.parse_terminated(syn::parse::Parse::parse)?,
})
}
}
pub struct Definition {
pub name: syn::Ident,
pub attrs: Attributes,
}
impl syn::parse::Parse for Definition {
fn parse(input: syn::parse::ParseStream) -> syn::parse::Result<Self> {
let name = input.parse()?;
let content;
let _ = braced!(content in input);
let attrs = content.parse_terminated(syn::parse::Parse::parse)?;
Ok(Self { name, attrs })
}
}
pub struct Attribute {
pub key: syn::Ident,
_eq: Token![=],
pub value: syn::Lit,
}
impl syn::parse::Parse for Attribute {
fn parse(input: syn::parse::ParseStream) -> syn::parse::Result<Self> {
Ok(Self {
key: input.parse()?,
_eq: input.parse()?,
value: input.parse()?,
})
}
}