cue: simplify implementation
This is to help transition to new evaluator later.
Change-Id: Ieb6bea857302114ffa19249134732c6c57cf0d06
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6516
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/testdata/script/vet_path.txt b/cmd/cue/cmd/testdata/script/vet_path.txt
index 0893851..84a8ad5 100644
--- a/cmd/cue/cmd/testdata/script/vet_path.txt
+++ b/cmd/cue/cmd/testdata/script/vet_path.txt
@@ -4,10 +4,7 @@
deployment.Booster.name: invalid value "Booster" (excluded by !~"^[A-Z]"):
./services.cue:1:29
./services.jsonl:3:13
-service."""
- Supplement
- foo
- """.name: invalid value "Supplement\nfoo" (excluded by !~"^[A-Z]"):
+service."Supplement\nfoo".name: invalid value "Supplement\nfoo" (excluded by !~"^[A-Z]"):
./services.cue:2:26
./services.jsonl:3:13
-- services.cue --
diff --git a/cue/builtin.go b/cue/builtin.go
index 4cda187..cfd98a6 100644
--- a/cue/builtin.go
+++ b/cue/builtin.go
@@ -91,7 +91,9 @@
if err != nil {
panic(fmt.Errorf("could not parse %v: %v", p.cue, err))
}
- pkg := evalExpr(ctx, obj, expr).(*structLit)
+ v := newVisitor(ctx.index, nil, nil, nil, false)
+ value := v.walk(expr)
+ pkg := value.evalPartial(ctx).(*structLit)
for _, a := range pkg.Arcs {
// Discard option status and attributes at top level.
// TODO: filter on capitalized fields?
diff --git a/cue/types.go b/cue/types.go
index e5006b4..9000165 100644
--- a/cue/types.go
+++ b/cue/types.go
@@ -23,7 +23,6 @@
"math/big"
"strconv"
"strings"
- "unicode"
"github.com/cockroachdb/apd/v2"
@@ -508,39 +507,17 @@
case listKind:
a = append(a, strconv.FormatInt(int64(v.index), 10))
case structKind:
- f := idx.LabelStr(v.arc.Label)
- if l := v.arc.Label; !l.IsDef() && !l.IsHidden() {
- if !isIdent(f) && !isNumber(f) {
- f = quote(f, '"')
+ label := idx.LabelStr(v.arc.Label)
+ if f := v.arc.Label; !f.IsDef() && !f.IsHidden() {
+ if !ast.IsValidIdent(label) {
+ label = strconv.Quote(label)
}
}
- a = append(a, f)
+ a = append(a, label)
}
return a, v.arc.Value.Kind()
}
-var validIdent = []*unicode.RangeTable{unicode.L, unicode.N}
-
-func isIdent(s string) bool {
- valid := []*unicode.RangeTable{unicode.Letter}
- for _, r := range s {
- if !unicode.In(r, valid...) && r != '_' {
- return false
- }
- valid = validIdent
- }
- return true
-}
-
-func isNumber(s string) bool {
- for _, r := range s {
- if r < '0' || '9' < r {
- return false
- }
- }
- return true
-}
-
// Value holds any value, which may be a Boolean, Error, List, Null, Number,
// Struct, or String.
type Value struct {