]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression_template.go
update vendor and go.mod
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / hcl2 / hcl / hclsyntax / expression_template.go
index a1c472754d2858e0a7a98a8172f486a1d83201bb..ca3dae189f4c60719dd3540615a6939891a7deff 100644 (file)
@@ -16,8 +16,8 @@ type TemplateExpr struct {
 }
 
 func (e *TemplateExpr) walkChildNodes(w internalWalkFunc) {
-       for i, part := range e.Parts {
-               e.Parts[i] = w(part).(Expression)
+       for _, part := range e.Parts {
+               w(part)
        }
 }
 
@@ -37,8 +37,10 @@ func (e *TemplateExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics)
                                Detail: fmt.Sprintf(
                                        "The expression result is null. Cannot include a null value in a string template.",
                                ),
-                               Subject: part.Range().Ptr(),
-                               Context: &e.SrcRange,
+                               Subject:     part.Range().Ptr(),
+                               Context:     &e.SrcRange,
+                               Expression:  part,
+                               EvalContext: ctx,
                        })
                        continue
                }
@@ -61,8 +63,10 @@ func (e *TemplateExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics)
                                        "Cannot include the given value in a string template: %s.",
                                        err.Error(),
                                ),
-                               Subject: part.Range().Ptr(),
-                               Context: &e.SrcRange,
+                               Subject:     part.Range().Ptr(),
+                               Context:     &e.SrcRange,
+                               Expression:  part,
+                               EvalContext: ctx,
                        })
                        continue
                }
@@ -85,6 +89,26 @@ func (e *TemplateExpr) StartRange() hcl.Range {
        return e.Parts[0].StartRange()
 }
 
+// IsStringLiteral returns true if and only if the template consists only of
+// single string literal, as would be created for a simple quoted string like
+// "foo".
+//
+// If this function returns true, then calling Value on the same expression
+// with a nil EvalContext will return the literal value.
+//
+// Note that "${"foo"}", "${1}", etc aren't considered literal values for the
+// purposes of this method, because the intent of this method is to identify
+// situations where the user seems to be explicitly intending literal string
+// interpretation, not situations that result in literals as a technicality
+// of the template expression unwrapping behavior.
+func (e *TemplateExpr) IsStringLiteral() bool {
+       if len(e.Parts) != 1 {
+               return false
+       }
+       _, ok := e.Parts[0].(*LiteralValueExpr)
+       return ok
+}
+
 // TemplateJoinExpr is used to convert tuples of strings produced by template
 // constructs (i.e. for loops) into flat strings, by converting the values
 // tos strings and joining them. This AST node is not used directly; it's
@@ -94,7 +118,7 @@ type TemplateJoinExpr struct {
 }
 
 func (e *TemplateJoinExpr) walkChildNodes(w internalWalkFunc) {
-       e.Tuple = w(e.Tuple).(Expression)
+       w(e.Tuple)
 }
 
 func (e *TemplateJoinExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
@@ -127,7 +151,9 @@ func (e *TemplateJoinExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnosti
                                Detail: fmt.Sprintf(
                                        "An iteration result is null. Cannot include a null value in a string template.",
                                ),
-                               Subject: e.Range().Ptr(),
+                               Subject:     e.Range().Ptr(),
+                               Expression:  e,
+                               EvalContext: ctx,
                        })
                        continue
                }
@@ -143,7 +169,9 @@ func (e *TemplateJoinExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnosti
                                        "Cannot include one of the interpolation results into the string template: %s.",
                                        err.Error(),
                                ),
-                               Subject: e.Range().Ptr(),
+                               Subject:     e.Range().Ptr(),
+                               Expression:  e,
+                               EvalContext: ctx,
                        })
                        continue
                }
@@ -176,7 +204,7 @@ type TemplateWrapExpr struct {
 }
 
 func (e *TemplateWrapExpr) walkChildNodes(w internalWalkFunc) {
-       e.Wrapped = w(e.Wrapped).(Expression)
+       w(e.Wrapped)
 }
 
 func (e *TemplateWrapExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {