hcl/zcl/zclsyntax/variables.go
Martin Atkins 007b38797b zclsyntax: Expression.Variables implementation using AST walk
This function is effectively the implementation of Variables for all
expressions, but unfortunately we still need to declare a wrapper around
it as a method on every single expression type.
2017-05-24 08:05:52 -07:00

21 lines
484 B
Go

package zclsyntax
import (
"github.com/apparentlymart/go-zcl/zcl"
)
// Variables returns all of the variables referenced within a given experssion.
//
// This is the implementation of the "Variables" method on every native
// expression.
func Variables(expr Expression) []zcl.Traversal {
var vars []zcl.Traversal
VisitAll(expr, func(n Node) zcl.Diagnostics {
if ste, ok := n.(*ScopeTraversalExpr); ok {
vars = append(vars, ste.Traversal)
}
return nil
})
return vars
}