python - "SyntaxError: Can't build lexer"? -


here code:

import ply.lex lex  tokens = (     'langle', # <     'langleslash', # </     'rangle', # >     'equal', # =     'string', # "hello"     'word') # welcome!  state = ( ("htmlcomment", "exclusive"), )  t_ignore = ' '  def t_htmlcomment(token):     r'<!--'     token.lexer.begin('htmlcomment')  def t_htmlcomment_end(token):     r'-->'     token.lexer.lineno += token.value.count('\n')     token.lexer.begin('initial')  def t_htmlcomment_error(token):     token.lexer.skip(1)  def t_newline(token):     r'\n'     token.lexer.lineno += 1     pass  def t_langleslash(token):     r'</'     return token  def t_langle(token):     r'<'     return token  def t_rangle(token):     r'>'     return token  def t_equal(token):     r'='     return token  def t_string(token):     r'"[^"]*"'     token.value = token.value[1:-1] # dropping off double quotes     return token  def t_word(token):     r'[^ <>\n]+'     return token  webpage = "this <b>my</b> webpage" htmllexer = lex.lex() htmllexer.input(webpage) while true:     tok = htmllexer.token()     if not tok: break     print(tok) 

when run error:

traceback (most recent call last):   file "/home/******/documents/pro/main.py", line 62, in <module>     htmllexer = lex.lex()   file "/usr/lib/python2.7/dist-packages/ply/lex.py", line 901, in lex     raise syntaxerror("can't build lexer") syntaxerror: can't build lexer 

i think problem here:

state = ( ("htmlcomment", "exclusive"), ) 

but cant fix it.

does have suggestions how can fix that?

thank help!

there might problem t_ functions


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -