lex を試す、t_ignore
読みとばしトークン用に t_ignore というのが
あらかじめ用意されているようだ
#!/usr/bin/env python import ply.lex as lex tokens = ( 'CHAR', 'PLUS', ) t_CHAR = r'\w+' t_PLUS = r'\+' t_ignore = ' \t' def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.skip(1) lex.lex() lex.input("a + b + abc") while 1: tok = lex.token() if not tok: break # No more input print tok
で、
LexToken(CHAR,'a',1,0) LexToken(PLUS,'+',1,2) LexToken(CHAR,'b',1,4) LexToken(PLUS,'+',1,6) LexToken(CHAR,'abc',1,8)