github.com/leeprovoost/terraform@v0.6.10-0.20160119085442-96f3f76118e7/config/lang/ast/unary_arithmetic.go (about)

     1  package ast
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // UnaryArithmetic represents a node where the result is arithmetic of
     8  // one operands
     9  type UnaryArithmetic struct {
    10  	Op   ArithmeticOp
    11  	Expr Node
    12  	Posx Pos
    13  }
    14  
    15  func (n *UnaryArithmetic) Accept(v Visitor) Node {
    16  	n.Expr = n.Expr.Accept(v)
    17  
    18  	return v(n)
    19  }
    20  
    21  func (n *UnaryArithmetic) Pos() Pos {
    22  	return n.Posx
    23  }
    24  
    25  func (n *UnaryArithmetic) GoString() string {
    26  	return fmt.Sprintf("*%#v", *n)
    27  }
    28  
    29  func (n *UnaryArithmetic) String() string {
    30  	var sign rune
    31  	switch n.Op {
    32  	case ArithmeticOpAdd:
    33  		sign = '+'
    34  	case ArithmeticOpSub:
    35  		sign = '-'
    36  	}
    37  	return fmt.Sprintf("%c%s", sign, n.Expr)
    38  }
    39  
    40  func (n *UnaryArithmetic) Type(Scope) (Type, error) {
    41  	return TypeInt, nil
    42  }