Add the error code to the diagnostic

This commit is contained in:
Sameer Rahmani 2021-09-12 17:49:51 +01:00
parent b285172597
commit 766cf2dfed
4 changed files with 21 additions and 7 deletions

View File

@ -1,5 +1,5 @@
(def main
(fn () 4))
(fn () 4)))
(def main1 (fn (v y n) 3))
ht

View File

@ -25,6 +25,7 @@
#ifndef SERENE_ERRORS_CONSTANTS_H
#define SERENE_ERRORS_CONSTANTS_H
#include <llvm/Support/FormatVariadic.h>
#include <map>
#include <string>
@ -32,7 +33,7 @@ namespace serene {
namespace errors {
enum ErrID {
E0000,
E0000 = 0,
E0001,
E0002,
E0003,
@ -56,6 +57,8 @@ struct ErrorVariant {
ErrorVariant(ErrID id, std::string desc, std::string longDesc)
: id(id), description(desc), longDescription(longDesc){};
std::string getErrId() { return llvm::formatv("E{0:d}", id); };
};
static ErrorVariant

View File

@ -84,18 +84,22 @@ void Diagnostic::print(llvm::raw_ostream &os, llvm::StringRef prefix) {
llvm::WithColor s(os, llvm::raw_ostream::SAVEDCOLOR, true, false, mode);
s << "[";
if (err) {
writeColorByType(os, err->getErrId());
}
s << "] ";
writeColorByType(os, getPrefix(prefix));
s << "]: ";
s << ": ";
if (err) {
s << err->description << "\n";
s << err->description << '\n';
}
if (message != "") {
s.changeColor(llvm::raw_ostream::Colors::YELLOW);
s << "With message: ";
s << "With message";
s.resetColor();
s << message << "\n";
s << ": " << message << "\n";
}
s << "In ns '";

View File

@ -222,7 +222,14 @@ exprs::Node Reader::readSymbol() {
if (!this->isValidForIdentifier(*c) || isEndOfBuffer(c) || isspace(*c)) {
advance();
loc = LocationRange(getCurrentLocation());
ctx.diagEngine->emitSyntaxError(loc, errors::InvalidCharacterForSymbol);
std::string msg;
if (*c == ')') {
msg = "An extra ')' is detected.";
}
ctx.diagEngine->emitSyntaxError(loc, errors::InvalidCharacterForSymbol,
msg);
exit(1);
}