Correctly parses formulas with ions and groups