6 months ago
- The chemparse project in Python parses chemical formula strings into dictionaries mapping elements to counts.
- Supported formula variants include simple formulas, fractional stoichiometry, groups, nested groups, and square brackets.
- A similar functionality is built in Factor using EBNF syntax for parsing expression grammar.
- Steps include parsing symbols, numbers, and pairs (symbols with optional numbers).
- The implementation involves flattening parsed elements into an associative array mapping elements to counts.
- Unit tests demonstrate support for various formula features like H2O, C1.5O3, (CH3)2, ((CH3)2)3, and K4[Fe(SCN)6].
- The code is available on GitHub.