Implemented all Lexer errors

This commit is contained in:
Pasha Bibko
2025-07-20 22:34:11 +01:00
parent bb3d8fb13e
commit a6afeff493
6 changed files with 58 additions and 11 deletions

View File

@@ -27,8 +27,6 @@ int main(int argc, char** argv)
Util::Stop();
}
Util::Log("Succesfully opened source file.");
// Turns the file contents into a vector of tokens //
Util::ReturnVal tokens = Lexer::TokenizeFile(fileContents);
if (tokens.Failed()) _UNLIKELY
@@ -36,11 +34,23 @@ int main(int argc, char** argv)
// Stores the error for easier access //
Lexer::LexerError& err = tokens.Error();
// Finds the file location of the error //
Util::FileLocation location;
Util::GetFileLocationAtIndex(location, fileContents, err.index);
// Prints the error to the console //
Util::PrintAs<Util::WHITE>("[LXC] ");
Util::Print(src.filename().string());
Util::Print(src.filename().string(), '(', location.line, ',', location.col, ')');
Util::PrintAs<Util::LIGHT_RED>(" Error: ");
Util::Print(Lexer::LexerError::ReasonStr(err.reason));
if (err.reason == Lexer::LexerError::InvalidCharacter)
Util::PrintLn(": {", fileContents.Result()[err.index], '}');
else
Util::PrintLn();
Util::Log("Error occured in Lexer: ", Lexer::LexerError::ReasonStr(err.reason));
Util::Stop();
}