Confusing syntax: either a pylint warning, or a program error using the "sly" lexer

20 Views Asked by At

I am using the sly lexer to build a simple lexer, and I am a little confused by the Python syntax in this one. The below code works, but I get a syntax warning in my editor, that I am using OPCODE before assignment.

from sly import Lexer

class AsmLexer(Lexer):    
    tokens = { OPCODE }
    ignore = '\t\n'

    OPCODE          = r'[A-Z]{3}'

When I move the OPCODE line before tokens though, I get this error:

sly.lex.LexerBuildError: OPCODE does not match a name in tokens

Now, I can live with a pylint warning, but I always want my code to be clean (warnings are bugs in disguise) and I don't really understand why this happens.

0

There are 0 best solutions below