Skip to content

Commit

Permalink
internal/core/debug: simplify label code following a TODO
Browse files Browse the repository at this point in the history
Support for `::` definitions has been gone since February 2023
via https://cuelang.org/cl/546886.

Signed-off-by: Daniel Martí <[email protected]>
Change-Id: I7de49b46f43fef95feb62e95b2ec53e12870ef05
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194287
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Marcel van Lohuizen <[email protected]>
  • Loading branch information
mvdan committed May 7, 2024
1 parent 51209a5 commit c445c7d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
6 changes: 2 additions & 4 deletions internal/core/debug/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,14 @@ func (w *compactPrinter) node(n adt.Node) {
w.string("]")

case *adt.Field:
s := w.labelString(x.Label)
w.string(s)
w.label(x.Label)
w.string(x.ArcType.Suffix())
w.string(":")
w.node(x.Value)

case *adt.LetField:
w.string("let ")
s := w.labelString(x.Label)
w.string(s)
w.label(x.Label)
if x.IsMulti {
w.string("m")
}
Expand Down
43 changes: 18 additions & 25 deletions internal/core/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,22 @@ func (w *printer) string(s string) {
}

func (w *printer) label(f adt.Feature) {
w.string(w.labelString(f))
switch {
case f.IsHidden():
ident := f.IdentString(w.index)
if pkgName := f.PkgID(w.index); pkgName != "_" {
ident = fmt.Sprintf("%s(%s)", ident, pkgName)
}
w.string(ident)

case f.IsLet():
ident := f.RawString(w.index)
ident = strings.Replace(ident, "\x00", "#", 1)
w.string(ident)

default:
w.string(f.SelectorString(w.index))
}
}

func (w *printer) ident(f adt.Feature) {
Expand Down Expand Up @@ -129,26 +144,6 @@ func (w *printer) printShared(v *adt.Vertex) (x *adt.Vertex, ok bool) {
return v, false
}

// TODO: fold into label once :: is no longer supported.
func (w *printer) labelString(f adt.Feature) string {
switch {
case f.IsHidden():
ident := f.IdentString(w.index)
if pkgName := f.PkgID(w.index); pkgName != "_" {
ident = fmt.Sprintf("%s(%s)", ident, pkgName)
}
return ident

case f.IsLet():
ident := f.RawString(w.index)
ident = strings.Replace(ident, "\x00", "#", 1)
return ident

default:
return f.SelectorString(w.index)
}
}

func (w *printer) shortError(errs errors.Error) {
for {
msg, args := errs.Msg()
Expand Down Expand Up @@ -360,17 +355,15 @@ func (w *printer) node(n adt.Node) {
w.string("\n]")

case *adt.Field:
s := w.labelString(x.Label)
w.string(s)
w.label(x.Label)
w.string(x.ArcType.Suffix())
w.string(":")
w.string(" ")
w.node(x.Value)

case *adt.LetField:
w.string("let ")
s := w.labelString(x.Label)
w.string(s)
w.label(x.Label)
if x.IsMulti {
w.string("multi")
}
Expand Down

0 comments on commit c445c7d

Please sign in to comment.