Sexy Lexing with Python
evanfosmark.com
evanfosmark.com
There's another popular library that escapes me, too.
For his example, it needs one more line:
simple = Scan(
IDENTIFIER = r'[\w_]\w*',
OPERATOR = r'[-+\*=]',
DIGIT = r'\d+(\.\d+)?',
END_STATEMENT = r';',
SPACE = r'\s+',
)
simple.ignore('SPACE')
simple('foo = 5 * 30; bar = bar - 60;')
# generates tokens.