internal/core/adt: support interpolation of bytes and bool
Also fixes bytes interpolation, which was still WIP.
For bool: use JSON representation
For bytes: assume bytes are UTF-8 and replace illegal characters according to the recommendations of the Unicode consortium and W3C requirement for character encodings. (So not the Go standard for replacement.)
Details clarified in spec.
Fixes #475.
Change-Id: I94c068f8a73a3948194b179a33e556c37692c05f
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6951
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
diff --git a/internal/core/compile/compile.go b/internal/core/compile/compile.go
index 853a6a6..dbb556a 100644
--- a/internal/core/compile/compile.go
+++ b/internal/core/compile/compile.go
@@ -799,11 +799,16 @@
if len(n.Elts) == 1 {
return c.expr(n.Elts[0])
}
- lit := &adt.Interpolation{Src: n, K: adt.StringKind}
+ lit := &adt.Interpolation{Src: n}
info, prefixLen, _, err := literal.ParseQuotes(first.Value, last.Value)
if err != nil {
return c.errf(n, "invalid interpolation: %v", err)
}
+ if info.IsDouble() {
+ lit.K = adt.StringKind
+ } else {
+ lit.K = adt.BytesKind
+ }
prefix := ""
for i := 0; i < len(n.Elts); i += 2 {
l, ok := n.Elts[i].(*ast.BasicLit)