cue/parser: remove support for legacy field comprehensions
`a: b for x in src`-style comprehensions are now
no longer supported, even by `cue fmt`.
Removing this support allows for a notable
simplification in the parser.
Issue #339
Change-Id: Ibff7ffc3b70f668e5c5c130c599399e353829465
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5682
Reviewed-by: roger peppe <rogpeppe@gmail.com>
diff --git a/cmd/cue/cmd/fix_test.go b/cmd/cue/cmd/fix_test.go
index 15093b3..198c844 100644
--- a/cmd/cue/cmd/fix_test.go
+++ b/cmd/cue/cmd/fix_test.go
@@ -54,25 +54,6 @@
ref: X1 & x
}
`,
- }, {
- name: "comprehensions",
- in: `
-package fix
-
-"\(k)": v for k, v in src
-
-"\(k)": v <-
- for k, v in src
- `,
- out: `package fix
-
-for k, v in src {
- "\(k)": v
-}
-for k, v in src {
- "\(k)": v
-}
-`,
// }, {
// name: "slice",
// in: `package foo
diff --git a/cmd/cue/cmd/testdata/script/legacy.txt b/cmd/cue/cmd/testdata/script/legacy.txt
index 13cd68f..8cb4a6e 100644
--- a/cmd/cue/cmd/testdata/script/legacy.txt
+++ b/cmd/cue/cmd/testdata/script/legacy.txt
@@ -4,16 +4,11 @@
! cue export foo.cue
cmp stderr expect-stderr
-cue fmt foo.cue
-cmp foo.cue foo-new.cue
+! cue fmt foo.cue
+cmp stderr expect-stderr
-- expect-stderr --
-old-style comprehensions deprecated as of v0.0.11: try running `cue fmt` on the file to upgrade.:
+missing ',' in struct literal:
./foo.cue:1:8
-- foo.cue --
"x": 3 for x in a
--- foo-new.cue --
-
-for x in a {
- "x": 3
-}
diff --git a/cue/parser/parser.go b/cue/parser/parser.go
index 85c1061..eb3a06a 100644
--- a/cue/parser/parser.go
+++ b/cue/parser/parser.go
@@ -786,8 +786,6 @@
this := &ast.Field{Label: nil}
m := this
- allowComprehension := true
-
for i := 0; ; i++ {
tok := p.tok
@@ -901,48 +899,14 @@
}
if attrs := p.parseAttributes(); attrs != nil {
- allowComprehension = false
m.Attrs = attrs
}
- decl = this
- switch p.tok {
- case token.ARROW:
- p.expect(token.ARROW)
- fallthrough
-
- case token.FOR, token.IF:
- p.assertV0(p.pos, 0, 10, "old-style comprehensions")
- if !allowComprehension {
- p.errf(p.pos, "comprehension not allowed for this field")
- }
- clauses, _ := p.parseComprehensionClauses(false)
- if len(clauses) == 0 {
- p.errf(p.pos, "empty comprehension")
- return &ast.BadDecl{From: p.pos, To: p.pos}
- }
- // Erase first position to allow fmt to move to recommended style for
- // new syntax.
- switch c := clauses[0].(type) {
- case *ast.ForClause:
- c.For = token.NoPos
- case *ast.IfClause:
- c.If = token.NoPos
- }
-
- return &ast.Comprehension{
- Clauses: clauses,
- Value: &ast.StructLit{
- Elts: []ast.Decl{this},
- },
- }
- }
-
if p.atComma("struct literal", token.RBRACE) { // TODO: may be EOF
p.next()
}
- return decl
+ return this
}
func (p *parser) parseAttributes() (attrs []*ast.Attribute) {
diff --git a/cue/parser/parser_test.go b/cue/parser/parser_test.go
index 45bdbe0..92734f4 100644
--- a/cue/parser/parser_test.go
+++ b/cue/parser/parser_test.go
@@ -254,15 +254,6 @@
}`,
`{y: {a: 1, b: 2}, a: {for k: v in y if v>2 {"\(k)": v}}}`,
}, {
- "legacy comprehensions", // TODO: remove
- `
- a: b for a, v in s
-
- z: 3 // Remove to have some fun.
- for a, v in t {d:c}
- `,
- `for a: v in s {a: b}, z: 3, for a: v in t {d: c}`,
- }, {
"duplicates allowed",
`{
a: b: 3