Skip to content

Commit 8d8c03f

Browse files
committed
Print quotes with ' rather than Expr.apply
Also add coloring for clearer visualization of the code
1 parent 845fd59 commit 8d8c03f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
318318
if (name.isTypeName) typeText(txt)
319319
else txt
320320
case tree @ Select(qual, name) =>
321-
if (qual.isType) toTextLocal(qual) ~ "#" ~ typeText(toText(name))
321+
if (tree.symbol == defn.QuotedExpr_~ || tree.symbol == defn.QuotedType_~) keywordStr("~(") ~ toTextLocal(qual) ~ keywordStr(")")
322+
else if (qual.isType) toTextLocal(qual) ~ "#" ~ typeText(toText(name))
322323
else toTextLocal(qual) ~ ("." ~ nameIdText(tree) provided name != nme.CONSTRUCTOR)
323324
case tree: This =>
324325
optDotPrefix(tree) ~ keywordStr("this") ~ idText(tree)
@@ -329,6 +330,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
329330
changePrec (GlobalPrec) {
330331
keywordStr("throw ") ~ toText(args.head)
331332
}
333+
else if (fun.symbol == defn.QuotedExpr_apply)
334+
keywordStr("'{") ~ toTextGlobal(args, ", ") ~ keywordStr("}")
335+
else if (fun.symbol == defn.QuotedType_apply)
336+
keywordStr("'[") ~ toTextGlobal(args, ", ") ~ keywordStr("]")
332337
else
333338
toTextLocal(fun) ~ "(" ~ toTextGlobal(args, ", ") ~ ")"
334339
case tree: TypeApply =>

0 commit comments

Comments
 (0)