Implements complex tables
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-12 15:19:28 +02:00
parent ba4fe888fa
commit c022c91777
21 changed files with 272 additions and 50 deletions

View File

@@ -24,6 +24,7 @@ enum class ParsedExpressionKind{
FunctionCall,
Indexer,
NumericalTable,
Table,
};
class ParsedExpression {

View File

@@ -0,0 +1,31 @@
#ifndef PORYGONLANG_PARSEDTABLEEXPRESSION_HPP
#define PORYGONLANG_PARSEDTABLEEXPRESSION_HPP
#include "ParsedExpression.hpp"
#include "../ParsedStatements/ParsedStatement.hpp"
class ParsedTableExpression : public ParsedExpression{
ParsedBlockStatement* _block;
public:
ParsedTableExpression(ParsedBlockStatement* block, unsigned int start, unsigned int length)
: ParsedExpression(start, length){
_block = block;
}
~ParsedTableExpression() final{
delete _block;
}
ParsedBlockStatement* GetBlock(){
return _block;
}
ParsedExpressionKind GetKind() final{
return ParsedExpressionKind::Table;
}
};
#include "ParsedExpression.hpp"
#endif //PORYGONLANG_PARSEDTABLEEXPRESSION_HPP

View File

@@ -5,6 +5,7 @@
#include "UnaryOperatorKind.hpp"
#include "BinaryOperatorKind.hpp"
#include "TypedVariableIdentifier.hpp"
#include "ParsedExpressions/ParsedTableExpression.hpp"
ParsedScriptStatement* Parser::Parse() {
@@ -372,6 +373,7 @@ ParsedExpression* Parser::ParseTableExpression(IToken* current){
auto start = current->GetStartPosition();
return new ParsedNumericalTableExpression({}, start, this -> Peek()->GetEndPosition() - start);
}
auto start = current->GetStartPosition();
auto firstItem = this->ParseStatement(this -> Next());
// If the first item is an expression, and is followed by a comma, we're dealing with a simple {1, 2, 3} kind of array
if (firstItem->GetKind() == ParsedStatementKind::Expression &&
@@ -389,7 +391,6 @@ ParsedExpression* Parser::ParseTableExpression(IToken* current){
hasErrors = true;
}
}
auto start = current->GetStartPosition();
if (hasErrors){
return new BadExpression(start, n->GetEndPosition() - start);
}
@@ -400,7 +401,8 @@ ParsedExpression* Parser::ParseTableExpression(IToken* current){
auto block = (ParsedBlockStatement*)this -> ParseBlock({TokenKind ::CloseCurlyBracket});
auto statements = block->GetStatements();
statements->insert(statements->begin(), firstItem);
throw "not implemented TODO";
auto closeToken = this -> PeekAt(-1);
return new ParsedTableExpression(block, start, closeToken->GetEndPosition() - start);
}
}