Skip to content

Commit

Permalink
cue/cmd/cue: disallow quoted identifiers by default
Browse files Browse the repository at this point in the history
These were deprecated a while back. Now step up the
enforcement.

Also bumps the syntax check level.

Issue #339

Change-Id: I922bb075114c638e411eaf7d6e8418cf730578d5
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5780
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Apr 23, 2020
1 parent 50bcd97 commit 9954ecd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/cue/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
// - block comments
// - old-style field comprehensions
// - space separator syntax
const syntaxVersion = -1000 + 13
const syntaxVersion = -1000 + 100*1 + 2

var defaultConfig = config{
loadCfg: &load.Config{
Expand Down
6 changes: 5 additions & 1 deletion cue/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ func (p *parser) next() {
p.comments.add(comment)
}
}

if p.tok == token.IDENT && p.lit[0] == '`' {
p.assertV0(p.pos, 0, 13, "quoted identifiers")
}
}

// assertV0 indicates the last version at which a certain feature was
Expand Down Expand Up @@ -1131,7 +1135,7 @@ func (p *parser) parseList() (expr ast.Expr) {

if clauses, _ := p.parseComprehensionClauses(false); clauses != nil {
var expr ast.Expr
p.assertV0(p.pos, 1, 1, "old-style list comprehensions")
p.assertV0(p.pos, 1, 3, "old-style list comprehensions")
if len(elts) != 1 {
p.errf(lbrack.Add(1), "list comprehension must have exactly one element")
}
Expand Down
10 changes: 5 additions & 5 deletions doc/tutorial/kubernetes/manual/services/k8s.cue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ kubernetes: services: {
metadata: labels: x.label
spec: selector: x.label

spec: ports: [ p for p in x.port ] // convert struct to list
spec: ports: [ for p in x.port {p}] // convert struct to list
}
}
// Note that we cannot write
Expand Down Expand Up @@ -84,13 +84,13 @@ _k8sSpec: X: kubernetes: {
image: X.image
args: X.args
if len(X.envSpec) > 0 {
env: [ for k, v in X.envSpec {v, name: k} ]
env: [ for k, v in X.envSpec {v, name: k}]
}

ports: [ for k, p in X.expose.port & X.port {
name: k
containerPort: p
} ]
}]
}]
}

Expand All @@ -102,7 +102,7 @@ _k8sSpec: X: kubernetes: {
v.kubernetes

name: v.name
}
},
]
}

Expand All @@ -120,7 +120,7 @@ _k8sSpec: X: kubernetes: {
if v.readOnly {
readOnly: v.readOnly
}
}
},
]
}
}]
Expand Down

0 comments on commit 9954ecd

Please sign in to comment.