Search code examples
pythonply

Python and PLY: how to get rid of token 'XXX', defined but not used


I'm using Python and PLY. I'm ignoring comments with this rule:

    def t_ANY_COMMENT(self, t):
    r'//.*$'
    pass

It works fine, but I get this warning:

WARNING: Token 'COMMENT' defined, but not used

I'd like to get rid of this warning. I don't see anything in the PLY documentation to suggest what to do for this case.


Solution

  • in my case the solution was to simply not add COMMENT to the tokens variable. I had initially thought I had to add all the tokens there. Turns out, it's only the ones used by the yacc portion. that makes sense, but the doc didn't really come out and say that.