Compiles on UNIX based systems
This commit is contained in:
@@ -11,10 +11,10 @@ namespace LXC::Lexer
|
||||
|
||||
// Trackers for the Lexer itself //
|
||||
const std::string& source;
|
||||
__int32 index;
|
||||
uint32_t index;
|
||||
|
||||
LexerOutput out;
|
||||
const __int32 len;
|
||||
const uint32_t len;
|
||||
|
||||
// Trackers for where the Lexer is within the user version of source //
|
||||
unsigned short column;
|
||||
@@ -32,7 +32,7 @@ namespace LXC::Lexer
|
||||
};
|
||||
|
||||
// Constructor to pass arguments through to the struct //
|
||||
LexerError(Reason _reason, __int32 errorIndex, std::string _info = "")
|
||||
LexerError(Reason _reason, uint32_t errorIndex, std::string _info = "")
|
||||
: reason(_reason), index(errorIndex), info(_info)
|
||||
{}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace LXC::Lexer
|
||||
|
||||
// Error information //
|
||||
const Reason reason;
|
||||
const __int32 index;
|
||||
const uint32_t index;
|
||||
const std::string info;
|
||||
};
|
||||
|
||||
|
||||
@@ -83,11 +83,20 @@ namespace LXC::Lexer
|
||||
};
|
||||
|
||||
// Util function calculating wether a token is of a given class //
|
||||
template<TokenClass::ClassMask mask> static constexpr bool IsTypeClass(TokenType type) { return type & mask; }
|
||||
template<TokenClass::ClassMask mask> static constexpr bool IsTypeClass(Token token) { return token.type & mask; }
|
||||
template<TokenClass::ClassMask mask> static constexpr bool IsTypeClass(TokenType type)
|
||||
{
|
||||
using T = std::underlying_type_t<TokenType>;
|
||||
return static_cast<T>(type) & static_cast<T>(mask);
|
||||
}
|
||||
|
||||
template<TokenClass::ClassMask mask> static constexpr bool IsTypeClass(Token token)
|
||||
{
|
||||
using T = std::underlying_type_t<TokenType>;
|
||||
return static_cast<T>(token.type) & static_cast<T>(mask);
|
||||
}
|
||||
|
||||
// Constructor to set the data of the token for more complex token types //
|
||||
Token(const LexerContext& ctx, unsigned __int32 start, unsigned short len, TokenType _type);
|
||||
Token(const LexerContext& ctx, uint32_t start, unsigned short len, TokenType _type);
|
||||
|
||||
// Deconstructor to clean up the allocated memory //
|
||||
~Token();
|
||||
@@ -105,7 +114,7 @@ namespace LXC::Lexer
|
||||
const unsigned short length;
|
||||
|
||||
// Start index of the token //
|
||||
const unsigned __int32 index;
|
||||
const uint32_t index;
|
||||
|
||||
private:
|
||||
// The data of the token //
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace LXC::Internal
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
static constexpr bool IsWhitespace(const char c)
|
||||
bool IsWhitespace(const char c)
|
||||
{
|
||||
return c == ' ' || c == '\t' || c == '\n' || c == '\r';
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace LXC::Internal
|
||||
namespace LXC::Lexer
|
||||
{
|
||||
LexerContext::LexerContext(const std::string& _source) :
|
||||
source(_source), index(0), out{}, len((__int32)_source.length()), column(0), line(0)
|
||||
source(_source), index(0), out{}, len((uint32_t)_source.length()), column(0), line(0)
|
||||
{}
|
||||
|
||||
Util::ReturnVal<LexerOutput, LexerError> TokenizeFile(const std::string& fileContents)
|
||||
@@ -86,7 +86,7 @@ namespace LXC::Lexer
|
||||
|
||||
bool inComment = false;
|
||||
|
||||
unsigned __int32 sectionStart = 0;
|
||||
uint32_t sectionStart = 0;
|
||||
|
||||
} trackers;
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace LXC::Lexer
|
||||
|
||||
// Creates the token (if at the end of the string literal) //
|
||||
if (!trackers.inStrLiteral)
|
||||
ctx.out.emplace_back(ctx, trackers.sectionStart + 1, (USHORT)(ctx.index - trackers.sectionStart - 1), Token::StringLiteral);
|
||||
ctx.out.emplace_back(ctx, trackers.sectionStart + 1, (unsigned short)(ctx.index - trackers.sectionStart - 1), Token::StringLiteral);
|
||||
|
||||
} else if (trackers.inStrLiteral) {}
|
||||
|
||||
@@ -125,9 +125,7 @@ namespace LXC::Lexer
|
||||
// Checks for the end of the number literal to create the token //
|
||||
if (!Internal::IsNumeric(next)) _UNLIKELY
|
||||
{
|
||||
|
||||
|
||||
ctx.out.emplace_back(ctx, trackers.sectionStart, (USHORT)(ctx.index - trackers.sectionStart + 1), Token::NumLiteral);
|
||||
ctx.out.emplace_back(ctx, trackers.sectionStart, (unsigned short)(ctx.index - trackers.sectionStart + 1), Token::NumLiteral);
|
||||
trackers.inNumLiteral = false;
|
||||
}
|
||||
}
|
||||
@@ -147,7 +145,7 @@ namespace LXC::Lexer
|
||||
auto it = Internal::keywords.find(fullWord);
|
||||
Token::TokenType tType = (it != Internal::keywords.end()) ? it->second : Token::Identifier;
|
||||
|
||||
ctx.out.emplace_back(ctx, trackers.sectionStart, (USHORT)(ctx.index - trackers.sectionStart + 1), tType);
|
||||
ctx.out.emplace_back(ctx, trackers.sectionStart, (unsigned short)(ctx.index - trackers.sectionStart + 1), tType);
|
||||
trackers.inIdentifier = false;
|
||||
}
|
||||
}
|
||||
@@ -168,7 +166,7 @@ namespace LXC::Lexer
|
||||
std::string_view fullSymbol(ctx.source.data() + trackers.sectionStart, ctx.index - trackers.sectionStart + 1);
|
||||
auto it = Internal::symbolAndOpMap.find(fullSymbol);
|
||||
if (it != Internal::symbolAndOpMap.end())
|
||||
ctx.out.emplace_back(ctx, trackers.sectionStart, (USHORT)(ctx.index - trackers.sectionStart + 1), it->second);
|
||||
ctx.out.emplace_back(ctx, trackers.sectionStart, (unsigned short)(ctx.index - trackers.sectionStart + 1), it->second);
|
||||
|
||||
else
|
||||
return Util::FunctionFail<LexerError>(LexerError::UnknownSymbolOrOperand, trackers.sectionStart, std::string(fullSymbol));
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace LXC::Lexer
|
||||
{
|
||||
// Constructor to assign the members of the token class //
|
||||
Token::Token(const LexerContext& ctx, unsigned __int32 start, unsigned short len, TokenType _type) :
|
||||
Token::Token(const LexerContext& ctx, const uint32_t start, unsigned short len, TokenType _type) :
|
||||
type(_type), length(len), index(start), contents(nullptr)
|
||||
{
|
||||
// Only user defined class tokens need to store c-string //
|
||||
|
||||
Reference in New Issue
Block a user