Removed raw-enums
This commit is contained in:
@@ -38,7 +38,7 @@ namespace PashaBibko::LXC::Parser
|
||||
}
|
||||
|
||||
// Checks if the tokens are the correct types //
|
||||
inline bool Expect(const std::span<const Lexer::Token::TokenType>& tokens) const
|
||||
inline bool Expect(const std::span<const Lexer::TokenType>& tokens) const
|
||||
{
|
||||
for (int i = 0; i < tokens.size(); i++)
|
||||
{
|
||||
|
||||
@@ -34,12 +34,12 @@ namespace PashaBibko::LXC::Parser
|
||||
switch (current->type)
|
||||
{
|
||||
// Fowards to the ParseIdentifier and returns the result/error //
|
||||
case Lexer::Token::Identifier:
|
||||
case Lexer::TokenType::Identifier:
|
||||
ctx.Advance();
|
||||
return Internal::CreateNodeV<AST::VarAccess>(current->Str());
|
||||
|
||||
// Returns an integer literal node //
|
||||
case Lexer::Token::NumLiteral:
|
||||
case Lexer::TokenType::NumLiteral:
|
||||
ctx.Advance();
|
||||
return Internal::CreateNodeV<AST::IntLiteral>(current->Str());
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace PashaBibko::LXC::Parser
|
||||
static Util::ReturnVal<AST::NodeValuePtr, ParserError> ParseFunctionCall(ParserContext& ctx)
|
||||
{
|
||||
// Checks if the upcoming pattern matches a function signature: [Identifier(function name), OpenBracket(Start of params)] //
|
||||
if (ctx.Expect(std::array{ Lexer::Token::Identifier, Lexer::Token::OpenParen }))
|
||||
if (ctx.Expect(std::array{ Lexer::TokenType::Identifier, Lexer::TokenType::OpenParen }))
|
||||
{
|
||||
// Captures the function name and advances over it and the start paren //
|
||||
const Lexer::Token* functionNameToken = ctx.At();
|
||||
@@ -64,11 +64,11 @@ namespace PashaBibko::LXC::Parser
|
||||
while (current != nullptr)
|
||||
{
|
||||
// End of the function call //
|
||||
if (current->type == Lexer::Token::CloseParen)
|
||||
if (current->type == Lexer::TokenType::CloseParen)
|
||||
return Internal::CreateNodeV<AST::FunctionCall>(functionNameToken->Str(), arguments);
|
||||
|
||||
// Checks for seperating comma //
|
||||
if (!ctx.Expect(std::array{ Lexer::Token::Comma }))
|
||||
if (!ctx.Expect(std::array{ Lexer::TokenType::Comma }))
|
||||
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
||||
ctx.Advance();
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace PashaBibko::LXC::Parser
|
||||
if (at == nullptr)
|
||||
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
||||
|
||||
if (at->type == Lexer::Token::Return)
|
||||
if (at->type == Lexer::TokenType::Return)
|
||||
{
|
||||
// Iterates over the return token and parses the value to be returned //
|
||||
ctx.Advance();
|
||||
@@ -139,7 +139,7 @@ namespace PashaBibko::LXC::Parser
|
||||
static Util::ReturnVal<AST::NodePtr, ParserError> ParseVarDeclaration(ParserContext& ctx)
|
||||
{
|
||||
// Checks for the pattern of a variable declaration //
|
||||
if (ctx.Expect(std::array{ Lexer::Token::Identifier, Lexer::Token::Colon }))
|
||||
if (ctx.Expect(std::array{ Lexer::TokenType::Identifier, Lexer::TokenType::Colon }))
|
||||
{
|
||||
// Can safely advance over the pattern (types are not checked/stored yet) //
|
||||
ctx.Advance(2);
|
||||
@@ -149,7 +149,7 @@ namespace PashaBibko::LXC::Parser
|
||||
if (varName == nullptr)
|
||||
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
||||
|
||||
if (varName->type != Lexer::Token::Identifier)
|
||||
if (varName->type != Lexer::TokenType::Identifier)
|
||||
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
||||
|
||||
// Checks for a default value for the variable //
|
||||
@@ -157,7 +157,7 @@ namespace PashaBibko::LXC::Parser
|
||||
if (varAssign == nullptr)
|
||||
return Internal::CreateNode<AST::VarDeclaration>(varNameStr);
|
||||
|
||||
if (varAssign->type != Lexer::Token::Assign)
|
||||
if (varAssign->type != Lexer::TokenType::Assign)
|
||||
return Internal::CreateNode<AST::VarDeclaration>(varNameStr);
|
||||
|
||||
// Creates a node with the default value of the variable //
|
||||
@@ -182,7 +182,7 @@ namespace PashaBibko::LXC::Parser
|
||||
Util::ReturnVal<FunctionAST, ParserError> ParseFunction(ParserContext& ctx)
|
||||
{
|
||||
// Checks for the sequence of: func<T> funcName( //
|
||||
if (!ctx.Expect(std::array{ Lexer::Token::FunctionDef, Lexer::Token::OpenCrocodile, Lexer::Token::Identifier, Lexer::Token::CloseCrocodile, Lexer::Token::Identifier, Lexer::Token::OpenParen }))
|
||||
if (!ctx.Expect(std::array{ Lexer::TokenType::FunctionDef, Lexer::TokenType::OpenCrocodile, Lexer::TokenType::Identifier, Lexer::TokenType::CloseCrocodile, Lexer::TokenType::Identifier, Lexer::TokenType::OpenParen }))
|
||||
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
||||
|
||||
// Assumes int for now so skips over func<T> //
|
||||
@@ -197,10 +197,10 @@ namespace PashaBibko::LXC::Parser
|
||||
if (paramsStart == nullptr )
|
||||
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
||||
|
||||
while (ctx.At()->type != Lexer::Token::CloseParen)
|
||||
while (ctx.At()->type != Lexer::TokenType::CloseParen)
|
||||
{
|
||||
// Checks for parameter pattern: identifier, identifier //
|
||||
if (!ctx.Expect(std::array{ Lexer::Token::Identifier, Lexer::Token::Colon, Lexer::Token::Identifier }))
|
||||
if (!ctx.Expect(std::array{ Lexer::TokenType::Identifier, Lexer::TokenType::Colon, Lexer::TokenType::Identifier }))
|
||||
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
||||
|
||||
const Lexer::Token* paramType = ctx.At();
|
||||
@@ -213,7 +213,7 @@ namespace PashaBibko::LXC::Parser
|
||||
if (end == nullptr)
|
||||
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
||||
|
||||
if (end->type == Lexer::Token::Comma || end->type == Lexer::Token::CloseParen)
|
||||
if (end->type == Lexer::TokenType::Comma || end->type == Lexer::TokenType::CloseParen)
|
||||
continue;
|
||||
|
||||
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
||||
@@ -226,7 +226,7 @@ namespace PashaBibko::LXC::Parser
|
||||
const Lexer::Token* current = ctx.At();
|
||||
while (current != nullptr)
|
||||
{
|
||||
if (current->type == Lexer::Token::CloseBrace)
|
||||
if (current->type == Lexer::TokenType::CloseBrace)
|
||||
{
|
||||
// Advances over closing brace before returning the function //
|
||||
ctx.Advance();
|
||||
@@ -260,7 +260,7 @@ namespace PashaBibko::LXC::Parser
|
||||
switch (current->type)
|
||||
{
|
||||
// Only functions are currently supported //
|
||||
case Lexer::Token::FunctionDef:
|
||||
case Lexer::TokenType::FunctionDef:
|
||||
{
|
||||
// Parses the function and add it to the vector if there are no errors //
|
||||
Util::ReturnVal func = ParseFunction(ctx);
|
||||
|
||||
Reference in New Issue
Block a user