mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[cond-expr] parse _ ? _ : _ into conditional AST node
This commit is contained in:
parent
4563d4bd3c
commit
7eefa838a3
@ -932,13 +932,26 @@ ASTPointer<Expression> Parser::parseExpression(
|
||||
)
|
||||
{
|
||||
ASTPointer<Expression> expression = parseBinaryExpression(4, _lookAheadIndexAccessStructure);
|
||||
if (!Token::isAssignmentOp(m_scanner->currentToken()))
|
||||
return expression;
|
||||
if (Token::isAssignmentOp(m_scanner->currentToken()))
|
||||
{
|
||||
Token::Value assignmentOperator = expectAssignmentOperator();
|
||||
ASTPointer<Expression> rightHandSide = parseExpression();
|
||||
ASTNodeFactory nodeFactory(*this, expression);
|
||||
nodeFactory.setEndPositionFromNode(rightHandSide);
|
||||
return nodeFactory.createNode<Assignment>(expression, assignmentOperator, rightHandSide);
|
||||
}
|
||||
else if (m_scanner->currentToken() == Token::Value::Conditional)
|
||||
{
|
||||
m_scanner->next();
|
||||
ASTPointer<Expression> trueExpression = parseExpression();
|
||||
expectToken(Token::Colon);
|
||||
ASTPointer<Expression> falseExpression = parseExpression();
|
||||
ASTNodeFactory nodeFactory(*this, expression);
|
||||
nodeFactory.setEndPositionFromNode(falseExpression); // TODO:
|
||||
return nodeFactory.createNode<Conditional>(expression, trueExpression, falseExpression);
|
||||
}
|
||||
else
|
||||
return expression;
|
||||
}
|
||||
|
||||
ASTPointer<Expression> Parser::parseBinaryExpression(
|
||||
|
Loading…
Reference in New Issue
Block a user