Is it possible to parse non-trivial C enums with pyparsing?

Viewed 1159

I have a preprocessed C file and I need to enumerate the members of one of the enums inside it. pyparsing ships with a simple example for that (examples/cpp_enum_parser.py), but it only works when enum values are positive integers. In real life a value may be negative, hex, or a complex expression.

I don't need structured values, just the names.

enum hello {
    minusone=-1,
    par1 = ((0,5)),
    par2 = sizeof("a\\")bc};,"),
    par3 = (')')
};

When parsing the value, the parser should skip everything until [('",}] and handle these chars. For that Regex or SkipTo may be useful. For strings and chars - QuotedString. For nested parentheses - Forward (examples/fourFn.py)

2 Answers
Related