VisitBefore implements the ast.Visitor interface.
(n ast.Node)
| 48 | |
| 49 | // VisitBefore implements the ast.Visitor interface. |
| 50 | func (u *Unparser) VisitBefore(n ast.Node) (ast.Visitor, ast.Node) { |
| 51 | if u.emitTypes { |
| 52 | u.emit(fmt.Sprintf("<%s>(", n.Type())) |
| 53 | } |
| 54 | switch v := n.(type) { |
| 55 | case *ast.StmtList: |
| 56 | for _, child := range v.Children { |
| 57 | ast.Walk(u, child) |
| 58 | u.newline() |
| 59 | } |
| 60 | |
| 61 | case *ast.ExprList: |
| 62 | if len(v.Children) > 0 { |
| 63 | ast.Walk(u, v.Children[0]) |
| 64 | for _, child := range v.Children[1:] { |
| 65 | u.emit(", ") |
| 66 | ast.Walk(u, child) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | case *ast.CondStmt: |
| 71 | if v.Cond != nil { |
| 72 | ast.Walk(u, v.Cond) |
| 73 | } |
| 74 | u.emit(" {") |
| 75 | u.newline() |
| 76 | u.indent() |
| 77 | ast.Walk(u, v.Truth) |
| 78 | if v.Else != nil { |
| 79 | u.outdent() |
| 80 | u.emit("} else {") |
| 81 | u.newline() |
| 82 | u.indent() |
| 83 | ast.Walk(u, v.Else) |
| 84 | } |
| 85 | u.outdent() |
| 86 | u.emit("}") |
| 87 | |
| 88 | case *ast.PatternFragment: |
| 89 | u.emit("const ") |
| 90 | ast.Walk(u, v.ID) |
| 91 | u.emit(" ") |
| 92 | ast.Walk(u, v.Expr) |
| 93 | |
| 94 | case *ast.PatternLit: |
| 95 | u.emit("/" + strings.ReplaceAll(v.Pattern, "/", "\\/") + "/") |
| 96 | |
| 97 | case *ast.BinaryExpr: |
| 98 | ast.Walk(u, v.LHS) |
| 99 | switch v.Op { |
| 100 | case LT: |
| 101 | u.emit(" < ") |
| 102 | case GT: |
| 103 | u.emit(" > ") |
| 104 | case LE: |
| 105 | u.emit(" <= ") |
| 106 | case GE: |
| 107 | u.emit(" >= ") |