55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
#include <LXC.h>
|
|
|
|
#include <Lexer.h>
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
using namespace LXC;
|
|
|
|
// Creates the debug log //
|
|
Util::CreateLog("LXC.log");
|
|
|
|
std::filesystem::path src = "example/example.lx";
|
|
|
|
// Reads the given file to a string //
|
|
Util::ReturnVal fileContents = Util::ReadFile(src);
|
|
if (fileContents.Failed()) _UNLIKELY
|
|
{
|
|
// Stores the error for easier access //
|
|
Util::FileReadError& err = fileContents.Error();
|
|
|
|
// Prints the error to the console //
|
|
Util::PrintAs<Util::WHITE>("[LXC]");
|
|
Util::PrintAs<Util::LIGHT_RED>(" Error: ");
|
|
Util::PrintLn(Util::FileReadError::ReasonStr(err.reason), " [", std::filesystem::absolute(err.path), ']');
|
|
|
|
Util::Log("Opening source file failed. Stopping program.");
|
|
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
|
|
{
|
|
// Stores the error for easier access //
|
|
Lexer::LexerError& err = tokens.Error();
|
|
|
|
// Prints the error to the console //
|
|
Util::PrintAs<Util::WHITE>("[LXC] ");
|
|
Util::Print(src.filename().string());
|
|
Util::PrintAs<Util::LIGHT_RED>(" Error: ");
|
|
|
|
Util::Stop();
|
|
}
|
|
|
|
// Prints all of the tokens to the log //
|
|
for (const auto& token : tokens.Result())
|
|
{
|
|
Util::Log(token);
|
|
}
|
|
|
|
return 0;
|
|
}
|