Minor cleanup of Parser
This commit is contained in:
parent
9241273e7c
commit
ec2419bc7d
|
@ -38,7 +38,7 @@ ParsedStatement* Parser::ParseStatement(IToken* current){
|
|||
case TokenKind ::LocalKeyword: return this -> ParseAssignment(current);
|
||||
case TokenKind ::FunctionKeyword: return this -> ParseFunctionDeclaration(current);
|
||||
case TokenKind ::ReturnKeyword: return this->ParseReturnStatement(current);
|
||||
case TokenKind ::IfKeyword: return this -> ParseIfStatement(current, false);
|
||||
case TokenKind ::IfKeyword: return this -> ParseIfStatement(current);
|
||||
default: break;
|
||||
}
|
||||
if (this->Peek()->GetKind() == TokenKind::AssignmentToken){
|
||||
|
@ -87,7 +87,7 @@ ParsedStatement *Parser::ParseBlock(const vector<TokenKind>& endTokens) {
|
|||
}
|
||||
statements.push_back(this -> ParseStatement(next));
|
||||
}
|
||||
if (statements.size() == 0){
|
||||
if (statements.empty()){
|
||||
return new ParsedBlockStatement(statements,start);
|
||||
}
|
||||
return new ParsedBlockStatement(statements);
|
||||
|
@ -162,7 +162,7 @@ ParsedStatement* Parser::ParseReturnStatement(IToken* current){
|
|||
return new ParsedReturnStatement(expression, start, expression->GetEndPosition() - start);
|
||||
}
|
||||
|
||||
ParsedStatement* Parser::ParseIfStatement(IToken* current, bool isElseIf){
|
||||
ParsedStatement* Parser::ParseIfStatement(IToken* current){
|
||||
auto condition = this->ParseExpression(this->Next());
|
||||
auto next = this -> Next();
|
||||
if (next->GetKind() != TokenKind::ThenKeyword){
|
||||
|
@ -173,7 +173,7 @@ ParsedStatement* Parser::ParseIfStatement(IToken* current, bool isElseIf){
|
|||
auto closeToken = this->PeekAt(-1);
|
||||
auto start = current->GetStartPosition();
|
||||
if (closeToken->GetKind() == TokenKind::ElseIfKeyword){
|
||||
auto elseIfStatement = this -> ParseIfStatement(closeToken, true);
|
||||
auto elseIfStatement = this -> ParseIfStatement(closeToken);
|
||||
return new ParsedConditionalStatement(condition, block, elseIfStatement, start, elseIfStatement->GetEndPosition() - start);
|
||||
} else if (closeToken->GetKind() == TokenKind::ElseKeyword){
|
||||
auto elseStatement = this -> ParseBlock({TokenKind ::EndKeyword});
|
||||
|
@ -263,7 +263,6 @@ OperatorPrecedence GetBinaryPrecedence(TokenKind kind){
|
|||
case TokenKind ::Greater: return OperatorPrecedence ::Equality;
|
||||
case TokenKind ::GreaterEquals: return OperatorPrecedence ::Equality;
|
||||
|
||||
|
||||
// Logical
|
||||
case TokenKind::AndKeyword: return OperatorPrecedence ::LogicalAnd;
|
||||
case TokenKind::OrKeyword: return OperatorPrecedence ::LogicalOr;
|
||||
|
|
|
@ -30,7 +30,7 @@ class Parser {
|
|||
ParsedStatement *ParseBlock(const vector<TokenKind>& endTokens);
|
||||
ParsedStatement* ParseFunctionDeclaration(IToken* current);
|
||||
ParsedStatement *ParseReturnStatement(IToken *current);
|
||||
ParsedStatement *ParseIfStatement(IToken *current, bool isElseIf);
|
||||
ParsedStatement *ParseIfStatement(IToken *current);
|
||||
|
||||
ParsedExpression* ParseExpression(IToken* current);
|
||||
ParsedExpression* ParseBinaryExpression(IToken* current, OperatorPrecedence parentPrecedence);
|
||||
|
|
Loading…
Reference in New Issue