I have a python pyparsing language grammar where the language allows both /*... */ and // style comments. Currently a regex filters the comments out before calling the parser.
The problem I am trying to solve is that I want to make the system use the comments to automatically generate documentation similar to Autodoc. My thought for a solution is, instead of pre-filtering out comments, I want to add them to the pyParsing definition of white-space. But then how would I retrieve the comments in order to associate them with (for example) the class or function definition that follows in the text?
I need to retrieve all the comments, even the ones that are not associated with classes or functions. Is there a way to do that? Or is there a better solution that I'm not seeing?
EDIT: By "adding to the definition of white space" I mean using the "ignore(expr)" function.