Regex to parse C/C++ functions declarations

前端 未结 3 1257
夕颜
夕颜 2020-12-18 07:36

I need to parse and split C and C++ functions into the main components (return type, function name/class and method, parameters, etc).

I\'m working from either heade

3条回答
  •  Happy的楠姐
    2020-12-18 08:19

    C++ is notoriously hard to parse; it is impossible to write a regex that catches all cases. For example, there can be an unlimited number of nested parentheses, which shows that even this subset of the C++ language is not regular.

    But it seems that you're going for practicality, not theoretical correctness. Just keep improving your regex until it catches the cases it needs to catch, and try to make it as stringent as possible so you don't get any false matches.

    Without knowing the "odd exceptions" that it doesn't catch, it's hard to say how to improve the regex.

提交回复
热议问题