def pop_and_check(self, expected): token = self.pop() if expected != token: raise ParseError("Invalid token at line {0}. Expected: {1} but received {2}." .format(self.get_line(), expected, token)) return token