Updated function signatures
This commit is contained in:
@@ -15,17 +15,22 @@ namespace LXC::Internal
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
bool IsWhitespace(const char c)
|
||||
static constexpr bool IsWhitespace(const char c)
|
||||
{
|
||||
return c == ' ' || c == '\t' || c == '\n' || c == '\r';
|
||||
}
|
||||
|
||||
static constexpr bool IsSymbolOrOperator(const char c)
|
||||
static constexpr bool IsOperator(const char c)
|
||||
{
|
||||
return
|
||||
c == '+' || c == '-' ||
|
||||
c == '*' || c == '/' ||
|
||||
c == '%' || c == '=' ||
|
||||
c == '%' || c == '=';
|
||||
}
|
||||
|
||||
static constexpr bool IsSymbol(const char c)
|
||||
{
|
||||
return
|
||||
c == ',' || c == '[' ||
|
||||
c == ']' || c == '{' ||
|
||||
c == '}' || c == '(' ||
|
||||
@@ -33,7 +38,7 @@ namespace LXC::Internal
|
||||
c == '>';
|
||||
}
|
||||
|
||||
static const std::unordered_map<std::string_view, Lexer::Token::TokenType> symbolAndOpMap =
|
||||
static const std::unordered_map<std::string_view, Lexer::Token::TokenType> operatorMap =
|
||||
{
|
||||
{ "+", Lexer::Token::Add },
|
||||
{ "-", Lexer::Token::Sub },
|
||||
@@ -43,20 +48,24 @@ namespace LXC::Internal
|
||||
|
||||
{ "==", Lexer::Token::Eql },
|
||||
|
||||
{ "=", Lexer::Token::Assign },
|
||||
{ ",", Lexer::Token::Comma },
|
||||
{ "=", Lexer::Token::Assign }
|
||||
};
|
||||
|
||||
{ "[", Lexer::Token::CloseBracket },
|
||||
{ "]", Lexer::Token::OpenBracket },
|
||||
static const std::unordered_map<char, Lexer::Token::TokenType> symbolMap =
|
||||
{
|
||||
{ ',', Lexer::Token::Comma },
|
||||
|
||||
{ "}", Lexer::Token::CloseBrace },
|
||||
{ "{", Lexer::Token::OpenBrace },
|
||||
{ '[', Lexer::Token::CloseBracket },
|
||||
{ ']', Lexer::Token::OpenBracket },
|
||||
|
||||
{ ")", Lexer::Token::CloseParen },
|
||||
{ "(", Lexer::Token::OpenParen },
|
||||
{ '}', Lexer::Token::CloseBrace },
|
||||
{ '{', Lexer::Token::OpenBrace },
|
||||
|
||||
{ ">", Lexer::Token::CloseCrocodile },
|
||||
{ "<", Lexer::Token::OpenCrocodile }
|
||||
{ ')', Lexer::Token::CloseParen },
|
||||
{ '(', Lexer::Token::OpenParen },
|
||||
|
||||
{ '>', Lexer::Token::CloseCrocodile },
|
||||
{ '<', Lexer::Token::OpenCrocodile }
|
||||
};
|
||||
|
||||
static const std::unordered_map<std::string_view, Lexer::Token::TokenType> keywords =
|
||||
@@ -87,7 +96,7 @@ namespace LXC::Lexer
|
||||
bool inStrLiteral = false;
|
||||
bool inIdentifier = false;
|
||||
bool inNumLiteral = false;
|
||||
bool inSymbolOrOp = false;
|
||||
bool inOperator = false;
|
||||
|
||||
bool inComment = false;
|
||||
|
||||
@@ -155,22 +164,22 @@ namespace LXC::Lexer
|
||||
}
|
||||
}
|
||||
|
||||
// === Symbols/Operators === //
|
||||
else if (Internal::IsSymbolOrOperator(current))
|
||||
// === Operators === //
|
||||
else if (Internal::IsOperator(current))
|
||||
{
|
||||
// Updates trackers //
|
||||
trackers.sectionStart = trackers.inSymbolOrOp ? trackers.sectionStart : ctx.index;
|
||||
trackers.inSymbolOrOp = true;
|
||||
trackers.sectionStart = trackers.inOperator ? trackers.sectionStart : ctx.index;
|
||||
trackers.inOperator = true;
|
||||
|
||||
// Checks for the end of the symbol or operator //
|
||||
if (!Internal::IsSymbolOrOperator(next)) _LIKELY
|
||||
if (!Internal::IsOperator(next)) _LIKELY
|
||||
{
|
||||
trackers.inSymbolOrOp = false;
|
||||
trackers.inOperator = false;
|
||||
|
||||
// Finds the operator/symbol if it can //
|
||||
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())
|
||||
auto it = Internal::operatorMap.find(fullSymbol);
|
||||
if (it != Internal::operatorMap.end())
|
||||
ctx.out.emplace_back(ctx, trackers.sectionStart, (unsigned short)(ctx.index - trackers.sectionStart + 1), it->second);
|
||||
|
||||
else
|
||||
@@ -178,6 +187,12 @@ namespace LXC::Lexer
|
||||
}
|
||||
}
|
||||
|
||||
// === Symbols === //
|
||||
else if (Internal::IsSymbol(current))
|
||||
{
|
||||
ctx.out.emplace_back(ctx, ctx.index, 1, Internal::symbolMap.at(current));
|
||||
}
|
||||
|
||||
// === Whitespace === //
|
||||
else if (Internal::IsWhitespace(current)) _LIKELY {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user