Added basic vector<len, Ty>

This commit is contained in:
Pasha Bibko
2025-08-12 23:56:12 +01:00
parent 3d1865de59
commit 313736addd
2 changed files with 25 additions and 30 deletions

View File

@@ -210,7 +210,7 @@ namespace PashaBibko::LXC::Parser
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
// Checks for a default value for the variable //
const Lexer::Token* varAssign = ctx.Peek();
const Lexer::Token* varAssign = ctx.Advance();
if (varAssign == nullptr)
return Internal::CreateNode<AST::VarDeclaration>(varNameStr);
@@ -254,36 +254,31 @@ namespace PashaBibko::LXC::Parser
if (paramsStart == nullptr )
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
// Parses the parameters of the function //
if (paramsStart->type == Lexer::Token::Identifier && paramsStart->Str() == "void")
{ /* No parameters/arguments for the function */}
// Loops over the parameters/arguments of the function declaration //
else
while (ctx.At()->type != Lexer::Token::CloseParen)
{
while (ctx.At()->type != Lexer::Token::CloseParen)
{
// Checks for parameter pattern: identifier, identifier //
if (!ctx.Expect(std::array{ Lexer::Token::Identifier, Lexer::Token::Colon, Lexer::Token::Identifier }))
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
const Lexer::Token* paramType = ctx.At();
const Lexer::Token* paramName = ctx.Advance(2); // Skips over seperating colon
currentFunction.funcParams.emplace_back(paramType->Str(), paramName->Str());
// Expects a comma or close bracket for the next token //
const Lexer::Token* end = ctx.Advance();
if (end == nullptr)
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
if (end->type == Lexer::Token::Comma || end->type == Lexer::Token::CloseParen)
continue;
// Checks for parameter pattern: identifier, identifier //
if (!ctx.Expect(std::array{ Lexer::Token::Identifier, Lexer::Token::Colon, Lexer::Token::Identifier }))
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
}
const Lexer::Token* paramType = ctx.At();
const Lexer::Token* paramName = ctx.Advance(2); // Skips over seperating colon
currentFunction.funcParams.emplace_back(paramType->Str(), paramName->Str());
// Expects a comma or close bracket for the next token //
const Lexer::Token* end = ctx.Advance();
if (end == nullptr)
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
if (end->type == Lexer::Token::Comma || end->type == Lexer::Token::CloseParen)
continue;
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
}
// Adcances over close paren and open brace //
ctx.Advance(2);
// Parses the function body //
const Lexer::Token* current = ctx.At();
while (current != nullptr)
@@ -301,9 +296,7 @@ namespace PashaBibko::LXC::Parser
return Util::FunctionFail<ParserError>(node.Error()); // Fowards the error
currentFunction.contents.emplace_back(std::move(node.Result()));
// Advances to the next token //
current = ctx.Advance();
current = ctx.At();
}
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error