terraform/config/lang/ast/literal.go

34 lines
602 B
Go
Raw Normal View History

2015-01-11 21:38:45 +01:00
package ast
import (
"fmt"
)
2015-01-11 21:38:45 +01:00
// LiteralNode represents a single literal value, such as "foo" or
// 42 or 3.14159. Based on the Type, the Value can be safely cast.
type LiteralNode struct {
Value interface{}
2015-01-15 05:13:35 +01:00
Typex Type
2015-01-12 09:28:47 +01:00
Posx Pos
2015-01-11 21:38:45 +01:00
}
func (n *LiteralNode) Accept(v Visitor) Node {
return v(n)
2015-01-12 00:26:54 +01:00
}
2015-01-12 09:28:47 +01:00
func (n *LiteralNode) Pos() Pos {
return n.Posx
}
func (n *LiteralNode) GoString() string {
return fmt.Sprintf("*%#v", *n)
}
2015-01-13 17:50:28 +01:00
func (n *LiteralNode) String() string {
2015-01-15 07:01:42 +01:00
return fmt.Sprintf("Literal(%s, %v)", n.Typex, n.Value)
2015-01-13 17:50:28 +01:00
}
2015-01-15 05:13:35 +01:00
func (n *LiteralNode) Type(Scope) (Type, error) {
return n.Typex, nil
}