]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/walk.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / hcl2 / hcl / hclsyntax / walk.go
1 package hclsyntax
2
3 import (
4 "github.com/hashicorp/hcl2/hcl"
5 )
6
7 // VisitFunc is the callback signature for VisitAll.
8 type VisitFunc func(node Node) hcl.Diagnostics
9
10 // VisitAll is a basic way to traverse the AST beginning with a particular
11 // node. The given function will be called once for each AST node in
12 // depth-first order, but no context is provided about the shape of the tree.
13 //
14 // The VisitFunc may return diagnostics, in which case they will be accumulated
15 // and returned as a single set.
16 func VisitAll(node Node, f VisitFunc) hcl.Diagnostics {
17 diags := f(node)
18 node.walkChildNodes(func(node Node) {
19 diags = append(diags, VisitAll(node, f)...)
20 })
21 return diags
22 }
23
24 // Walker is an interface used with Walk.
25 type Walker interface {
26 Enter(node Node) hcl.Diagnostics
27 Exit(node Node) hcl.Diagnostics
28 }
29
30 // Walk is a more complex way to traverse the AST starting with a particular
31 // node, which provides information about the tree structure via separate
32 // Enter and Exit functions.
33 func Walk(node Node, w Walker) hcl.Diagnostics {
34 diags := w.Enter(node)
35 node.walkChildNodes(func(node Node) {
36 diags = append(diags, Walk(node, w)...)
37 })
38 moreDiags := w.Exit(node)
39 diags = append(diags, moreDiags...)
40 return diags
41 }