Implemented all Lexer errors
This commit is contained in:
@@ -64,4 +64,39 @@ namespace LXC::Util
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
// Struct to hold a position within a file //
|
||||
struct FileLocation
|
||||
{
|
||||
unsigned short col;
|
||||
unsigned short line;
|
||||
};
|
||||
|
||||
// Finds the location of a given index within a file //
|
||||
inline bool GetFileLocationAtIndex(FileLocation& location, const std::string& file, __int32 index)
|
||||
{
|
||||
// Returns false if outside the bounds //
|
||||
if (index < 0 || index > file.length())
|
||||
return false;
|
||||
|
||||
// Resets location //
|
||||
location.line = 1;
|
||||
location.col = 1;
|
||||
|
||||
// Finds the location //
|
||||
__int32 localIndex = 0;
|
||||
while (localIndex != index)
|
||||
{
|
||||
if (file[localIndex] == '\n')
|
||||
{
|
||||
location.line += 1;
|
||||
location.col = 0;
|
||||
}
|
||||
|
||||
location.col++;
|
||||
localIndex++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,5 @@
|
||||
// LXC util files //
|
||||
|
||||
#include <Result.h>
|
||||
#include <FileRead.h>
|
||||
#include <File.h>
|
||||
#include <IO.h>
|
||||
|
||||
Reference in New Issue
Block a user