How to parse in easy way a .h file written in C for comments and entity names using Python?
We’re suppose for a further writing the content into the word file already developed.
Source comments are formatted using a simple tag-style rules. Comment tags used for an easy distinguishing one entity comment from the other and non-documenting comments. A comment could be in multi-line form. An each comment have stay straight upon the entity definition:
//ENUM My comment bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla // could be multi-line. Bla bla bla bla bla bla bla bla bla. enum my_enum { //EITEM My enum item 1. // Just could be multi-line too. MY_ENUM_ITEM_1, //EITEM My enum item 2 MY_ENUM_ITEM_2, }; //STRUCT My struct struct my_struct { //MEMBER struct member 1 int m_1_; }; //FUNC my function 1 description. // Could be multi-line also. //INPUT arg1 - first argument //RETURN pointer to an allocated my_struct instance. my_struct* func_1(int arg1);
A code-and-comments tree should come out as a result of this parsing.
How does one make it quickly and without using third-party libraries?
Here’s a quick and dirty solution. It won’t handle comments in strings, but since this is just for header files that shouldn’t be an issue.