7 // Node is the interface that all AST nodes must implement.
9 // Accept is called to dispatch to the visitors. It must return the
10 // resulting Node (which might be different in an AST transform).
13 // Pos returns the position of this node in some source.
16 // Type returns the type of this node for the given context.
17 Type(Scope) (Type, error)
20 // Pos is the starting position of an AST node
22 Column, Line int // Column/Line number, starting at 1
23 Filename string // Optional source filename, if known
26 func (p Pos) String() string {
28 return fmt.Sprintf("%d:%d", p.Line, p.Column)
30 return fmt.Sprintf("%s:%d:%d", p.Filename, p.Line, p.Column)
34 // InitPos is an initiaial position value. This should be used as
35 // the starting position (presets the column and line to 1).
36 var InitPos = Pos{Column: 1, Line: 1}
38 // Visitors are just implementations of this function.
40 // The function must return the Node to replace this node with. "nil" is
41 // _not_ a valid return value. If there is no replacement, the original node
42 // should be returned. We build this replacement directly into the visitor
43 // pattern since AST transformations are a common and useful tool and
44 // building it into the AST itself makes it required for future Node
45 // implementations and very easy to do.
47 // Note that this isn't a true implementation of the visitor pattern, which
48 // generally requires proper type dispatch on the function. However,
49 // implementing this basic visitor pattern style is still very useful even
50 // if you have to type switch.
51 type Visitor func(Node) Node
53 //go:generate stringer -type=Type
55 // Type is the type of any value.
60 TypeAny Type = 1 << iota
68 // This is a special type used by Terraform to mark "unknown" values.
69 // It is impossible for this type to be introduced into your HIL programs
70 // unless you explicitly set a variable to this value. In that case,
71 // any operation including the variable will return "TypeUnknown" as the
76 func (t Type) Printable() string {