Initial commit
This commit is contained in:
81
src/SyntaxError.cpp
Normal file
81
src/SyntaxError.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
Iodine
|
||||
Copyright (C) 2025 Maxwell Jeffress
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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);
|
||||
}
|
||||
void SyntaxError::cannotCompareDifferentTypes(string notes) {
|
||||
cerr << "ComparisonError: cannot compare two different types" << endl;
|
||||
if (!notes.empty()) cerr << "Notes: " << notes << endl;
|
||||
exit(1);
|
||||
}
|
||||
void SyntaxError::comparisonTypeError(string notes) {
|
||||
cerr << "ComparisonError: cannot use a non-bool type in an if or while statement" << endl;
|
||||
if (!notes.empty()) cerr << "Notes: " << notes << endl;
|
||||
}
|
Reference in New Issue
Block a user