Commit 8d124068 authored by Stefan Plantikow's avatar Stefan Plantikow
Browse files

Reorganize Doc helpers for breaks and remove some dead code

parent 127ab3e6
Showing with 18 additions and 30 deletions
+18 -30
......@@ -37,7 +37,7 @@ sealed abstract class Doc {
override def toString = pformat(this, formatter = LineDocFormatter)(docStructureDocBuilder.docGenerator)
def ::(hd: Doc): Doc = cons(hd, this)
def :/:(hd: Doc): Doc = cons(hd, cons(breakHere, this))
def :/:(hd: Doc): Doc = cons(hd, cons(break, this))
def :?:(hd: Doc): Doc = replaceNil(hd, this)
def :+:(hd: Doc): Doc = appendWithBreak(hd, this)
......@@ -54,7 +54,6 @@ object Doc {
def replaceNil(head: Doc, tail: Doc) = tail match {
case NilDoc => head
case ConsDoc(NilDoc, next) => cons(head, next)
case other => tail
}
......@@ -66,7 +65,6 @@ object Doc {
else
tail match {
case NilDoc => head
case ConsDoc(NilDoc, next) => ConsDoc(head, ConsDoc(BreakDoc, next))
case other => ConsDoc(head, ConsDoc(BreakDoc, other))
}
......@@ -76,12 +74,13 @@ object Doc {
// breaks are either expanded to their value or a line break
def breakHere: Doc = BreakDoc
def breakWith(value: String): Doc = BreakWith(value)
val break: BreakingDoc = BreakDoc
val breakHere: BreakingDoc = BreakWith("")
def breakWith(value: String): BreakingDoc = BreakWith(value)
// useful to force a page break if a group is in PageMode and print nothing otherwise
def breakBefore(doc: Doc): Doc = if (doc == nil) nil else breakWith("") :: doc
def breakBefore(doc: Doc): Doc = if (doc == nil) nil else breakHere :: doc
// *all* breaks in a group are either expanded to their value or a line break
......@@ -106,9 +105,9 @@ object Doc {
implicit def list(docs: TraversableOnce[Doc]): Doc = docs.foldRight(nil)(cons)
def breakList(docs: TraversableOnce[Doc]): Doc = docs.foldRight(nil) {
def breakList(docs: TraversableOnce[Doc], break: BreakingDoc = break): Doc = docs.foldRight(nil) {
case (hd, NilDoc) => hd :: nil
case (hd, tail) => hd :/: tail
case (hd, tail) => hd :: break :: tail
}
def breakBeforeList(docs: TraversableOnce[Doc]): Doc = docs.foldRight(nil) {
......@@ -116,9 +115,9 @@ object Doc {
case (hd, tail) => hd :: breakBefore(tail)
}
def sepList(docs: TraversableOnce[Doc], sep: Doc = ","): Doc = docs.foldRight(nil) {
def sepList(docs: TraversableOnce[Doc], sep: Doc = ",", break: BreakingDoc = break): Doc = docs.foldRight(nil) {
case (hd, NilDoc) => hd :: nil
case (hd, tail) => hd :: sep :/: tail
case (hd, tail) => hd :: sep :: break :: tail
}
def block(name: Doc, open: Doc = "(", close: Doc = ")")(innerDoc: Doc): Doc =
......
......@@ -38,7 +38,7 @@ object logicalPlanDocBuilder extends CachingDocBuilder[Any] {
.filter( (v: Any) => !childPlans.contains(v) )
.map(inner)
val deps = sepList(plan.availableSymbols.map(inner))
val deps = sepList(plan.availableSymbols.map(inner), break = breakHere)
val depsBlock = block(plan.productPrefix, open = "[", close = "]")(deps)
val head = block(depsBlock)(sepList(arguments))
......
......@@ -57,8 +57,7 @@ case object plannerDocBuilder extends DocBuilderChain[Any] {
val forNestedPredicate = asDocBuilder[Any] {
case Predicate(dependencies, expr) => (inner) =>
val pred = sepList(dependencies.map(inner))
val pred = sepList(dependencies.map(inner), break = breakHere)
val predBlock = block("Predicate", open = "[", close = "]")(pred)
block(predBlock)(inner(expr))
}
......
......@@ -38,7 +38,7 @@ class DocTest extends CypherFunSuite {
}
test("break == BreakDoc") {
breakHere should equal(BreakDoc)
break should equal(BreakDoc)
}
test("breakWith(v) == BreakWith(v)") {
......@@ -73,15 +73,10 @@ class DocTest extends CypherFunSuite {
text("a") :?: nil should equal(text("a"))
}
test("a :?: ConsDoc(nil, b) => a :: b") {
text("a") :?: ConsDoc(nil, text("b")) should equal(text("a") :: text("b"))
}
test("a :?: b => b") {
text("a") :?: text("b") should equal(text("b"))
}
test("nil :+: a => a") {
nil :+: text("a") should equal(text("a"))
}
......@@ -90,10 +85,6 @@ class DocTest extends CypherFunSuite {
text("a") :+: nil should equal(text("a"))
}
test("a :+: ConsDoc(nil, b) => a :/: b") {
text("a") :+: ConsDoc(nil, text("b")) should equal(text("a") :/: text("b"))
}
test("a :+: b => a :/: b") {
text("a") :+: text("b") should equal(text("a") :/: text("b"))
}
......
......@@ -32,7 +32,7 @@ class DocStructureDocBuilderTest extends DocGeneratorTestSuite[Doc] {
}
test("break => \"_\"") {
format(breakHere) should equal("_")
format(break) should equal("_")
}
test("breakWith(...) => \"_..._\"") {
......
......@@ -22,7 +22,6 @@ package org.neo4j.cypher.internal.compiler.v2_1.pprint.docbuilders
import org.neo4j.cypher.internal.compiler.v2_1.pprint._
import org.neo4j.cypher.internal.compiler.v2_1.planner.logical.plans.{LogicalPlan, IdName, LogicalLeafPlan}
import org.neo4j.cypher.internal.compiler.v2_1.planner.logical.plans.IdName
import scala.Some
import org.neo4j.cypher.internal.compiler.v2_1.pprint.PrintNewLine
import org.neo4j.cypher.internal.compiler.v2_1.pprint.PrintText
......@@ -62,7 +61,7 @@ class LogicalPlanDocBuilderTest extends DocBuilderTestSuite[Any] {
val doc = docGen(TestComboPlan(TestLeafPlan(1), TestLeafPlan(2)))
val result = condense(defaultFormatter(doc))
result should equal(Seq(
PrintText("TestComboPlan[c, d]()"),
PrintText("TestComboPlan[c,d]()"),
PrintNewLine(2),
PrintText("↳ left = TestLeafPlan[a](1)"),
PrintNewLine(2),
......
......@@ -39,7 +39,7 @@ class LineDocFormatterTest extends CypherFunSuite {
}
test("format BreakDoc") {
LineDocFormatter(breakHere) should equal(Seq(PrintText(" ")))
LineDocFormatter(break) should equal(Seq(PrintText(" ")))
}
test("format BreakWith") {
......
......@@ -41,8 +41,8 @@ class LineFitterTest extends CypherFunSuite {
}
test("fits breaks") {
LineFitter.fitsDoc(1, breakHere) should equal(true)
LineFitter.fitsDoc(0, breakHere) should equal(false)
LineFitter.fitsDoc(1, break) should equal(true)
LineFitter.fitsDoc(0, break) should equal(false)
}
test("fits breakWith") {
......
......@@ -39,7 +39,7 @@ class PageDocFormatterTest extends CypherFunSuite {
}
test("format BreakDoc") {
PageDocFormatter(10)(breakHere) should equal(Seq(PrintText(" ")))
PageDocFormatter(10)(break) should equal(Seq(PrintText(" ")))
}
test("format BreakWith") {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment