Refactor formula syntaxes into proper classes #2619