Added basic vector<len, Ty>
This commit is contained in:
@@ -73,5 +73,7 @@ int main(int argc, char** argv)
|
|||||||
Util::Log("Function AST", functionsAST.Result());
|
Util::Log("Function AST", functionsAST.Result());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
functionsAST.Result().~vector();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ namespace PashaBibko::LXC::Parser
|
|||||||
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
||||||
|
|
||||||
// Checks for a default value for the variable //
|
// Checks for a default value for the variable //
|
||||||
const Lexer::Token* varAssign = ctx.Peek();
|
const Lexer::Token* varAssign = ctx.Advance();
|
||||||
if (varAssign == nullptr)
|
if (varAssign == nullptr)
|
||||||
return Internal::CreateNode<AST::VarDeclaration>(varNameStr);
|
return Internal::CreateNode<AST::VarDeclaration>(varNameStr);
|
||||||
|
|
||||||
@@ -254,36 +254,31 @@ namespace PashaBibko::LXC::Parser
|
|||||||
if (paramsStart == nullptr )
|
if (paramsStart == nullptr )
|
||||||
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
||||||
|
|
||||||
// Parses the parameters of the function //
|
while (ctx.At()->type != Lexer::Token::CloseParen)
|
||||||
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)
|
// Checks for parameter pattern: identifier, identifier //
|
||||||
{
|
if (!ctx.Expect(std::array{ Lexer::Token::Identifier, Lexer::Token::Colon, Lexer::Token::Identifier }))
|
||||||
// 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
|
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 //
|
// Parses the function body //
|
||||||
const Lexer::Token* current = ctx.At();
|
const Lexer::Token* current = ctx.At();
|
||||||
while (current != nullptr)
|
while (current != nullptr)
|
||||||
@@ -301,9 +296,7 @@ namespace PashaBibko::LXC::Parser
|
|||||||
return Util::FunctionFail<ParserError>(node.Error()); // Fowards the error
|
return Util::FunctionFail<ParserError>(node.Error()); // Fowards the error
|
||||||
|
|
||||||
currentFunction.contents.emplace_back(std::move(node.Result()));
|
currentFunction.contents.emplace_back(std::move(node.Result()));
|
||||||
|
current = ctx.At();
|
||||||
// Advances to the next token //
|
|
||||||
current = ctx.Advance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
return Util::FunctionFail<ParserError>(); // <- TODO: Make an actual error
|
||||||
|
|||||||
Reference in New Issue
Block a user