Ejemplo n.º 1
0
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()),
	}
}
Ejemplo n.º 2
0
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: "?:",
	}
}