Skip to content

Commit

Permalink
Add stringify function for IndexListExpr in mingo
Browse files Browse the repository at this point in the history
  • Loading branch information
koki-develop committed Mar 6, 2024
1 parent 8460df6 commit 9595f7e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions internal/mingo/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,30 @@ func stringifyExpr(expr ast.Expr) string {
return stringifyStructType(x)
case *ast.FuncType:
return stringifyFuncType(x)
case *ast.IndexListExpr:
return stringifyIndexListExpr(x)
case nil:
return ""
}

return expr.(*ast.Ident).Name
}

func stringifyIndexListExpr(expr *ast.IndexListExpr) string {
sb := new(strings.Builder)

sb.WriteString("[")
for i, index := range expr.Indices {
if i > 0 {
sb.WriteString(",")
}
sb.WriteString(stringifyExpr(index))
}
sb.WriteString("]")

return sb.String()
}

func stringifySelectExpr(expr *ast.SelectorExpr) string {
switch x := expr.X.(type) {
case *ast.SelectorExpr:
Expand Down

0 comments on commit 9595f7e

Please sign in to comment.