Skip to content

Commit

Permalink
doc/ref/spec.md: introduction of value aliases
Browse files Browse the repository at this point in the history
Also:
- removes a deprecated example
- simplifies the definition of AliasExpr

Change-Id: I4f6e389146850102c21fcc9fd75f8bd59daa07df
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9684
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
  • Loading branch information
mpvl committed May 5, 2021
1 parent 2118921 commit 3316905
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions doc/ref/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ StructLit = "{" { Declaration "," } "}" .
Declaration = Field | Ellipsis | Embedding | LetClause | attribute .
Ellipsis = "..." [ Expression ] .
Embedding = Comprehension | AliasExpr .
Field = Label ":" { Label ":" } Expression { attribute } .
Field = Label ":" { Label ":" } AliasExpr { attribute } .
Label = [ identifier "=" ] LabelExpr .
LabelExpr = LabelName [ "?" ] | "[" AliasExpr "]" .
LabelName = identifier | simple_string_lit .
Expand Down Expand Up @@ -1472,7 +1472,7 @@ within the [scope](#declarations-and-scopes) in which they are declared.
The name of an alias must be unique within its scope.

```
AliasExpr = Expression | identifier "=" Expression .
AliasExpr = [ identifier "=" ] Expression .
```

Aliases can appear in several positions:
Expand All @@ -1492,6 +1492,10 @@ In front of a Label (`X=label: value`):
- for optional fields (`foo?: bar` and `[foo]: bar`),
the bound identifier is only visible within the field value (`bar`).

Before a value (`foo: X=x`)

- binds the identifier to the value it precedes within the scope of that value.

Inside a bracketed label (`[X=expr]: value`):

- binds the identifier to the the concrete label that matches `expr`
Expand All @@ -1508,14 +1512,14 @@ Before a list element (`[ X=value, X+1 ]`) (Not yet implemented)
-->

```
// An alias declaration
Alias = 3
a: Alias // 3
// A field alias
foo: X // 4
X="not an identifier": 4
// A value alias
foo: X={x: X.a}
bar: foo & {a: 1} // {a: 1, x: 1}
// A label alias
[Y=string]: { name: Y }
foo: { value: 1 } // outputs: foo: { name: "foo", value: 1 }
Expand Down

0 comments on commit 3316905

Please sign in to comment.