Ex-Mente / auxi.0

GNU Lesser General Public License v3.0
8 stars 8 forks source link

Improved parser #192

Closed alchemyst closed 7 years ago

alchemyst commented 7 years ago

Incorporated a formula parser using parsimonious. I've kept the interface of stoichiometry.py exactly the same, but I've removed the redundant parsing code and replaced it with a single parser and some classes which represent the parsed bits. Instead of manual memoization, I've included the functools.lru_cache on the parsing function, which should work the same way with less effort. This new parser is much easier to extend if we need to parse new forms in the future.

I've tried to be relatively verbose in the comments, but I feel like parsing with the grammar is easier to understand than the previous hand-written parser. I'm putting this in as a pull request rather than just pushing because I know this is a big step and I want some eyes on this before merging.

Closes #191

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.6%) to 68.347% when pulling 7c3826169a84f8d2dd1179c18be528200e69b300 on dev-parser into 8fd1c11361018b0c5bc9374754d012df4ebf862f on develop.

alchemyst commented 7 years ago

Note that the reason coverage went down is because total lines of code in this well-covered module went down. The coverage in the files I worked on actually went up.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-1.2%) to 67.724% when pulling c673677b9c98f5d8e30dc888662b9ab4c3b91588 on dev-parser into 8fd1c11361018b0c5bc9374754d012df4ebf862f on develop.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-1.2%) to 67.702% when pulling 7928d16176646b59ea8fdb2a2641332c559d8ac4 on dev-parser into dbd296b51098da4617857a93889787137858de12 on develop.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-1.2%) to 68.374% when pulling a0a28026f60f211845ecc0811b27efafe066cf8e on dev-parser into fcf2bcb2e19a8aa5003936ba44b8b78822659fdc on develop.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-1.1%) to 69.637% when pulling 6d7ac47e7ef75cb7711f41c7bdb7cf5a0a597366 on dev-parser into 777f0247631020631b9954d71aab51c088d612a7 on develop.

alchemyst commented 7 years ago

@johanzietsman @johanzietsman-em @christoffkok Have you had a chance to look at this? I'd like to merge it or reject it, but it's tedious to keep this up to date with the other things I've committed.

christoffkok commented 7 years ago

@alchemyst I took a look at this and I am all for it. This looks like a great change. There is less code and it is easier to understand and work with, and the tests pass. @johanzietsman-em is the original author of this. Just waiting for an 'ok' from him.