A generic lexical analyzer in python