Professional Documents
Culture Documents
Anthony M. Sloane
Programming Languages Research Group
Department of Computing
Macquarie University
Sydney, Australia
http://www.comp.mq.edu.au/~asloane
https://wiki.mq.edu.au/display/plrg
Also useful:
Unparsing Expressions With Prefix and Postfix Operators
Norman Ramsey
SoftwarePractice and Experience, 28 (12), 1327-1356, Oct.1998
Basic Combinators
trait Doc {
def <> (e : Doc) : Doc
}
def
def
def
def
def
trait Doc {
def <+> (e : Doc) : Doc = this <> space <> e
}
implicit def stringToDoc (s : String) : Doc = text (s)
def value (v : Any) : Doc = string (v.toString)
def enclose (l : Doc, d : Doc, r : Doc) : Doc = l <> d <> r
def parens (d : Doc) : Doc = enclose (lparen, d, rparen)
def ssep (ds : Seq[Doc], sep : Doc) : Doc =
fold (ds, (_ <> sep <> _))
def product (p : Any) : Doc = ...
class
class
class
class
class
class
Num
Var
Neg
Add
Sub
Mul
(d
(s
(e
(l
(l
(l
:
:
:
:
:
:
class
class
class
class
Demo...
Implementation (1)
pretty
TreeCont
Indent
Width
Doc
Tree
Cont
TreeCont
Pos Dq
Remaining
Tree
Cont
Out
Out
""
0 emptyDq
0
Layout
w
Doc
Tree
Cont
Out
Implementation (2)
nest (d, j)
empty
l <> r
Code...
Downloads