The parsing code in auxi/tools/chemistry/stoichiometry.py has much logical duplication. It also uses the ord values of characters, which should not be relied upon. We should parse once into an abstract representation and then derive the other properties from there instead of parsing the same string many times with different goals as is currently done.
I have a working parser which handles this a little more normally, with separate tokenisation and parsing to an abstract form, but it may be even better just to use a proper parsing framework like PyParsing or the newer Parsimonious.
The parsing code in
auxi/tools/chemistry/stoichiometry.py
has much logical duplication. It also uses theord
values of characters, which should not be relied upon. We should parse once into an abstract representation and then derive the other properties from there instead of parsing the same string many times with different goals as is currently done.I have a working parser which handles this a little more normally, with separate tokenisation and parsing to an abstract form, but it may be even better just to use a proper parsing framework like PyParsing or the newer Parsimonious.