Skip to content

Commit fc8791f

Browse files
haoqixumvdan
authored andcommitted
cue/parser: allow for as label for required field
This adds support for using `for` in field labels when they are marked as required with '!'. Fixes #3783 Change-Id: I77b063250f79e26c9eb33c706cc970639a5e69b1 Signed-off-by: haoqixu <[email protected]> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1209270 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent b14cfde commit fc8791f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: cue/parser/parser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ func (p *parser) parseComprehensionClauses(first bool) (clauses []ast.Clause, c
10831083
forPos := p.expect(token.FOR)
10841084
if first {
10851085
switch p.tok {
1086-
case token.COLON, token.BIND, token.OPTION,
1086+
case token.COLON, token.BIND, token.OPTION, token.NOT,
10871087
token.COMMA, token.EOF:
10881088
return nil, c
10891089
}

Diff for: cue/parser/parser_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ func TestParse(t *testing.T) {
7272
for: if: func: let: 3
7373
`,
7474
`if: 0, for: 1, in: 2, where: 3, div: 4, quo: 5, func: 6, for: {if: {func: {let: 3}}}`,
75+
}, {
76+
"keywords as optional labels",
77+
`if?: 0, for?: 1, in?: 2, where?: 3, div?: 4, quo?: 5, func?: 6
78+
for?: if?: func?: let?: 3
79+
`,
80+
`if?: 0, for?: 1, in?: 2, where?: 3, div?: 4, quo?: 5, func?: 6, for?: {if?: {func?: {let?: 3}}}`,
81+
}, {
82+
"keywords as required labels",
83+
`for!: 1, in!: 2, where!: 3, div!: 4, quo!: 5, func!: 6
84+
for!: if!: func!: let!: 3
85+
`,
86+
`for!: 1, in!: 2, where!: 3, div!: 4, quo!: 5, func!: 6, for!: {if!: {func!: {let!: 3}}}`,
7587
}, {
7688
"keywords as alias",
7789
`if=foo: 0

0 commit comments

Comments
 (0)