aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/parsing/Parser.cpp
diff options
context:
space:
mode:
authorLu Guanqun <guanqun.lu@gmail.com>2015-12-23 00:47:55 +0800
committerLu Guanqun <guanqun.lu@gmail.com>2016-01-23 01:14:00 +0800
commit7eefa838a3384d3a8a81d73d7e544afa7f3193fc (patch)
treeb43a24fd88c7864357bb3efb7b9b3534654887d0 /libsolidity/parsing/Parser.cpp
parent4563d4bd3c3525fd2bf26823567f3c99018482e1 (diff)
downloaddexon-solidity-7eefa838a3384d3a8a81d73d7e544afa7f3193fc.tar.gz
dexon-solidity-7eefa838a3384d3a8a81d73d7e544afa7f3193fc.tar.zst
dexon-solidity-7eefa838a3384d3a8a81d73d7e544afa7f3193fc.zip
[cond-expr] parse _ ? _ : _ into conditional AST node
Diffstat (limited to 'libsolidity/parsing/Parser.cpp')
-rw-r--r--libsolidity/parsing/Parser.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index 4ac3381c..cc06eb87 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -932,13 +932,26 @@ ASTPointer<Expression> Parser::parseExpression(
)
{
ASTPointer<Expression> expression = parseBinaryExpression(4, _lookAheadIndexAccessStructure);
- if (!Token::isAssignmentOp(m_scanner->currentToken()))
+ 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;
- Token::Value assignmentOperator = expectAssignmentOperator();
- ASTPointer<Expression> rightHandSide = parseExpression();
- ASTNodeFactory nodeFactory(*this, expression);
- nodeFactory.setEndPositionFromNode(rightHandSide);
- return nodeFactory.createNode<Assignment>(expression, assignmentOperator, rightHandSide);
}
ASTPointer<Expression> Parser::parseBinaryExpression(