diff options
author | Martin Odersky <odersky@gmail.com> | 2013-05-17 13:28:02 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-05-17 13:28:02 +0200 |
commit | 94b9a2a0d083cca2ba1358582d8d6fd8143b0b31 (patch) | |
tree | e84279f763b7a241bf18c27c7227d66618936719 /src/dotty/tools/dotc/printing/Texts.scala | |
parent | d2261b37cf23ccd04e9029f3556c2dc9e2bdf077 (diff) | |
download | dotty-94b9a2a0d083cca2ba1358582d8d6fd8143b0b31.tar.gz dotty-94b9a2a0d083cca2ba1358582d8d6fd8143b0b31.tar.bz2 dotty-94b9a2a0d083cca2ba1358582d8d6fd8143b0b31.zip |
Refactored Printing architecture.
Split printers into several files. Added refined printing of trees. Changed Showable and generalized printing
under a precedence.
Diffstat (limited to 'src/dotty/tools/dotc/printing/Texts.scala')
-rw-r--r-- | src/dotty/tools/dotc/printing/Texts.scala | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/printing/Texts.scala b/src/dotty/tools/dotc/printing/Texts.scala index 2ff4edc9a..8c214f5f0 100644 --- a/src/dotty/tools/dotc/printing/Texts.scala +++ b/src/dotty/tools/dotc/printing/Texts.scala @@ -1,5 +1,6 @@ package dotty.tools.dotc package printing +import core.Contexts.Context object Texts { @@ -128,15 +129,28 @@ object Texts { def over (that: Text) = if (this.isVertical) Vertical(that :: this.relems) else Vertical(that :: this :: Nil) + + def provided(pred: => Boolean) = if (pred) this else Str("") } object Text { + + /** The empty text */ def apply(): Text = Str("") + + /** A concatenation of elements in `xs` and interspersed with + * separator strings `sep`. + */ def apply(xs: Traversable[Text], sep: String = " "): Text = { - val ys = xs filterNot (_.isEmpty) - if (ys.isEmpty) Str("") - else ys reduce (_ ~ sep ~ _) + if (sep == "\n") lines(xs) + else { + val ys = xs filterNot (_.isEmpty) + if (ys.isEmpty) Str("") + else ys reduce (_ ~ sep ~ _) + } } + + /** The given texts `xs`, each on a separate line */ def lines(xs: Traversable[Text]) = Vertical(xs.toList.reverse) } |