thibaultmarin / hpp2plantuml

Convert C++ header files to PlantUML
MIT License
223 stars 35 forks source link

#ifdef in enum causes CppParseError exception #15

Closed TedLyngmoVCC closed 3 years ago

TedLyngmoVCC commented 3 years ago
enum class MyType : uint8_t {
    kFoo = 0,
    kBar
#ifdef UNIT_TESTS
    , kTest
#endif
};

Causes

Traceback (most recent call last):
  File "/home/tlyngmo/.local/lib/python3.8/site-packages/CppHeaderParser/CppHeaderParser.py", line 2963, in __init__
    self._evaluate_stack()
  File "/home/tlyngmo/.local/lib/python3.8/site-packages/CppHeaderParser/CppHeaderParser.py", line 3397, in _evaluate_stack
    self._parse_enum()
  File "/home/tlyngmo/.local/lib/python3.8/site-packages/CppHeaderParser/CppHeaderParser.py", line 3583, in _parse_enum
    self._parse_enumerator_list(newEnum["values"])
  File "/home/tlyngmo/.local/lib/python3.8/site-packages/CppHeaderParser/CppHeaderParser.py", line 3655, in _parse_enumerator_list
    tok = self._next_token_must_be("}", ",", "=", "DBL_LBRACKET")
  File "/home/tlyngmo/.local/lib/python3.8/site-packages/CppHeaderParser/CppHeaderParser.py", line 3164, in _next_token_must_be
    raise self._parse_error((tok,), "' or '".join(tokenTypes))
CppHeaderParser.CppHeaderParser.CppParseError: unexpected '#ifdef UNIT_TESTS', expected '}' or ',' or '=' or 'DBL_LBRACKET'
thibaultmarin commented 3 years ago

This is more an issue with the package we use to parse code (https://github.com/robotpy/robotpy-cppheaderparser). It does not aim at handling preprocessor directives, but the readme offers some suggestions.

TedLyngmoVCC commented 3 years ago

I'm satisfied with this explanation