}
+func reduceDepth(depth int) int {
+ depth--
+ if depth < 1 {
+ depth = 1
+ }
+ return depth
+}
+
+
// Format the binary expression: decide the cutoff and then format.
// Let's call depth == 1 Normal mode, and depth > 1 Compact mode.
// (Algorithm suggestion by Russ Cox.)
// Note: The parser inserts an ast.ParenExpr node; thus this case
// can only occur if the AST is created in a different way.
p.print(token.LPAREN)
- p.expr0(x, depth-1, multiLine) // parentheses undo one level of depth
+ p.expr0(x, reduceDepth(depth), multiLine) // parentheses undo one level of depth
p.print(token.RPAREN)
return
}
case *ast.ParenExpr:
p.print(token.LPAREN)
- p.expr0(x.X, depth-1, multiLine) // parentheses undo one level of depth
+ p.expr0(x.X, reduceDepth(depth), multiLine) // parentheses undo one level of depth
p.print(x.Rparen, token.RPAREN)
case *ast.SelectorExpr:
case *ast.LabeledStmt:
// a "correcting" unindent immediately following a line break
- // is applied before the line break if there is no comment
+ // is applied before the line break if there is no comment
// between (see writeWhitespace)
p.print(unindent)
p.expr(s.Label, multiLine)
p.expr(n, ignoreMultiLine)
case ast.Stmt:
p.useNodeComments = true
+ // A labeled statement will un-indent to position the
+ // label. Set indent to 1 so we don't get indent "underflow".
+ if _, labeledStmt := n.(*ast.LabeledStmt); labeledStmt {
+ p.indent = 1
+ }
p.stmt(n, ignoreMultiLine)
case ast.Decl:
p.useNodeComments = true