From a6055ea788f75987f9b1b2dc0c4235fd1acf9de1 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Thu, 17 Nov 2022 17:36:28 +0100 Subject: [PATCH] all: remove support for :: This also includes deprecation support. Signed-off-by: Marcel van Lohuizen Change-Id: I3ea7aea6af545bbbeb8bdd4228891a6136a22096 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/546886 Reviewed-by: Roger Peppe Unity-Result: CUEcueckoo TryBot-Result: CUEcueckoo --- cmd/cue/cmd/get_go.go | 22 +++++++++++++++------- cue/ast/ast.go | 4 +--- cue/format/node.go | 2 +- cue/format/node_test.go | 4 ++-- cue/parser/parser.go | 26 ++++++++++---------------- cue/parser/parser_test.go | 2 -- cue/scanner/scanner.go | 7 +------ cue/scanner/scanner_test.go | 1 - cue/token/token.go | 2 -- internal/core/compile/compile.go | 15 --------------- internal/encoding/encoding.go | 3 +-- internal/internal.go | 3 --- 12 files changed, 31 insertions(+), 60 deletions(-) diff --git a/cmd/cue/cmd/get_go.go b/cmd/cue/cmd/get_go.go index 21a38cfa9f2..6d162ca3df8 100644 --- a/cmd/cue/cmd/get_go.go +++ b/cmd/cue/cmd/get_go.go @@ -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) @@ -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) @@ -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() } @@ -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) diff --git a/cue/ast/ast.go b/cue/ast/ast.go index 8ccc14bc928..6f6746ed385 100644 --- a/cue/ast/ast.go +++ b/cue/ast/ast.go @@ -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. @@ -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: diff --git a/cue/format/node.go b/cue/format/node.go index d5da396326f..543f1e6a20b 100644 --- a/cue/format/node.go +++ b/cue/format/node.go @@ -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) } diff --git a/cue/format/node_test.go b/cue/format/node_test.go index 0ee09112136..7bc48ea0ae4 100644 --- a/cue/format/node_test.go +++ b/cue/format/node_test.go @@ -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", diff --git a/cue/parser/parser.go b/cue/parser/parser.go index c0215513714..fa120e87e3e 100644 --- a/cue/parser/parser.go +++ b/cue/parser/parser.go @@ -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 @@ -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 { @@ -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() } @@ -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 } @@ -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 } @@ -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 } diff --git a/cue/parser/parser_test.go b/cue/parser/parser_test.go index 30e57ee1f15..a904f20977f 100644 --- a/cue/parser/parser_test.go +++ b/cue/parser/parser_test.go @@ -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", diff --git a/cue/scanner/scanner.go b/cue/scanner/scanner.go index 3e7fb35096c..9372c7c16fd 100644 --- a/cue/scanner/scanner.go +++ b/cue/scanner/scanner.go @@ -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 diff --git a/cue/scanner/scanner_test.go b/cue/scanner/scanner_test.go index af89f45da47..693e413c26d 100644 --- a/cue/scanner/scanner_test.go +++ b/cue/scanner/scanner_test.go @@ -184,7 +184,6 @@ var testTokens = [...]elt{ {token.RBRACK, "]", operator}, {token.RBRACE, "}", operator}, {token.COLON, ":", operator}, - {token.ISA, "::", operator}, // Keywords {token.TRUE, "true", keyword}, diff --git a/cue/token/token.go b/cue/token/token.go index 657833969e1..b9a891a81ff 100644 --- a/cue/token/token.go +++ b/cue/token/token.go @@ -87,7 +87,6 @@ const ( RBRACE // } SEMICOLON // ; COLON // : - ISA // :: OPTION // ? operatorEnd @@ -161,7 +160,6 @@ var tokens = [...]string{ RBRACE: "}", SEMICOLON: ";", COLON: ":", - ISA: "::", OPTION: "?", BOTTOM: "_|_", diff --git a/internal/core/compile/compile.go b/internal/core/compile/compile.go index 06fccc3aaa6..a0e2c0f5461 100644 --- a/internal/core/compile/compile.go +++ b/internal/core/compile/compile.go @@ -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, @@ -640,9 +631,6 @@ 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), @@ -650,9 +638,6 @@ func (c *compiler) decl(d ast.Decl) adt.Decl { } 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), diff --git a/internal/encoding/encoding.go b/internal/encoding/encoding.go index 1f955a7d4de..e7e9dd101f1 100644 --- a/internal/encoding/encoding.go +++ b/internal/encoding/encoding.go @@ -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) diff --git a/internal/internal.go b/internal/internal.go index 2e4003cbea4..8bb2a5cfb2d 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -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: