package hclwrite import ( "github.com/hashicorp/hcl2/hcl" "github.com/zclconf/go-cty/cty" ) type Expression struct { inTree absTraversals nodeSet } func newExpression() *Expression { return &Expression{ inTree: newInTree(), absTraversals: newNodeSet(), } } // NewExpressionLiteral constructs an an expression that represents the given // literal value. // // Since an unknown value cannot be represented in source code, this function // will panic if the given value is unknown or contains a nested unknown value. // Use val.IsWhollyKnown before calling to be sure. // // HCL native syntax does not directly represent lists, maps, and sets, and // instead relies on the automatic conversions to those collection types from // either list or tuple constructor syntax. Therefore converting collection // values to source code and re-reading them will lose type information, and // the reader must provide a suitable type at decode time to recover the // original value. func NewExpressionLiteral(val cty.Value) *Expression { toks := TokensForValue(val) expr := newExpression() expr.children.AppendUnstructuredTokens(toks) return expr } // NewExpressionAbsTraversal constructs an expression that represents the // given traversal, which must be absolute or this function will panic. func NewExpressionAbsTraversal(traversal hcl.Traversal) *Expression { panic("NewExpressionAbsTraversal not yet implemented") } type Traversal struct { inTree steps nodeSet } func newTraversal() *Traversal { return &Traversal{ inTree: newInTree(), steps: newNodeSet(), } } type TraverseName struct { inTree name *node } func newTraverseName() *TraverseName { return &TraverseName{ inTree: newInTree(), } } type TraverseIndex struct { inTree key *node } func newTraverseIndex() *TraverseIndex { return &TraverseIndex{ inTree: newInTree(), } }