]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - 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
index 3405d268a0c3cff867aff03aadac8c5735e91900..90f81c9c1c1333af6227b1e2f2ddd5276fd8b3e3 100644 (file)
@@ -15,9 +15,8 @@ type VisitFunc func(node Node) hcl.Diagnostics
 // and returned as a single set.
 func VisitAll(node Node, f VisitFunc) hcl.Diagnostics {
        diags := f(node)
-       node.walkChildNodes(func(node Node) Node {
+       node.walkChildNodes(func(node Node) {
                diags = append(diags, VisitAll(node, f)...)
-               return node
        })
        return diags
 }
@@ -33,45 +32,10 @@ type Walker interface {
 // Enter and Exit functions.
 func Walk(node Node, w Walker) hcl.Diagnostics {
        diags := w.Enter(node)
-       node.walkChildNodes(func(node Node) Node {
+       node.walkChildNodes(func(node Node) {
                diags = append(diags, Walk(node, w)...)
-               return node
        })
+       moreDiags := w.Exit(node)
+       diags = append(diags, moreDiags...)
        return diags
 }
-
-// Transformer is an interface used with Transform
-type Transformer interface {
-       // Transform accepts a node and returns a replacement node along with
-       // a flag for whether to also visit child nodes. If the flag is false,
-       // none of the child nodes will be visited and the TransformExit method
-       // will not be called for the node.
-       //
-       // It is acceptable and appropriate for Transform to return the same node
-       // it was given, for situations where no transform is needed.
-       Transform(node Node) (Node, bool, hcl.Diagnostics)
-
-       // TransformExit signals the end of transformations of child nodes of the
-       // given node. If Transform returned a new node, the given node is the
-       // node that was returned, rather than the node that was originally
-       // encountered.
-       TransformExit(node Node) hcl.Diagnostics
-}
-
-// Transform allows for in-place transformations of an AST starting with a
-// particular node. The provider Transformer implementation drives the
-// transformation process. The return value is the node that replaced the
-// given top-level node.
-func Transform(node Node, t Transformer) (Node, hcl.Diagnostics) {
-       newNode, descend, diags := t.Transform(node)
-       if !descend {
-               return newNode, diags
-       }
-       node.walkChildNodes(func(node Node) Node {
-               newNode, newDiags := Transform(node, t)
-               diags = append(diags, newDiags...)
-               return newNode
-       })
-       diags = append(diags, t.TransformExit(newNode)...)
-       return newNode, diags
-}