v0.0.14
This release is characterized by a major syntax change. We don’t take such changes lightly. The new syntax makes the language more regular (and simpler to parse), prepares it for some key features, and, we believe, makes it easier to understand. This is also a major step towards stabilizing the grammar of the language to the extent we can start guaranteeing backwards compatibility.
The old syntax is still supported. The cue fmt will rewrite your files from the old syntax to the new one.
Colons instead of spaces as separators for shorthands
CUE allows single-field structs to be written without curly braces if they are declared at another field. In the old syntax
a: {
b: {
c: 4
}
}could be written as
a b c: 4In the new syntax, this is written as
a: b: c: 4Aside from enabling some new features and simplifying the parser, this syntax also allows the shorthand to be used for both definitions and regular fields. For instance,
a: b:: c: intprevious had to be written as
a: {
b:: { c: int }
}Bulk optional fields
The new syntax now allows optional fields to be specified in bulk:
// Define a map from string key to numbers
numMap: [string]: number
// Apply constraint T to all fields with a name ending in "Test"
[=~"Test$"]: TUsing [string]: number is very similar to using a “bind label” previously. More on that later.
The old syntax for optional fields
foo?: baris now just syntactic sugar for
["foo"]: barLabel filters are the equivalent of patternProperties in JSON schema.
Note that using colons as separators, which often have a connotation of defining something, interacts well with this language construct. For instance, a map of maps of ints is written as:
[string]: [string]: intMore aliasing
Shadowing of fields is a common issue in CUE (or similar languages, for that matter). CUE already supported various mechanisms to deal with this. For instance, in this example an alias is used to reach the outer a:
A=a
a: c: a: A.b
b: 4Other tricks up CUE sleeves were quoted identifiers and allowing to make field non-referable using double quotes. Together these tricks proved both cumbersome and inadequate. The existing techniques also proved to be hard to handle for code generators and rewriters.
CUE now extends the aliasing model to field and label aliases. A field alias,
X=foo: barbinds X to bar just as foo does. This allows the above to be written as
X=a: c: a: X.b
b: 4This is not a great win, bit in many cases it will be. Moreover, it allows defining references to fields that can otherwise not be referenced, such as
X="foo-bar": baz
Y="\(x)Test": yCUE now also allows label aliases, which are placed inside the square brackets:
[X=string]: { name: X }These are only visible within the field’s value. This replaces the “bind” labels, such as <Name>: { name: Name }. These are essentially the same, but explained differently and with a different syntax. The old syntax makes CUE hard to parse and is less flexible and will be phased out.
Packaging
Another change is the way the cue tool manages packaging. The cue.mod file and pkg directory are replaced with a cue.mod directory marking the root of a CUE module and with contents managed by the cue tool, analogously to how the git tool manages the .git directory.
See https://cuelang.org/docs/concepts/packages for more details.
Deprecations
Fields names starting with double underscore __
This was defined in the language specification, but previously not enforced. It now is. Field aliases make it easier to work around this restriction.
<X> syntax
Bind labels, or templates, are being replaced by the new optional field construct.
cue fmt will rewrite the old format to the new one.
Back-quoted identifiers
Back-quoted identifiers (i.e. foo-bar) were introduced to improve reachability of fields in case of shadowing. But they only solve half the problem. Field proved to be a more general solution, making back-quoted identifiers a redundant part of the language. As they are not trivial, they will be removed. As for now, the cue tool will rewrite programs using back-quoted identifiers using aliases.
All changes
32 changesby area
cmd8
cmd/cue/cmdadded cue mod init commandcmd/cue/cmdclarify location for commands in error messagecmd/cue/cmdcorrect module outputcmd/cue/cmdget go: convert Go block commentscmd/cue/cmdreport error for certain deprecated syntaxcmd/cue/cmdupdate more examples to the new formatcmd/cue/cmdupdate trim documentation to new syntaxcmd/cuerewrite quoted identifiers
cue16
cue/astadd NewList helpercue/formatformatting of nested single-line fieldscue/loadallow cue.mod to be directorycue/loadallow cue.mod to be directorycue/loadmake cue.mod the default desitinationcue/loadrevert: report when "tool" pkg is used in non-tool filecue/parserdisallow declarations with __foo identifiers as per speccue/parserfix comment attachement issuecue/parserfix comment attachement issuescue/parserrecord position of deprecated featurecuegenerate builtins to update task documentationcuegenerate new-style maps when exportingcueimplement key filters using new syntaxcueintroduce colon-separated labelscuemore conversions to new style templatescuemove to square brackets
doc5
doc/ref/spec.mdbug fix: add solidus to escaped_chardoc/ref/spec.mdintroduce colons as separatorsdoc/ref/spec.mdwrite out spec for aliases and optional field setsdoc/tutorial/kubernetesupdate formattingdoc/tutorial/kubernetesupdate to new syntax
Other3
- Fix typo (#164)
README.mdbump supported go version to 1.12+Readme.mdadd GolangCI badge
Downloads
Every file this release published on GitHub, with its SHA-256. Most people install CUE as Installing CUE describes, which also shows how to check a download.
Archives
| Platform | File and SHA-256 |
|---|---|
| macOS, Intel | cue_950842c31d2d58f10ef7f1821c85fcef8adafd93f93dae3596ac3cba33e696b1 |
| Linux, Arm64 | cue_bd4e47860e9df2132e0e80876ddb37179d7a1e8bb93ca6d34b5bb19884b2aaf6 |
| Linux, x86-64 | cue_9c8a456d76548c015af9543e21d26f83ae8f28d82c3f5fc4425cdf3378e76fa1 |
| Windows, x86-64 | cue_a575451e59e8fa146b69379fba2e5cd4c5d45f9c64ba18690cdd109de847dda1 |
SHA-256 checksums for all of these: checksums.txt