I am creating a C++ class parser and I am trying to get the info from the header and the source file of a class.
I would like to get all the info about the class, specifically from the header first I need:
- the headers to be included
- other declarations and defines
- the class name, the class access specifiers and the base classes names and access specifiers
- the class constructors and destructor
- the class members and their info
- the class methods and their info
- other nested struct or classes
For now I was kind of able to get the headers and the class name. I got stuck at the class members as they can have several modifiers, the return type, can be written as Class::method or just method and finally they have constrains on their naming.
As an example I have tried the following regex
^(\s*(?:(?:virtual|inline|constexpr|static|friend|override)\s+)?((?!Automobile)[a-zA-Z_][a-zA-Z0-9_]*\s*)((Automobile::(?!Automobile)[a-zA-Z_][a-zA-Z0-9_]*)|((?!Automobile)[a-zA-Z_][a-zA-Z0-9_]*(?!::)))).+
just for the part of the method up to the brackets. The problem is that it recognizes
Automobile::Automobile() {
Automobile::Automobile(int a, int b) {
Automobile::Automobile();
Automobile::Automobile(int a, int b);
Automobile::Automobile(int a, int b)
Automobile::Automobile()
void Automobile::start //-> this
bool Automobile::start() //-> this
Automobile()
constexpr void Automobile::start \n //-> this
Autamobile::start //-> this
inline corri()//-> this
void Automobile::1_cjoin() //-> this
run()//-> this
Of course the last four ones should not be matched.
Is there any good soul who would help me correcting the regex for this or (if willing) helping me with my project? In case I will give the link to the repo.
Thanks!