summaryrefslogtreecommitdiff
path: root/src/library/scala/text/Document.scala
diff options
context:
space:
mode:
authorGeoffrey Washburn <geoffrey.washburn@epfl.ch>2008-04-04 12:09:06 +0000
committerGeoffrey Washburn <geoffrey.washburn@epfl.ch>2008-04-04 12:09:06 +0000
commitcb9f5470c9a9dabdc334b234c9c6b6fd17237198 (patch)
treed0e48d83f2a9e916c9f682160920c621dbf457d6 /src/library/scala/text/Document.scala
parent0cda1dec3f2ec23c181b17dbb0f59299bab89430 (diff)
downloadscala-cb9f5470c9a9dabdc334b234c9c6b6fd17237198.tar.gz
scala-cb9f5470c9a9dabdc334b234c9c6b6fd17237198.tar.bz2
scala-cb9f5470c9a9dabdc334b234c9c6b6fd17237198.zip
The great library reorg!
The standard library will now be laid out approximately like this library/scala /jvm/scala /jvm/jvm1.4/scala /jvm/jvm1.5/scala /jvm/android/scala /jvm/cldc/scala /dotnet/scala To build the standard library for a given target you start by copying the root library/scala tree to a staging area, then move down in the hierarchy copying the nested "scala" trees on top in the staging area. So if you wanted to build for cldc, for example, you would do something like the following: rsync -avz library/scala staging/ rsync -avz library/scala/jvm/scala staging/ rsync -avz library/scala/jvm/cldc/scala staging/ The ant build files will be updated to do this for you automagically, and there will soon be shell script to do this if you want to compile some parts of the standard library manually.
Diffstat (limited to 'src/library/scala/text/Document.scala')
-rw-r--r--src/library/scala/text/Document.scala122
1 files changed, 0 insertions, 122 deletions
diff --git a/src/library/scala/text/Document.scala b/src/library/scala/text/Document.scala
deleted file mode 100644
index 39aea9ec81..0000000000
--- a/src/library/scala/text/Document.scala
+++ /dev/null
@@ -1,122 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.text
-
-
-import java.io.Writer
-
-case object DocNil extends Document
-case object DocBreak extends Document
-case class DocText(txt: String) extends Document
-case class DocGroup(doc: Document) extends Document
-case class DocNest(indent: Int, doc: Document) extends Document
-case class DocCons(hd: Document, tl: Document) extends Document
-
-/**
- * A basic pretty-printing library, based on Lindig's strict version
- * of Wadler's adaptation of Hughes' pretty-printer.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-abstract class Document {
- def ::(hd: Document): Document = DocCons(hd, this)
- def ::(hd: String): Document = DocCons(DocText(hd), this)
- def :/:(hd: Document): Document = hd :: DocBreak :: this
- def :/:(hd: String): Document = hd :: DocBreak :: this
-
- /**
- * Format this document on <code>writer</code> and try to set line
- * breaks so that the result fits in <code>width</code> columns.
- *
- * @param width ...
- * @param writer ...
- */
- def format(width: Int, writer: Writer) {
- type FmtState = (Int, Boolean, Document)
-
- def fits(w: Int, state: List[FmtState]): Boolean = state match {
- case _ if w < 0 =>
- false
- case List() =>
- true
- case (_, _, DocNil) :: z =>
- fits(w, z)
- case (i, b, DocCons(h, t)) :: z =>
- fits(w, (i,b,h) :: (i,b,t) :: z)
- case (_, _, DocText(t)) :: z =>
- fits(w - t.length(), z)
- case (i, b, DocNest(ii, d)) :: z =>
- fits(w, (i + ii, b, d) :: z)
- case (_, false, DocBreak) :: z =>
- fits(w - 1, z)
- case (_, true, DocBreak) :: z =>
- true
- case (i, _, DocGroup(d)) :: z =>
- fits(w, (i, false, d) :: z)
- }
-
- def spaces(n: Int) {
- var rem = n
- while (rem >= 16) { writer write " "; rem -= 16 }
- if (rem >= 8) { writer write " "; rem -= 8 }
- if (rem >= 4) { writer write " "; rem -= 4 }
- if (rem >= 2) { writer write " "; rem -= 2}
- if (rem == 1) { writer write " " }
- }
-
- def fmt(k: Int, state: List[FmtState]): Unit = state match {
- case List() => ()
- case (_, _, DocNil) :: z =>
- fmt(k, z)
- case (i, b, DocCons(h, t)) :: z =>
- fmt(k, (i, b, h) :: (i, b, t) :: z)
- case (i, _, DocText(t)) :: z =>
- writer write t
- fmt(k + t.length(), z)
- case (i, b, DocNest(ii, d)) :: z =>
- fmt(k, (i + ii, b, d) :: z)
- case (i, true, DocBreak) :: z =>
- writer write "\n"
- spaces(i);
- fmt(i, z)
- case (i, false, DocBreak) :: z =>
- writer write " "
- fmt(k + 1, z)
- case (i, b, DocGroup(d)) :: z =>
- val fitsFlat = fits(width - k, (i, false, d) :: z)
- fmt(k, (i, !fitsFlat, d) :: z)
- }
-
- fmt(0, (0, false, DocGroup(this)) :: Nil)
- }
-}
-
-object Document {
- /** The empty document */
- def empty = DocNil
-
- /** A break, which will either be turned into a space or a line break */
- def break = DocBreak
-
- /** A document consisting of some text literal */
- def text(s: String): Document = DocText(s)
-
- /**
- * A group, whose components will either be printed with all breaks
- * rendered as spaces, or with all breaks rendered as line breaks.
- */
- def group(d: Document): Document = DocGroup(d)
-
- /** A nested document, which will be indented as specified. */
- def nest(i: Int, d: Document): Document = DocNest(i, d)
-}