typhoon_metadata_extractor/
lib.rs

1mod doc;
2mod instruction;
3pub mod parsing;
4
5pub use {doc::*, instruction::*};
6
7// pub struct StateField<'a> {
8//     pub name: &'a Ident,
9//     pub ty: Type,
10// }
11
12// pub struct State<'a> {
13//     pub name: &'a Ident,
14//     pub fields: Vec<String>,
15// }
16
17// #[derive(Debug)]
18// pub enum ContextField {
19//     Account(InstructionAccount),
20//     Args,
21//     Bumps,
22// }
23
24// #[derive(Debug)]
25// pub struct Context<'a> {
26//     pub name: &'a Ident,
27//     pub fields: Vec<ContextField>,
28//     pub args: Option<&'a Ident>,
29// }
30
31// pub struct Intruction<'a> {
32//     pub name: &'a Ident,
33//     // pub context: Vec<Context>,
34// }
35
36// pub struct Program {
37//     //TODO
38// }
39
40// impl Program {
41//     fn from_file(file: &File) -> Program {
42//         let context = ParsingContext::from(file);
43//         let (accounts, contexts) = Self::extract_accounts_and_contexts(file, &context);
44//         Program {}
45//     }
46
47//     fn extract_accounts_and_contexts<'a>(
48//         file: &'a File,
49//         context: &ParsingContext<'a>,
50//     ) -> (Vec<Account<'a>>, Vec<Context<'a>>) {
51//         let mut accounts = Vec::with_capacity(context.accounts.len());
52//         let mut contexts = Vec::with_capacity(context.contexts.len());
53
54//         for item in &file.items {
55//             if let Item::Struct(item_struct) = item {
56//                 let name = &item_struct.ident;
57
58//                 if context.accounts.contains(&&item_struct.ident) {
59//                     // item_struct.fields.iter().map(|f| {
60//                     //     match f.ty {
61
62//                     //     }
63//                     // });
64//                     accounts.push(Self::parse_account(name, &item_struct.attrs));
65//                 }
66
67//                 if context.contexts.contains(&&item_struct.ident) {
68//                     contexts.push(Self::parse_context(name, &item_struct.fields));
69//                 }
70//             }
71//         }
72
73//         (accounts, contexts)
74//     }
75
76//     fn parse_account<'a>(name: &'a Ident, attrs: &[syn::Attribute]) -> Account<'a> {
77//         let mut docs = Docs::default();
78//         attrs.iter().for_each(|attr| docs.visit_attribute(attr));
79
80//         Account { name, docs }
81//     }
82
83//     fn parse_context<'a>(name: &'a Ident, fields: &'a syn::Fields) -> Context<'a> {
84//         let fields = fields
85//             .iter()
86//             .map(|f| {
87//                 let mut docs = Docs::default();
88//                 f.attrs.iter().for_each(|attr| docs.visit_attribute(attr));
89
90//                 let account = Account {
91//                     name: f.ident.as_ref().unwrap(),
92//                     docs,
93//                 };
94
95//                 ContextField::Account(account)
96//             })
97//             .collect();
98
99//         Context {
100//             name,
101//             fields,
102//             args: None,
103//         }
104//     }
105// }