Skip to content

Commit

Permalink
all: remove support for ::
Browse files Browse the repository at this point in the history
This also includes deprecation support.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I3ea7aea6af545bbbeb8bdd4228891a6136a22096
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/546886
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
mpvl committed Feb 1, 2023
1 parent 76e0be4 commit a6055ea
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 60 deletions.
22 changes: 15 additions & 7 deletions cmd/cue/cmd/get_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ func (e *extractor) reportDecl(x *ast.GenDecl) (a []cueast.Decl) {
break
}

f, _ := e.makeField(name, cuetoken.ISA, underlying, x.Doc, true)
f, _ := e.makeField(name, definition, underlying, x.Doc, true)
a = append(a, f)
cueast.SetRelPos(f, cuetoken.NewSection)

Expand Down Expand Up @@ -983,10 +983,18 @@ func supportedType(stack []types.Type, t types.Type) (ok bool) {
return false
}

func (e *extractor) makeField(name string, kind cuetoken.Token, expr types.Type, doc *ast.CommentGroup, newline bool) (f *cueast.Field, typename string) {
type fieldKind int

const (
regular fieldKind = iota
optional
definition
)

func (e *extractor) makeField(name string, kind fieldKind, expr types.Type, doc *ast.CommentGroup, newline bool) (f *cueast.Field, typename string) {
typ := e.makeType(expr)
var label cueast.Label
if kind == cuetoken.ISA {
if kind == definition {
label = e.ident(name, true)
} else {
label = e.strLabel(name)
Expand All @@ -997,7 +1005,7 @@ func (e *extractor) makeField(name string, kind cuetoken.Token, expr types.Type,
cueast.SetRelPos(doc, cuetoken.NewSection)
}

if kind == cuetoken.OPTION {
if kind == optional {
f.Token = cuetoken.COLON
f.Optional = cuetoken.Blank.Pos()
}
Expand Down Expand Up @@ -1202,12 +1210,12 @@ func (e *extractor) addFields(x *types.Struct, st *cueast.StructLit) {
continue
}
// TODO: check referrers
kind := cuetoken.COLON
kind := regular
if e.isOptional(tag) {
kind = cuetoken.OPTION
kind = optional
}
if _, ok := f.Type().(*types.Pointer); ok {
kind = cuetoken.OPTION
kind = optional
}
field, cueType := e.makeField(name, kind, f.Type(), docs[i], count > 0)
add(field)
Expand Down
4 changes: 1 addition & 3 deletions cue/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ type Field struct {

// No TokenPos: Value must be an StructLit with one field.
TokenPos token.Pos
Token token.Token // ':' or '::', ILLEGAL implies ':'
Token token.Token // Deprecated: always token.COLON

Value Expr // the value associated with this field.

Expand Down Expand Up @@ -540,8 +540,6 @@ func NewStruct(fields ...interface{}) *StructLit {
break inner
case token.Token:
switch x {
case token.ISA:
tok = x
case token.OPTION:
optional = token.Blank.Pos()
case token.COLON, token.ILLEGAL:
Expand Down
2 changes: 1 addition & 1 deletion cue/format/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (f *formatter) walkDeclList(list []ast.Decl) {
if hasDocComments(x) {
switch x := list[i-1].(type) {
case *ast.Field:
if x.Token == token.ISA || internal.IsDefinition(x.Label) {
if internal.IsDefinition(x.Label) {
f.print(newsection)
}

Expand Down
4 changes: 2 additions & 2 deletions cue/format/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func TestInvalidAST(t *testing.T) {
}{{
desc: "label sequence for definition",
node: &ast.Field{Label: ident("foo"), Value: ast.NewStruct(
ident("bar"), token.ISA, &ast.StructLit{},
ident("#bar"), token.COLON, &ast.StructLit{},
)},
// Force a new struct.
out: `foo: {
bar :: {}
#bar: {}
}`,
}, {
desc: "label with invalid identifier",
Expand Down
26 changes: 10 additions & 16 deletions cue/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ func (p *parser) parseField() (decl ast.Decl) {
// allowComprehension = false

switch p.tok {
case token.COLON, token.ISA:
case token.COLON:
case token.COMMA:
p.expectComma() // sync parser.
fallthrough
Expand All @@ -898,13 +898,10 @@ func (p *parser) parseField() (decl ast.Decl) {

m.TokenPos = p.pos
m.Token = p.tok
if p.tok == token.ISA {
p.assertV0(p.pos, 2, 0, "'::'")
}
if p.tok != token.COLON && p.tok != token.ISA {
p.errorExpected(pos, "':' or '::'")
if p.tok != token.COLON {
p.errorExpected(pos, "':'")
}
p.next() // : or ::
p.next() // :

for {
if l, ok := m.Label.(*ast.ListLit); ok && len(l.Elts) != 1 {
Expand All @@ -913,7 +910,7 @@ func (p *parser) parseField() (decl ast.Decl) {

tok := p.tok
label, expr, _, ok := p.parseLabel(true)
if !ok || (p.tok != token.COLON && p.tok != token.ISA && p.tok != token.OPTION) {
if !ok || (p.tok != token.COLON && p.tok != token.OPTION) {
if expr == nil {
expr = p.parseRHS()
}
Expand All @@ -931,14 +928,11 @@ func (p *parser) parseField() (decl ast.Decl) {

m.TokenPos = p.pos
m.Token = p.tok
if p.tok == token.ISA {
p.assertV0(p.pos, 2, 0, "'::'")
}
if p.tok != token.COLON && p.tok != token.ISA {
if p.tok != token.COLON {
if p.tok.IsLiteral() {
p.errf(p.pos, "expected ':' or '::'; found %s", p.lit)
p.errf(p.pos, "expected ':'; found %s", p.lit)
} else {
p.errf(p.pos, "expected ':' or '::'; found %s", p.tok)
p.errf(p.pos, "expected ':'; found %s", p.tok)
}
break
}
Expand Down Expand Up @@ -1096,7 +1090,7 @@ func (p *parser) parseComprehensionClauses(first bool) (clauses []ast.Clause, c
forPos := p.expect(token.FOR)
if first {
switch p.tok {
case token.COLON, token.ISA, token.BIND, token.OPTION,
case token.COLON, token.BIND, token.OPTION,
token.COMMA, token.EOF:
return nil, c
}
Expand Down Expand Up @@ -1126,7 +1120,7 @@ func (p *parser) parseComprehensionClauses(first bool) (clauses []ast.Clause, c
ifPos := p.expect(token.IF)
if first {
switch p.tok {
case token.COLON, token.ISA, token.BIND, token.OPTION,
case token.COLON, token.BIND, token.OPTION,
token.COMMA, token.EOF:
return nil, c
}
Expand Down
2 changes: 0 additions & 2 deletions cue/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,6 @@ func TestStrict(t *testing.T) {
`a b c: 2`},
{"reserved identifiers",
`__foo: 3`},
{"old-style definition",
`foo :: 3`},
{"old-style alias 1",
`X=3`},
{"old-style alias 2",
Expand Down
7 changes: 1 addition & 6 deletions cue/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,12 +866,7 @@ scanAgain:
insertEOL = true
tok, lit = s.scanAttribute()
case ':':
if s.ch == ':' {
s.next()
tok = token.ISA
} else {
tok = token.COLON
}
tok = token.COLON
case ';':
tok = token.SEMICOLON
insertEOL = true
Expand Down
1 change: 0 additions & 1 deletion cue/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ var testTokens = [...]elt{
{token.RBRACK, "]", operator},
{token.RBRACE, "}", operator},
{token.COLON, ":", operator},
{token.ISA, "::", operator},

// Keywords
{token.TRUE, "true", keyword},
Expand Down
2 changes: 0 additions & 2 deletions cue/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const (
RBRACE // }
SEMICOLON // ;
COLON // :
ISA // ::
OPTION // ?
operatorEnd

Expand Down Expand Up @@ -161,7 +160,6 @@ var tokens = [...]string{
RBRACE: "}",
SEMICOLON: ";",
COLON: ":",
ISA: "::",
OPTION: "?",

BOTTOM: "_|_",
Expand Down
15 changes: 0 additions & 15 deletions internal/core/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,15 +595,6 @@ func (c *compiler) decl(d ast.Decl) adt.Decl {
return c.errf(x, "cannot use _ as label")
}

// TODO(legacy): remove: old-school definitions
if x.Token == token.ISA && !label.IsDef() {
name, isIdent, err := ast.LabelName(lab)
if err == nil && isIdent {
idx := c.index.StringToIndex(name)
label, _ = adt.MakeLabel(x, idx, adt.DefinitionLabel)
}
}

if x.Optional == token.NoPos {
return &adt.Field{
Src: x,
Expand Down Expand Up @@ -640,19 +631,13 @@ func (c *compiler) decl(d ast.Decl) adt.Decl {
}

case *ast.ParenExpr:
if x.Token == token.ISA {
c.errf(x, "definitions not supported for dynamic fields")
}
return &adt.DynamicField{
Src: x,
Key: c.expr(l),
Value: value,
}

case *ast.Interpolation:
if x.Token == token.ISA {
c.errf(x, "definitions not supported for interpolations")
}
return &adt.DynamicField{
Src: x,
Key: c.expr(l),
Expand Down
3 changes: 1 addition & 2 deletions internal/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ func (v *validator) validate(n ast.Node) bool {
check(n, i.Imports, "imports", true)

case *ast.Field:
check(n, i.Definitions, "definitions",
x.Token == token.ISA || internal.IsDefinition(x.Label))
check(n, i.Definitions, "definitions", internal.IsDefinition(x.Label))
check(n, i.Data, "regular fields", internal.IsRegularField(x))
check(n, constraints, "optional fields", x.Optional != token.NoPos)

Expand Down
3 changes: 0 additions & 3 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,6 @@ func IsDefinition(label ast.Label) bool {
}

func IsRegularField(f *ast.Field) bool {
if f.Token == token.ISA {
return false
}
var ident *ast.Ident
switch x := f.Label.(type) {
case *ast.Alias:
Expand Down

0 comments on commit a6055ea

Please sign in to comment.