Skip to content

Commit

Permalink
format: add display of Table
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Jan 17, 2018
1 parent 62bf7ad commit f5f82df
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
35 changes: 31 additions & 4 deletions format/expr.go
Expand Up @@ -104,10 +104,6 @@ func (p *printer) expr(e expr.Expr) {
p.buf.WriteString(" ")
p.stmt(e.Body.(*stmt.Block))
}
/* TODO
case *expr.TableLiteral:
panic("not implemented")
*/
case *expr.CompLiteral:
p.tipe(e.Type)
p.print("{")
Expand Down Expand Up @@ -189,6 +185,37 @@ func (p *printer) expr(e expr.Expr) {
}
}
p.print("}")
case *expr.TableLiteral:
p.tipe(e.Type)
p.print("{")
if len(e.ColNames) > 0 {
p.print("{|")
for i, col := range e.ColNames {
if i > 0 {
p.print(", ")
}
p.expr(col)
}
p.print("|}")
}
if len(e.Rows) > 0 {
p.print(", ")
for i, row := range e.Rows {
if i > 0 {
p.print(", ")
}
p.print("{")
for j, r := range row {
if j > 0 {
p.print(", ")
}
p.expr(r)
}
p.print("}")
}
p.print("}")
}
p.print("}")
case *expr.Type:
p.tipe(e.Type)
case *expr.Ident:
Expand Down
3 changes: 3 additions & 0 deletions format/tipe.go
Expand Up @@ -69,6 +69,9 @@ func (p *printer) tipe(t tipe.Type) {
case *tipe.Slice:
p.buf.WriteString("[]")
p.tipe(t.Elem)
case *tipe.Table:
p.buf.WriteString("[|]")
p.tipe(t.Type)
case *tipe.Interface:
if len(t.Methods) == 0 {
p.buf.WriteString("interface{}")
Expand Down

0 comments on commit f5f82df

Please sign in to comment.