Skip to content

Commit 9a8d214

Browse files
committed
Make infix tree-print correctly
1 parent e021ee6 commit 9a8d214

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

quill-engine/src/main/scala/io/getquill/AstPrinter.scala

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ object AstPrinter {
1818
}
1919
}
2020

21-
class AstPrinter(traceOpinions: Boolean, traceAstSimple: Boolean, traceQuats: QuatTrace) extends pprint.Walker {
21+
class AstPrinter(
22+
traceOpinions: Boolean = false,
23+
traceAstSimple: Boolean = false,
24+
traceQuats: QuatTrace = QuatTrace.None
25+
) extends pprint.Walker {
2226
val defaultWidth: Int = 150
2327
val defaultHeight: Int = Integer.MAX_VALUE
2428
val defaultIndent: Int = 2
@@ -83,7 +87,8 @@ class AstPrinter(traceOpinions: Boolean, traceAstSimple: Boolean, traceQuats: Qu
8387
def apply(list: Any*): treemake = Content(list.toList.map(Elem.apply))
8488
}
8589

86-
override def treeify(x: Any, escapeUnicode: Boolean, showFieldNames: Boolean): Tree =
90+
override def treeify(x: Any, escapeUnicode: Boolean, showFieldNames: Boolean): Tree = {
91+
def treeify1(x: Any) = treeify(x, escapeUnicode, showFieldNames)
8792
x match {
8893
case ast: Ast if (traceAstSimple) =>
8994
Tree.Literal("" + ast) // Do not blow up if it is null
@@ -117,7 +122,16 @@ class AstPrinter(traceOpinions: Boolean, traceAstSimple: Boolean, traceQuats: Qu
117122

118123
case s: ScalarValueLift => Tree.Apply("ScalarValueLift", treemake(s.name, s.source).withQuat(s.bestQuat).make)
119124

120-
case p: Property if (traceOpinions) =>
125+
case i: Infix =>
126+
TreeApplyList(
127+
"Infix",
128+
List(
129+
Tree.KeyValue("parts", ltree(i.parts.map(treeify1(_)))),
130+
Tree.KeyValue("params", ltree(i.params.map(treeify1(_))))
131+
)
132+
)
133+
134+
case p: Property =>
121135
TreeApplyList(
122136
"Property",
123137
l(treeify(p.ast, escapeUnicode, showFieldNames)) ++ l(treeify(p.name, escapeUnicode, showFieldNames)) ++
@@ -153,10 +167,12 @@ class AstPrinter(traceOpinions: Boolean, traceAstSimple: Boolean, traceQuats: Qu
153167

154168
case _ => super.treeify(x, escapeUnicode, showFieldNames)
155169
}
170+
}
156171

157172
private def TreeApplyList(prefix: String, body: List[Tree]) = Tree.Apply(prefix, body.iterator)
158173

159174
private def l(trees: Tree*): List[Tree] = List[Tree](trees: _*)
175+
private def ltree(trees: List[Tree]) = Tree.Apply("List", trees.iterator)
160176

161177
def apply(x: Any): fansi.Str =
162178
fansi.Str.join(this.tokenize(x).toSeq)

0 commit comments

Comments
 (0)