75 lines
2.3 KiB
C++
75 lines
2.3 KiB
C++
#include <LXC.h>
|
|
|
|
#include <NodeTypes.h>
|
|
#include <Parser.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 = "examples/Fib.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();
|
|
}
|
|
|
|
// 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();
|
|
|
|
// 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(), '(', 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], '}');
|
|
|
|
if (err.reason == Lexer::LexerError::UnknownSymbolOrOperand)
|
|
Util::PrintLn(": {", err.info, '}');
|
|
|
|
else
|
|
Util::PrintLn();
|
|
|
|
Util::Log("Error occured in Lexer: ", Lexer::LexerError::ReasonStr(err.reason));
|
|
Util::Stop();
|
|
}
|
|
else
|
|
{
|
|
// Prints all of the tokensto the log //
|
|
for (const auto& token : tokens.Result())
|
|
{
|
|
Util::Log(token);
|
|
}
|
|
}
|
|
|
|
// Turns the tokens into into an abstract syntax tree //
|
|
Util::ReturnVal functionsAST = Parser::TurnTokensIntoAST(tokens);
|
|
|
|
return 0;
|
|
}
|