Pyparsing ignore except

I have a file, with pythonStyleComments in lines, for example:

def foo(): # declare
    # Simple function
    a = 0 # TODO: add random
    return a

So, then I want to add .ignore(pythonStyleComments) to pyparsing, but want to handle any meta (such as TODO: ). I know all meta words, so how I can exclude this comments from ignoring?

Maybe declare comment as ‘#’ + Regex(), where Regex would be exclude meta words? Or pyparsing has more elegant method?


Source: regex

Leave a Reply