Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
cue/ast: remove support for TemplateLabel
Browse files Browse the repository at this point in the history
This really hasn't been parsed in ages, so if this
hasn't resulted in problems yet, it is unlikely
this will.

Change-Id: I45c79ad2605479fec4dbdb1df901d458f8662dea
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9561
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
  • Loading branch information
mpvl committed Apr 30, 2021
1 parent fd05bf4 commit b73ab0b
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 63 deletions.
17 changes: 1 addition & 16 deletions cue/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,18 +414,6 @@ type Ident struct {
expr
}

// A TemplateLabel represents a field template declaration in a struct.
//
// Deprecated: use square bracket notation through ListLit.
type TemplateLabel struct {
Langle token.Pos
Ident *Ident
Rangle token.Pos

comments
label
}

// A BasicLit node represents a literal of basic type.
type BasicLit struct {
ValuePos token.Pos // literal position
Expand Down Expand Up @@ -770,8 +758,6 @@ func (x *BadExpr) Pos() token.Pos { return x.From }
func (x *BadExpr) pos() *token.Pos { return &x.From }
func (x *Ident) Pos() token.Pos { return x.NamePos }
func (x *Ident) pos() *token.Pos { return &x.NamePos }
func (x *TemplateLabel) Pos() token.Pos { return x.Langle }
func (x *TemplateLabel) pos() *token.Pos { return &x.Langle }
func (x *BasicLit) Pos() token.Pos { return x.ValuePos }
func (x *BasicLit) pos() *token.Pos { return &x.ValuePos }
func (x *Interpolation) Pos() token.Pos { return x.Elts[0].Pos() }
Expand Down Expand Up @@ -817,8 +803,7 @@ func (x *BadExpr) End() token.Pos { return x.To }
func (x *Ident) End() token.Pos {
return x.NamePos.Add(len(x.Name))
}
func (x *TemplateLabel) End() token.Pos { return x.Rangle }
func (x *BasicLit) End() token.Pos { return x.ValuePos.Add(len(x.Value)) }
func (x *BasicLit) End() token.Pos { return x.ValuePos.Add(len(x.Value)) }

func (x *Interpolation) End() token.Pos { return x.Elts[len(x.Elts)-1].Pos() }
func (x *StructLit) End() token.Pos {
Expand Down
3 changes: 0 additions & 3 deletions cue/ast/astutil/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,6 @@ func applyCursor(v applyVisitor, c Cursor) {
case *ast.BottomLit, *ast.BadExpr, *ast.Ident, *ast.BasicLit:
// nothing to do

case *ast.TemplateLabel:
apply(v, c, &n.Ident)

case *ast.Interpolation:
applyExprList(v, c, &n, n.Elts)

Expand Down
7 changes: 0 additions & 7 deletions cue/ast/astutil/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,6 @@ func (s *scope) Before(n ast.Node) (w visitor) {
}
})
walk(s, expr)

case *ast.TemplateLabel:
s = newScope(s.file, s, x, nil)
name, err := ast.ParseIdent(label.Ident)
if err == nil {
s.insert(name, x.Label, x) // Field used for entire lambda.
}
}

if n := x.Value; n != nil {
Expand Down
3 changes: 0 additions & 3 deletions cue/ast/astutil/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ func walk(v visitor, node ast.Node) {
case *ast.BottomLit, *ast.BadExpr, *ast.Ident, *ast.BasicLit:
// nothing to do

case *ast.TemplateLabel:
walk(v, n.Ident)

case *ast.Interpolation:
for _, e := range n.Elts {
walk(v, e)
Expand Down
3 changes: 0 additions & 3 deletions cue/ast/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ func walk(v visitor, node Node) {
case *BottomLit, *BadExpr, *Ident, *BasicLit:
// nothing to do

case *TemplateLabel:
walk(v, n.Ident)

case *Interpolation:
for _, e := range n.Elts {
walk(v, e)
Expand Down
5 changes: 0 additions & 5 deletions cue/format/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,6 @@ func (f *formatter) label(l ast.Label, optional bool) {
}
f.print(n.ValuePos, str)

case *ast.TemplateLabel:
f.print(n.Langle, token.LSS, indent)
f.label(n.Ident, false)
f.print(unindent, n.Rangle, token.GTR)

case *ast.ListLit:
f.expr(n)

Expand Down
6 changes: 0 additions & 6 deletions internal/astinternal/debugstr.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ func DebugStr(x interface{}) (out string) {
case *ast.Ident:
return v.Name

case *ast.TemplateLabel:
out := "<"
out += DebugStr(v.Ident)
out += ">"
return out

case *ast.SelectorExpr:
return DebugStr(v.X) + "." + DebugStr(v.Sel)

Expand Down
20 changes: 0 additions & 20 deletions tools/fix/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,6 @@ func File(f *ast.File, o ...Option) *ast.File {
}
}

// Rewrite TemplateLabel to ListLit.
// Note: there is a chance that the name will clash with the
// scope in which it is defined. We drop the alias if it is not
// used to mitigate this issue.
f = astutil.Apply(f, func(c astutil.Cursor) bool {
n := c.Node()
switch x := n.(type) {
case *ast.TemplateLabel:
var expr ast.Expr = ast.NewIdent("string")
if _, ok := referred[x]; ok {
expr = &ast.Alias{
Ident: x.Ident,
Expr: ast.NewIdent("_"),
}
}
c.Replace(ast.NewList(expr))
}
return true
}, nil).(*ast.File)

// Rewrite quoted identifier fields that are referenced.
f = astutil.Apply(f, func(c astutil.Cursor) bool {
n := c.Node()
Expand Down

0 comments on commit b73ab0b

Please sign in to comment.