1 #ifndef YACAS_LISPERROR_H 2 #define YACAS_LISPERROR_H 3 4 #include <string> 5 6 class LispError { 7 public: 8 LispError(const std::string& msg); 9 10 const char* what() const; 11 12 private: 13 const std::string _what; 14 }; 15 16 inline LispError(const std::string & what)17LispError::LispError(const std::string& what): 18 _what(what) 19 { 20 } 21 22 inline what()23const char* LispError::what() const 24 { 25 return _what.c_str(); 26 } 27 28 class LispErrInvalidArg: public LispError { 29 public: LispErrInvalidArg()30 LispErrInvalidArg(): 31 LispError("Invalid argument") {} 32 }; 33 34 class LispErrWrongNumberOfArgs: public LispError { 35 public: LispErrWrongNumberOfArgs()36 LispErrWrongNumberOfArgs(): 37 LispError("Wrong number of arguments") {} 38 }; 39 40 class LispErrNotList: public LispError { 41 public: LispErrNotList()42 LispErrNotList(): 43 LispError("Argument is not a list") {} 44 }; 45 46 class LispErrListNotLongEnough: public LispError { 47 public: LispErrListNotLongEnough()48 LispErrListNotLongEnough(): 49 LispError("List not long enough") {} 50 }; 51 52 class LispErrInvalidStack: public LispError { 53 public: LispErrInvalidStack()54 LispErrInvalidStack(): 55 LispError("Invalid stack") {} 56 }; 57 58 class Quitting: public LispError { 59 public: Quitting()60 Quitting(): 61 LispError("Quitting...") {} 62 }; 63 64 class LispErrNotEnoughMemory: public LispError { 65 public: LispErrNotEnoughMemory()66 LispErrNotEnoughMemory(): 67 LispError("Not enough memory") {} 68 }; 69 70 class InvalidToken: public LispError { 71 public: InvalidToken()72 InvalidToken(): 73 LispError("Empty token during parsing") {} 74 }; 75 76 class LispErrInvalidExpression: public LispError { 77 public: LispErrInvalidExpression()78 LispErrInvalidExpression(): 79 LispError("Error parsing expression") {} 80 LispErrInvalidExpression(const std::string & ctx)81 explicit LispErrInvalidExpression(const std::string& ctx): 82 LispError("Error parsing expression near token " + ctx) {} 83 84 }; 85 86 class LispErrUnprintableToken: public LispError { 87 public: LispErrUnprintableToken()88 LispErrUnprintableToken(): 89 LispError("Unprintable atom") {} 90 }; 91 92 class LispErrFileNotFound: public LispError { 93 public: LispErrFileNotFound()94 LispErrFileNotFound(): 95 LispError("File not found") {} 96 }; 97 98 class LispErrReadingFile: public LispError { 99 public: LispErrReadingFile()100 LispErrReadingFile(): 101 LispError("Error reading file") {} 102 }; 103 104 class LispErrCreatingUserFunction: public LispError { 105 public: LispErrCreatingUserFunction()106 LispErrCreatingUserFunction(): 107 LispError("Could not create user function") {} 108 }; 109 110 class LispErrCreatingRule: public LispError { 111 public: LispErrCreatingRule()112 LispErrCreatingRule(): 113 LispError("Could not create rule") {} 114 }; 115 116 class LispErrArityAlreadyDefined: public LispError { 117 public: LispErrArityAlreadyDefined()118 LispErrArityAlreadyDefined(): 119 LispError("Rule base with this arity already defined") {} 120 }; 121 122 class LispErrCommentToEndOfFile: public LispError { 123 public: LispErrCommentToEndOfFile()124 LispErrCommentToEndOfFile(): 125 LispError("Reaching end of file within a comment block") {} 126 }; 127 128 class LispErrNotString: public LispError { 129 public: LispErrNotString()130 LispErrNotString(): 131 LispError("Argument is not a string") {} 132 }; 133 134 class LispErrNotInteger: public LispError { 135 public: LispErrNotInteger()136 LispErrNotInteger(): 137 LispError("Argument is not an integer") {} 138 }; 139 140 class LispErrParsingInput: public LispError { 141 public: LispErrParsingInput()142 LispErrParsingInput(): 143 LispError("Error while parsing input") {} 144 }; 145 146 class LispErrMaxRecurseDepthReached: public LispError { 147 public: LispErrMaxRecurseDepthReached()148 LispErrMaxRecurseDepthReached(): 149 LispError("Max evaluation stack depth reached.\nPlease use MaxEvalDepth to increase the stack size as needed.") {} 150 }; 151 152 class LispErrDefFileAlreadyChosen: public LispError { 153 public: LispErrDefFileAlreadyChosen()154 LispErrDefFileAlreadyChosen(): 155 LispError("DefFile already chosen for function") {} 156 }; 157 158 class LispErrDivideByZero: public LispError { 159 public: LispErrDivideByZero()160 LispErrDivideByZero(): 161 LispError("Divide by zero") {} 162 }; 163 164 class LispErrNotAnInFixOperator: public LispError { 165 public: LispErrNotAnInFixOperator()166 LispErrNotAnInFixOperator(): 167 LispError("Trying to make a non-infix operator right-associative") {} 168 }; 169 170 class LispErrUser: public LispError { 171 public: LispErrUser(const std::string & msg)172 LispErrUser(const std::string& msg): 173 LispError(msg) {} 174 }; 175 176 class LispErrIsNotInFix: public LispError { 177 public: LispErrIsNotInFix()178 LispErrIsNotInFix(): 179 LispError("Trying to get precedence of non-infix operator") {} 180 }; 181 182 class LispErrSecurityBreach: public LispError { 183 public: LispErrSecurityBreach()184 LispErrSecurityBreach(): 185 LispError("Trying to perform an insecure action") {} 186 }; 187 188 class LispErrLibraryNotFound: public LispError { 189 public: LispErrLibraryNotFound()190 LispErrLibraryNotFound(): 191 LispError("Could not find library") {} 192 }; 193 194 class LispErrUserInterrupt: public LispError { 195 public: LispErrUserInterrupt()196 LispErrUserInterrupt(): 197 LispError("User interrupted calculation") {} 198 }; 199 200 class LispErrNonBooleanPredicateInPattern: public LispError { 201 public: LispErrNonBooleanPredicateInPattern()202 LispErrNonBooleanPredicateInPattern(): 203 LispError("Predicate doesn't evaluate to a boolean in pattern") {} 204 }; 205 206 class LispErrProtectedSymbol: public LispError { 207 public: LispErrProtectedSymbol(const std::string & s)208 explicit LispErrProtectedSymbol(const std::string& s): 209 LispError(std::string("Attempt to override protected symbol: ") + s) {} 210 }; 211 212 class LispErrGeneric: public LispError { 213 public: LispErrGeneric(const std::string & what)214 LispErrGeneric(const std::string& what): 215 LispError(what) {} 216 }; 217 218 class LispEnvironment; 219 class LispOutput; 220 221 void HandleError(const LispError&, LispEnvironment& aEnvironment, std::ostream& aOutput); 222 223 224 #endif 225 226