robotpy-cppheaderparser
robotpy-cppheaderparser copied to clipboard
[BUG]: Cannot parse Enum in unnamed namespace
Problem description
I have something like:
#include <iostream>
namespace
{
enum MyEnum
{
A,B
};
}
int main(){
std::cout << "hello" << std::endl;
}
Then got:
In [8]: header = CppHeaderParser.CppHeader("main.cpp")
---------------------------------------------------------------------------
CppParseError Traceback (most recent call last)
File ~/.edm/envs/pmapp/lib/python3.8/site-packages/CppHeaderParser/CppHeaderParser.py:2975, in CppHeader.__init__(self, headerFileName, argType, encoding, preprocessed, **kwargs)
2974 if self.nameStack:
-> 2975 self._evaluate_stack()
2976 if self.stack and self.stack[0] == "class":
File ~/.edm/envs/pmapp/lib/python3.8/site-packages/CppHeaderParser/CppHeaderParser.py:3427, in CppHeader._evaluate_stack(self, token)
3426 debug_print("trace")
-> 3427 self._parse_enum()
3428 self.stack = []
File ~/.edm/envs/pmapp/lib/python3.8/site-packages/CppHeaderParser/CppHeaderParser.py:3593, in CppHeader._parse_enum(self)
3592 if tok.value != "enum":
-> 3593 raise self._parse_error((tok,), "enum")
3595 location = tok.location
CppParseError: unexpected 'namespace', expected 'enum'
The above exception was the direct cause of the following exception:
CppParseError Traceback (most recent call last)
Input In [8], in <cell line: 1>()
----> 1 header = CppHeaderParser.CppHeader("main.cpp")
File ~/.edm/envs/pmapp/lib/python3.8/site-packages/CppHeaderParser/CppHeaderParser.py:3115, in CppHeader.__init__(self, headerFileName, argType, encoding, preprocessed, **kwargs)
3108 else:
3109 msg = "Error parsing %s%s\nError around: %s" % (
3110 self.headerFileName,
3111 context,
3112 " ".join(self.nameStack),
3113 )
-> 3115 raise_exc(
3116 CppParseError(msg),
3117 e,
3118 )
3120 self.finalize()
3121 global parseHistory
File <string>:1, in raise_exc(e, src_e)
CppParseError: Not able to parse main.cpp on line 3 evaluating 'namespace': unexpected 'namespace', expected 'enum'
Error around: enum MyEnum
Operating System
MacOS
Installed Python Packages
No response
Reproducible example code
No response