Comparison of parsers in python?
andrew at acooke.org
Sun Sep 20 15:19:21 CEST 2009
also, parsing large files may be slow. in which case you may be
better with a non-python solution (even if you call it from python).
your file format is so simple that you may find a lexer is enough for
what you want, and they should be stream oriented. have a look at the
"shlex" package that is already in python. will that help?
alternatively, perhaps plex - http://www.cosc.canterbury.ac.nz/greg.ewing/python/Plex/
- that is pure python, but greg ewing is a good programmer and he says
on that page it is as fast as possible for python, so it is probably
going to be quite fast.
ps maybe you already know, but a lexer is simpler than a parser in
that it doesn't use the context to decide how to treat things. so it
can recognise something is a number, or a word, or a quoted string,
but not whether it is part of a track definition line or a data value,
for example. but in this case the format is so simple that a lexer
might do quite a ot of what you want, and would make the remaining
plain python program very simple.
More information about the Python-list