2017-05-24 15:05:52 +00:00
|
|
|
package zclsyntax
|
|
|
|
|
|
|
|
import (
|
2017-05-28 00:33:09 +00:00
|
|
|
"github.com/zclconf/go-zcl/zcl"
|
2017-05-24 15:05:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2017-06-13 15:53:33 +00:00
|
|
|
|
|
|
|
// TODO: When traversing into ForExpr, filter out references to
|
|
|
|
// the iterator variables, since they are references into the child
|
|
|
|
// scope, and thus not interesting to the caller.
|
|
|
|
|
2017-05-24 15:05:52 +00:00
|
|
|
VisitAll(expr, func(n Node) zcl.Diagnostics {
|
|
|
|
if ste, ok := n.(*ScopeTraversalExpr); ok {
|
|
|
|
vars = append(vars, ste.Traversal)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return vars
|
|
|
|
}
|