You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// exp.(hclsyntax.Node)
hclsyntax.VisitAll(node, func(n hclsyntax.Node) hcl.Diagnostics {
if fe, ok := n.(*hclsyntax.FunctionCallExpr); ok {
...
}
return nil
})
what isn't too awful.
But that does not work when parsing JSON inputs where *json.expression does not provide such access. Atm. the only solution I found for that case was doing some ugly hacks with the reflect package. There is smth called ExprCall but afaics that only works on a very specific input of a single function call.
There should be some common pattern to achieve this. Eg. maybe add Functions() []string method tho hcl.Expression. Or improve ways for walking through JSON expression types. I'm willing to contribute this if we can agree on the design first.
The text was updated successfully, but these errors were encountered:
Indeed, at the moment the assumption is that your table of functions will be static for all expressions, rather than dynamic based on what the expression is calling. The ability to look up variable references to populate a dynamic scope arose from Terraform's need to build a dependency graph; I'd be curious to hear about what you are doing that calls for static analysis of function calls!
I'm using this in docker/buildx#575 . The code is quite ugly atm, I hope to refactor it into a higher-level parser function that supports vars, user-funcs and cross-referencing values by default.
Currently
Expression
https://pkg.go.dev/github.com/hashicorp/hcl/v2#Expression provides access to variables it uses viaVariables()
method. This can be used for dynamic lookup for theEvalContext
. But similar concept is not provided for functions.Currently, I can do
what isn't too awful.
But that does not work when parsing JSON inputs where
*json.expression
does not provide such access. Atm. the only solution I found for that case was doing some ugly hacks with the reflect package. There is smth calledExprCall
but afaics that only works on a very specific input of a single function call.There should be some common pattern to achieve this. Eg. maybe add
Functions() []string
method thohcl.Expression
. Or improve ways for walking through JSON expression types. I'm willing to contribute this if we can agree on the design first.The text was updated successfully, but these errors were encountered: