im using python module ply.lexto write a lexer. I got some of my tokens given with regex, but now I'm stuck with it. I have list of Keywordsone that should be token. data- This is a list of 1000 keywords that should all be recognized as one of the keywords. It can be, for example: _Function1 _UDFType2etc. All words in the list are separated by spaces. I just want lexer to recognize the words in this list so that it returns a token like `KEYWORD.
data = 'Keyword1 Keyword2 Keyword3 Keyword4'
def t_KEYWORD(t):
return t
text = '''
Some test data
even more
$var = 2231
$[]Test this 2.31 + / &
'''
autoit = lex.lex()
autoit.input(text)
while True:
tok = autoit.token()
if not tok: break
print(tok)
So, I tried to add a variable to this regex, but that didn't work. I always get:
No regular expression defined for rule 't_KEYWORD'.
Thank you in advance! John