Implements indexing, currently can only be used with strings
This commit is contained in:
@@ -146,10 +146,11 @@ ParsedExpression* Parser::ParseExpression(IToken* current){
|
||||
if (peekKind == TokenKind::OpenParenthesis){
|
||||
expression = this->ParseFunctionCallExpression(expression);
|
||||
} else if (peekKind == TokenKind::OpenSquareBracket){
|
||||
//TODO: index expression
|
||||
expression = this->ParseIndexExpression(expression);
|
||||
} else {
|
||||
//TODO: index period expression
|
||||
}
|
||||
peekKind = this->Peek()->GetKind();
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
@@ -283,7 +284,17 @@ ParsedExpression *Parser::ParseFunctionCallExpression(ParsedExpression* function
|
||||
return new FunctionCallExpression(functionExpression, parameters, start, peeked->GetEndPosition() - start);
|
||||
}
|
||||
|
||||
|
||||
ParsedExpression* Parser::ParseIndexExpression(ParsedExpression* indexingExpression){
|
||||
this->Next(); // consume '[' token
|
||||
auto indexExpression = this -> ParseExpression(this -> Next());
|
||||
auto closeBracket = this->Next();
|
||||
if (closeBracket->GetKind() != TokenKind::CloseSquareBracket){
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, closeBracket->GetStartPosition(), closeBracket->GetLength());
|
||||
return new BadExpression(closeBracket->GetStartPosition(), closeBracket->GetLength());
|
||||
}
|
||||
auto start = indexingExpression->GetStartPosition();
|
||||
return new IndexExpression(indexingExpression, indexExpression, start, closeBracket->GetEndPosition() - start);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user