-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
272 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Website | ||
on: | ||
push: | ||
branches: [main] | ||
tags: ["*"] | ||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- uses: olafurpg/setup-scala@v10 | ||
with: | ||
java-version: [email protected] | ||
- uses: olafurpg/setup-gpg@v3 | ||
- run: sbt docs/docusaurusPublishGhpages | ||
env: | ||
GIT_DEPLOY_KEY: ${{ secrets.GIT_DEPLOY_KEY }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 16 additions & 16 deletions
32
src/asciidoctor/index.adoc → modules/document/src/asciidoctor/index.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
= Document library | ||
|
||
This project contains code that was developed as part of the Scala standard library but was later deprecated. | ||
|
||
A basic pretty-printing library, based on | ||
https://lindig.github.io/papers/strictly-pretty-2000.pdf[Lindig's strict version] of | ||
https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf[Wadler's adaptation] of | ||
http://www.cse.chalmers.se/~rjmh/Papers/pretty.html[Hughes' pretty-printer] derived from | ||
https://github.com/scala/scala/blob/v2.11.8/src/library/scala/text/Document.scala[Document.scala] whose original author was | ||
https://people.epfl.ch/michel.schinz[Michel Schinz] | ||
|
||
We maintain it because we had some code using it and because we want an experimental simple Scala code library to test documentation. | ||
|
||
== ScalaDoc | ||
|
||
link:latest/api/es/weso/document/Document.html[ScalaDoc] | ||
= Document library | ||
|
||
This project contains code that was developed as part of the Scala standard library but was later deprecated. | ||
|
||
A basic pretty-printing library, based on | ||
https://lindig.github.io/papers/strictly-pretty-2000.pdf[Lindig's strict version] of | ||
https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf[Wadler's adaptation] of | ||
http://www.cse.chalmers.se/~rjmh/Papers/pretty.html[Hughes' pretty-printer] derived from | ||
https://github.com/scala/scala/blob/v2.11.8/src/library/scala/text/Document.scala[Document.scala] whose original author was | ||
https://people.epfl.ch/michel.schinz[Michel Schinz] | ||
|
||
We maintain it because we had some code using it and because we want an experimental simple Scala code library to test documentation. | ||
|
||
== ScalaDoc | ||
|
||
link:latest/api/es/weso/document/Document.html[ScalaDoc] |
270 changes: 135 additions & 135 deletions
270
...ain/scala/es/weso/document/Document.scala → ...ain/scala/es/weso/document/Document.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,136 @@ | ||
package es.weso.document | ||
|
||
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. | ||
* | ||
* Derived from [[https://github.com/scala/scala/blob/v2.11.8/src/library/scala/text/Document.scala]] | ||
* @author Michel Schinz | ||
*/ | ||
sealed abstract class Document extends Product with Serializable { | ||
|
||
/*Join two documents.*/ | ||
def ::(hd: Document): Document = DocCons(hd, this) | ||
|
||
/*Join a document and a String.*/ | ||
def ::(hd: String): Document = DocCons(DocText(hd), this) | ||
|
||
/*Join two documents with a line break.*/ | ||
def :/:(hd: Document): Document = hd :: DocBreak :: this | ||
|
||
/*Join a document and a String with a line break.*/ | ||
def :/:(hd: String): Document = hd :: DocBreak :: this | ||
|
||
/** | ||
* Format this document on `writer` and try to set line | ||
* breaks so that the result fits in `width` columns. | ||
*/ | ||
def format(width: Int, writer: Writer): Unit = { | ||
|
||
type FmtState = (Int, Boolean, Document) | ||
|
||
def fits(width: Int, state: List[FmtState]): Boolean = state match { | ||
|
||
case _ if width < 0 => | ||
false | ||
|
||
case List() => | ||
true | ||
|
||
case (_, _, DocNil) :: z => | ||
fits(width, z) | ||
|
||
case (i, b, DocCons(h, t)) :: z => | ||
fits(width, (i,b,h) :: (i,b,t) :: z) | ||
|
||
case (_, _, DocText(t)) :: z => | ||
fits(width - t.length(), z) | ||
|
||
case (i, b, DocNest(ii, d)) :: z => | ||
fits(width, (i + ii, b, d) :: z) | ||
|
||
case (_, false, DocBreak) :: z => | ||
fits(width - 1, z) | ||
|
||
case (_, true, DocBreak) :: z => | ||
true | ||
|
||
case (i, _, DocGroup(d)) :: z => | ||
fits(width, (i, false, d) :: z) | ||
} | ||
|
||
def spaces(n: Int): Unit = { | ||
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) | ||
|
||
// case null => () | ||
} | ||
|
||
fmt(0, (0, false, DocGroup(this)) :: Nil) | ||
} | ||
} | ||
|
||
object Document { | ||
|
||
/** The empty document */ | ||
def empty: Document = DocNil | ||
|
||
/** A break, which will either be turned into a space or a line break */ | ||
def break: Document = DocBreak | ||
|
||
/** A document consisting of some text literal */ | ||
def text(s: String): Document = DocText(s) | ||
|
||
/** | ||
* A group of documents, 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) | ||
package es.weso.document | ||
|
||
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. | ||
* | ||
* Derived from [[https://github.com/scala/scala/blob/v2.11.8/src/library/scala/text/Document.scala]] | ||
* @author Michel Schinz | ||
*/ | ||
sealed abstract class Document extends Product with Serializable { | ||
|
||
/*Join two documents.*/ | ||
def ::(hd: Document): Document = DocCons(hd, this) | ||
|
||
/*Join a document and a String.*/ | ||
def ::(hd: String): Document = DocCons(DocText(hd), this) | ||
|
||
/*Join two documents with a line break.*/ | ||
def :/:(hd: Document): Document = hd :: DocBreak :: this | ||
|
||
/*Join a document and a String with a line break.*/ | ||
def :/:(hd: String): Document = hd :: DocBreak :: this | ||
|
||
/** | ||
* Format this document on `writer` and try to set line | ||
* breaks so that the result fits in `width` columns. | ||
*/ | ||
def format(width: Int, writer: Writer): Unit = { | ||
|
||
type FmtState = (Int, Boolean, Document) | ||
|
||
def fits(width: Int, state: List[FmtState]): Boolean = state match { | ||
|
||
case _ if width < 0 => | ||
false | ||
|
||
case List() => | ||
true | ||
|
||
case (_, _, DocNil) :: z => | ||
fits(width, z) | ||
|
||
case (i, b, DocCons(h, t)) :: z => | ||
fits(width, (i,b,h) :: (i,b,t) :: z) | ||
|
||
case (_, _, DocText(t)) :: z => | ||
fits(width - t.length(), z) | ||
|
||
case (i, b, DocNest(ii, d)) :: z => | ||
fits(width, (i + ii, b, d) :: z) | ||
|
||
case (_, false, DocBreak) :: z => | ||
fits(width - 1, z) | ||
|
||
case (_, true, DocBreak) :: z => | ||
true | ||
|
||
case (i, _, DocGroup(d)) :: z => | ||
fits(width, (i, false, d) :: z) | ||
} | ||
|
||
def spaces(n: Int): Unit = { | ||
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) | ||
|
||
// case null => () | ||
} | ||
|
||
fmt(0, (0, false, DocGroup(this)) :: Nil) | ||
} | ||
} | ||
|
||
object Document { | ||
|
||
/** The empty document */ | ||
def empty: Document = DocNil | ||
|
||
/** A break, which will either be turned into a space or a line break */ | ||
def break: Document = DocBreak | ||
|
||
/** A document consisting of some text literal */ | ||
def text(s: String): Document = DocText(s) | ||
|
||
/** | ||
* A group of documents, 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) | ||
} |
Oops, something went wrong.