-1

The second answer in this link provides a way to load enums from C++ to python:

Can python load definitions from a C header file?

The code works with the given example:

sample = """
stuff before
enum hello {
    Zero,
    One,
    Two,
    Three,
    Five=5,
    Six,
    Ten=10
    };
in the middle
enum blah
    {
    alpha,
    beta,
    gamma = 10 ,
    zeta = 50
    };
at the end
"""

However, it does not work for the following, due to the comments inside the enum:

sample = """
stuff before
enum hello {
    Zero,  //zero
    One,   //one
    Two,   //two
    Three,  //three
    Five=5,
    Six,
    Ten=10
    };
in the middle
enum blah
    {
    alpha,
    beta,   //beta
    gamma = 10 ,
    zeta = 50
    };
at the end
"""

Is there a simple way to suppress these comments in line with the code provided in the link above? I cannot comment on the answer as I lack the reputation.

CristiFati
  • 38,250
  • 9
  • 50
  • 87

1 Answers1

1

Import cppStyleComment from pyparsing, and than add it to the ignorables for your enum expression:

from pyparsing import cppStyleComment
...
enum.ignore(cppStyleComment)

This will handle C++ comments anywhere in your expression, not just the end-of-line ones in your example.

(Also, you should add the [pyparsing] tag to your question.)

PaulMcG
  • 62,419
  • 16
  • 94
  • 130