Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Cannot parse Enum in unnamed namespace #82

Open
sogoogos opened this issue Dec 7, 2022 · 2 comments
Open

[BUG]: Cannot parse Enum in unnamed namespace #82

sogoogos opened this issue Dec 7, 2022 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@sogoogos
Copy link

sogoogos commented Dec 7, 2022

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

@virtuald
Copy link
Member

virtuald commented Dec 7, 2022

cxxheaderparser can handle that (see https://robotpy.github.io/cxxheaderparser/ for a live demo you can paste that into).

I'm happy to accept PRs to fix this, however.

@virtuald virtuald added help wanted Extra attention is needed bug Something isn't working labels Dec 7, 2022
@sogoogos
Copy link
Author

sogoogos commented Dec 8, 2022

I was not aware of cxxheaderparser repo. I would switch to it once pip distribution becomes available

I'm happy to accept PRs to fix this, however.

I wish I could but unfortunately, I do not have currently the bandwidth for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants