sea-orm
                                
                                
                                
                                    sea-orm copied to clipboard
                            
                            
                            
                        Throw compile errors when unexpected proc_macros attributes are provided
Related to #391
Create a whitelist for all supported #[sea_orm(xxx)] proc_macros attributes. Thrown compile errors when it parse unknown attributes.
I was researching this issue and I believe there should be something like
#[proc_macro_attribute]
pub fn sea_orm(attr: TokenStream, item: TokenStream) -> TokenStream {
where all the attributes would pass from like column_name and table_name but I was unable to find this code in repo.
Is it because we are using proc-macro2 and serde libraries?
Please guide me.
Thanks.
Hey @Diwakar-Gupta, thanks for the investigation!!
First, every procedural macros is self contained in a .rs file under the sea-orm-macros/src/derives folder.
For example, DeriveActiveEnum is defined in a file below:
https://github.com/SeaQL/sea-orm/blob/9f6b5664eba59c5eafeb6ce91e8946af47983fdd/sea-orm-macros/src/derives/active_enum.rs#L12-L186
Each procedural macros starts by parsing the inputting TokenStream manually. Yes, it's done manually and it's prone to mistake. And some old procedural macros don't even has a explicite parsing stage.
Ideally we want each procedural macro should be testable. With that in mind we better implement it in two stages:
- Parsing: take the input 
TokenStreaminto a struct that contains all necessary data for the next code generating stage. - Code Generating: take a data struct from the parsing stage and from that we can use 
quote!macro to generate necessary implementations. 
Then, we can test the parsing and code generating parts separately and thoroughly.
We already has the code generating inplace, we just need to rewrite all of them. I think https://github.com/TedDriggs/darling could helps us do the parsing.
Does that make sense to you?
Thanks for the explanation @billy1624
What I understood is each derive/* receives DeriveInput from which it extracts necessary attributes and values in enum/struct  called Parsing then it is passed for code addon using quote! called code generation.
This parsing step can be replaced with use of darling as you mentioned.
We wanted to test both parsing and code generation step's separately for each derive/*.
Create a whitelist for all supported
#[sea_orm(xxx)]proc_macros attributes. Thrown compile errors when it parse unknown attributes.
and this too right.
Sounds like we have a plan now :)