v0.0.14

cue-lang/cue Released

A release of CUE OSS · its page on GitHub

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: 4

In the new syntax, this is written as

a: b: c: 4

Aside 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: int

previous 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$"]: T

Using [string]: number is very similar to using a “bind label” previously. More on that later.

The old syntax for optional fields

foo?: bar

is now just syntactic sugar for

["foo"]: bar

Label 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]: int

More 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: 4

Other 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: bar

binds X to bar just as foo does. This allows the above to be written as

X=a: c: a: X.b
b: 4

This 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": y

CUE 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 command9707302
  • cmd/cue/cmdclarify location for commands in error messagefd127fe
  • cmd/cue/cmdcorrect module outputf979aa6
  • cmd/cue/cmdget go: convert Go block comments329cd5b
  • cmd/cue/cmdreport error for certain deprecated syntax29f70f2
  • cmd/cue/cmdupdate more examples to the new format72b36fb
  • cmd/cue/cmdupdate trim documentation to new syntax26a1a0e
  • cmd/cuerewrite quoted identifiersb763fde

cue16

  • cue/astadd NewList helper9752844
  • cue/formatformatting of nested single-line fields4759dd2
  • cue/loadallow cue.mod to be directory0b4f016
  • cue/loadallow cue.mod to be directoryb34bce7
  • cue/loadmake cue.mod the default desitinationb13155b
  • cue/loadrevert: report when "tool" pkg is used in non-tool file60b298b
  • cue/parserdisallow declarations with __foo identifiers as per spec312fca9
  • cue/parserfix comment attachement issue7057dde
  • cue/parserfix comment attachement issues4177df9
  • cue/parserrecord position of deprecated feature98b8d2f
  • cuegenerate builtins to update task documentationfa59c10
  • cuegenerate new-style maps when exporting8192b54
  • cueimplement key filters using new syntaxff34272
  • cueintroduce colon-separated labels300af3e
  • cuemore conversions to new style templates6d8c95d
  • cuemove to square brackets467d7bc

doc5

  • doc/ref/spec.mdbug fix: add solidus to escaped_char39df6c9
  • doc/ref/spec.mdintroduce colons as separatorsc7791ac
  • doc/ref/spec.mdwrite out spec for aliases and optional field sets9ffcbbc
  • doc/tutorial/kubernetesupdate formatting2437f9d
  • doc/tutorial/kubernetesupdate to new syntax23623fa

Other3

  • Fix typo (#164)fe8ab34
  • README.mdbump supported go version to 1.12+2cd4162
  • Readme.mdadd GolangCI badge391e7ae

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

PlatformFile and SHA-256
macOS, Intelcue_0.0.14_Darwin_x86_64.tar.gz950842c31d2d58f10ef7f1821c85fcef8adafd93f93dae3596ac3cba33e696b1
Linux, Arm64cue_0.0.14_Linux_arm64.tar.gzbd4e47860e9df2132e0e80876ddb37179d7a1e8bb93ca6d34b5bb19884b2aaf6
Linux, x86-64cue_0.0.14_Linux_x86_64.tar.gz9c8a456d76548c015af9543e21d26f83ae8f28d82c3f5fc4425cdf3378e76fa1
Windows, x86-64cue_0.0.14_Windows_x86_64.zipa575451e59e8fa146b69379fba2e5cd4c5d45f9c64ba18690cdd109de847dda1

SHA-256 checksums for all of these: checksums.txt

Install CUE