cue: add __foo variants for predeclared identifiers
As `__foo` is an illegal field identifier, references
starting with `__` will always be referring to
predeclared identifiers when valid without fear
of shadowing. This simplifies code generation.
Change-Id: Ica1934df6d0716c34bfcc1756564a8da4f291a2c
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5090
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/ast.go b/cue/ast.go
index 269c379..b60e421 100644
--- a/cue/ast.go
+++ b/cue/ast.go
@@ -488,31 +488,32 @@
break
}
+ // TODO: consider supporting GraphQL-style names:
+ // String, Bytes, Boolean, Integer, Number.
+ // These names will not conflict with idiomatic camel-case JSON.
switch name {
case "_":
return &top{newExpr(n)}
- case "string":
+ case "string", "__string":
return &basicType{newExpr(n), stringKind}
- case "bytes":
+ case "bytes", "__bytes":
return &basicType{newExpr(n), bytesKind}
- case "bool":
+ case "bool", "__bool":
return &basicType{newExpr(n), boolKind}
- case "int":
+ case "int", "__int":
return &basicType{newExpr(n), intKind}
- case "float":
+ case "float", "__float":
return &basicType{newExpr(n), floatKind}
- case "number":
+ case "number", "__number":
return &basicType{newExpr(n), numKind}
- case "duration":
- return &basicType{newExpr(n), durationKind}
- case "len":
+ case "len", "__len":
return lenBuiltin
- case "close":
+ case "close", "__close":
return closeBuiltin
- case "and":
+ case "and", "__and":
return andBuiltin
- case "or":
+ case "or", "__or":
return orBuiltin
}
if r, ok := predefinedRanges[name]; ok {