Refactor error handling and reporting, and change the typed AST representation.