Skip to main content

seaography_generator/
parser.rs

1use proc_macro2::Ident;
2use quote::format_ident;
3
4pub struct EntityDefinition {
5    pub name: Ident,
6}
7
8pub fn parse_entity(file_name: String) -> EntityDefinition {
9    let name = &file_name[..file_name.len() - 3];
10    let name = format_ident!("{}", name);
11
12    EntityDefinition { name }
13}
14
15pub struct EnumerationDefinition {
16    pub name: Ident,
17}
18
19pub fn parse_enumerations(file_content: String) -> Vec<EnumerationDefinition> {
20    let tree = syn::parse2::<syn::File>(file_content.parse().unwrap()).unwrap();
21
22    let items: Vec<EnumerationDefinition> = tree
23        .items
24        .iter()
25        .filter(|item| matches!(item, syn::Item::Enum(_)))
26        .map(|item| match item {
27            syn::Item::Enum(enumeration) => EnumerationDefinition {
28                name: enumeration.ident.clone(),
29            },
30            _ => panic!("This is unreachable."),
31        })
32        .collect();
33
34    items
35}