bogus/src/SyntaxError.cpp

54 lines
2.0 KiB
C++

#include "SyntaxError.h"
void SyntaxError::fnTypeMismatch(string function, vector<string> validTypes, valtype typeGiven, string notes) {
cerr << "TypeError: function type mismatch" << endl;
cerr << "Function '" << function << "' expected one of the following types: ";
for (int i = 0; i < validTypes.size(); i++) {
if (i != 0) cerr << ", ";
cerr << validTypes[i];
}
cerr << endl << "Got type '";
if (typeGiven == valtype::INT) cerr << "int";
else if (typeGiven == valtype::DEC) cerr << "dec";
else if (typeGiven == valtype::STR) cerr << "str";
else if (typeGiven == valtype::BOOL) cerr << "bool";
else cerr << "unknown";
cerr << "' instead" << endl;
if (!notes.empty()) cerr << "Notes: " << notes << endl;
exit(1);
}
void SyntaxError::fnNotSufficientArgs(string function, int minArgs, int maxArgs, int argsGiven) {
cerr << "TypeError: function not sufficient arguments" << endl;
cerr << "Function '" << function << "' expected between " << minArgs << " and " << maxArgs << " arguments, got " << argsGiven << endl;
exit(1);
}
void SyntaxError::unknownFn() {
cerr << "TypeError: unknown function" << endl;
exit(1);
}
void SyntaxError::mathTypeMismatch(string notes) {
cerr << "MathError: cannot use two different types together" << endl;
if (!notes.empty()) cerr << "Notes: " << notes << endl;
exit(1);
}
void SyntaxError::mathTooFewArgs(string notes) {
cerr << "MathError: too few things to add together" << endl;
if (!notes.empty()) cerr << "Notes: " << notes << endl;
exit(1);
}
void SyntaxError::mathCannotDoOperationOnType(string operatorUsed, string type, string notes) {
cerr << "MathError: cannot use operator '" + operatorUsed + " on type '" + type + "'" << endl;
if (!notes.empty()) cerr << "Notes: " << notes << endl;
exit(1);
}
void SyntaxError::generalError(string notes) {
cerr << "GeneralError: Something went awfully wrong and we don't know why lmao" << endl;
if (!notes.empty()) cerr << "Notes: " << notes << endl;
exit(1);
}