@@ -77,10 +77,11 @@ object PrettyPrinter extends ParenPrettyPrinter {
77
77
// / TODO
78
78
hsep(t.args.map(toDoc), comma)
79
79
80
- def toDoc (b : Block ): Doc = b match {
80
+ def toDoc (b : Block , preventBraces : Boolean = false ): Doc = b match {
81
81
case BlockVar (id, _, _) => toDoc(id)
82
82
case BlockLit (tps, cps, vps, bps, body) =>
83
- braces { space <> paramsToDoc(tps, vps, bps) <+> " =>" <+> nest(line <> toDocStmts(body)) <> line }
83
+ val doc = space <> paramsToDoc(tps, vps, bps) <+> " =>" <+> nest(line <> toDocStmts(body)) <> line
84
+ if preventBraces then doc else braces { doc }
84
85
case Unbox (e) => parens(" unbox" <+> toDoc(e))
85
86
case New (handler) => " new" <+> toDoc(handler)
86
87
}
@@ -108,13 +109,17 @@ object PrettyPrinter extends ParenPrettyPrinter {
108
109
def argsToDoc (targs : List [core.ValueType ], vargs : List [core.Pure ], bargs : List [core.Block ]): Doc =
109
110
val targsDoc = if targs.isEmpty then emptyDoc else brackets(targs.map(toDoc))
110
111
// val cargsDoc = if cargs.isEmpty then emptyDoc else brackets(cargs.map(toDoc))
111
- val vargsDoc = vargs.map(toDoc)
112
- val bargsDoc = bargs.map(toDoc)
113
- targsDoc <> parens(vargsDoc ++ bargsDoc)
112
+ val vargsDoc = if vargs.isEmpty && ! bargs.isEmpty then emptyDoc else parens(vargs.map(toDoc))
113
+
114
+ // Wrap in braces individually, then concat with a space between. Force BlockLits to not add a layer of braces on top.
115
+ val bargsDoc = if bargs.isEmpty then emptyDoc else hcat { bargs.map { b => braces(toDoc(b, preventBraces = true )) } }
116
+ targsDoc <> vargsDoc <> bargsDoc
114
117
115
118
def paramsToDoc (tps : List [symbols.Symbol ], vps : List [ValueParam ], bps : List [BlockParam ]): Doc = {
116
- val tpsDoc = if (tps.isEmpty) emptyDoc else brackets(tps.map(toDoc))
117
- tpsDoc <> parens(hsep(vps map toDoc, comma)) <> hcat(bps map toDoc)
119
+ val tpsDoc = if tps.isEmpty then emptyDoc else brackets(tps.map(toDoc))
120
+ val vpsDoc = if vps.isEmpty && ! bps.isEmpty then emptyDoc else parens(vps.map(toDoc))
121
+ val bpsDoc = if bps.isEmpty then emptyDoc else hcat(bps.map(toDoc)) // already are in braces!
122
+ tpsDoc <> vpsDoc <> bpsDoc
118
123
}
119
124
120
125
def toDoc (instance : Implementation ): Doc = {
@@ -155,7 +160,7 @@ object PrettyPrinter extends ParenPrettyPrinter {
155
160
case Toplevel .Def (id, block) =>
156
161
" def" <+> toDoc(id) <+> " =" <+> toDoc(block)
157
162
case Toplevel .Val (id, _, binding) =>
158
- " vet " <+> toDoc(id) <+> " =" <+> toDoc(binding)
163
+ " let " <+> toDoc(id) <+> " =" <+> toDoc(binding)
159
164
}
160
165
161
166
def toDoc (s : Stmt ): Doc = s match {
0 commit comments