func (p *Parser) parseTernaryOperation(lhs ast.Expression) ast.Expression { var truthy ast.Expression if p.peek().Typ == token.TernaryOperator2 { truthy = lhs } else { truthy = p.parseNextExpression() } p.expect(token.TernaryOperator2) falsy := p.parseNextExpression() return &ast.TernaryExpression{ Condition: lhs, True: truthy, False: falsy, Type: truthy.EvaluatesTo().Union(falsy.EvaluatesTo()), } }
func (p *Parser) parseTernaryOperation(lhs ast.Expression) ast.Expression { var truthy ast.Expression if p.peek().typ == token.TernaryOperator2 { truthy = lhs } else { truthy = p.parseNextExpression() } p.expect(token.TernaryOperator2) falsy := p.parseNextExpression() return &ast.OperatorExpression{ Operand1: lhs, Operand2: truthy, Operand3: falsy, Type: truthy.EvaluatesTo() | falsy.EvaluatesTo(), Operator: "?:", } }