source: project/wiki/eggref/3/strictly-pretty @ 13621

Last change on this file since 13621 was 13621, checked in by sjamaan, 11 years ago

Move old chicken 3 eggs over to eggref/3

File size: 5.2 KB
Line 
1[[tags: egg]]
2
3== Introduction
4
5The {{strictly-pretty}} library is an implementation of the algebraic
6pretty printer described by Christian Lindig in his paper
7[[http://citeseer.ist.psu.edu/lindig00strictly.html|Strictly Pretty]].
8
9== Requires
10
11; [[datatype]]
12
13== Library procedures
14
15=== {{doc?:: OBJECT -> BOOL}}
16
17A predicate that returns true if the given argument is a
18pretty-printer object constructed with the procedures in this library.
19
20=== {{doc:empty?:: DOC -> BOOL}}
21
22Returns true if the given document object is empty, false otherwise.
23
24=== {{doc:empty:: () -> DOC}}
25
26Returns an empty document object.
27
28=== {{doc:cons:: DOC * DOC -> DOC}}
29
30Returns a document object that contains the concatenated pair of
31documents.
32
33
34=== {{doc:text:: STRING -> DOC}}
35
36Returns a document object that contains the given string.
37
38=== {{doc:nest:: INDENT * DOC -> DOC}}
39
40Returns an inner document group that contains the given document,
41which will be broken up at the given indentation.
42
43
44=== {{doc:break:: () -> DOC}}
45
46Returns an optional line break object.
47
48
49=== {{doc:break-with:: STRING -> DOC}}
50
51Returns an optional line break object that uses the given string to
52delimit the break.
53
54=== {{doc:group:: DOC -> DOC}}
55
56Returns a document group that contains the given document.
57
58=== {{doc:concat:: LST -> DOC}}
59
60Concatenates the documents in the given list.
61
62=== {{doc:binop:: INDENT -> LEFT * OPER * RIGHT -> DOC}}
63
64A parameterizable formatter for infix binary operation
65expressions. Given an indentation level {{INDENT}}, returns a
66procedure that takes a left operand (document object), operator
67(string), and a right operand (document object) and returns a document
68object that contains the formatted expression.
69
70
71=== {{doc:ifthen:: INDENT * IF * THEN * ELSE -> COND * IFTRUE * IFFALSE -> DOC}}
72
73A parameterizable formatter for if-then-else expressions. Given an
74indentation level {{INDENT}}, and document objects that represent
75{{if,then,else}} keywords, respectively, returns a procedure that
76takes a condition (document object), true branch (string), and false
77branch (document object) and returns a document object that contains
78the formatted expression.
79
80=== {{doc:list:: INDENT * ELEM->DOC * SEP -> LST -> DOC}}
81
82A parameterizable formatter for list expressions. Given an indentation
83level {{INDENT}}, a procedure that creates document object
84representations of the elements of the list, and a document object
85that represents the list element separator, returns a procedure that
86takes a list of elements and returns a document object that contains
87the formatted expression.
88
89
90=== {{doc:block:: INDENT * OPEN * CLOSE -> BODY -> DOC}}
91
92A parameterizable formatter for block expressions. Given an
93indentation level {{INDENT}}, and document objects that represent
94block open and close markers, returns a procedure that takes a
95document object and returns a new document object that encloses the
96given object in a block.
97
98
99=== {{doc:letblk:: INDENT * LET * IN * END -> E1 * E2 -> DOC}}
100
101A parameterizable formatter for let expressions (local binding). Given
102an indentation level {{INDENT}}, and document objects that represent
103{{let,in,end}} keywords, respectively, returns a procedure that takes
104bindings block (document object) and body block (document object) and
105returns a document object that contains the formatted expression.
106
107===  {{doc:display:: WIDTH * DOC -> UNDEFINED}}
108
109Formatted display procedure.
110
111===  {{doc:format:: WIDTH * DOC -> SDOC}}
112
113A procedure that generates simple document representation of the given
114document object.
115
116=== {{sdoc?:: OBJECT -> BOOL}}
117
118A predicate that returns true if the given argument is a
119simple document object.
120
121
122=== {{sdoc->string:: SDOC -> STRING}}
123
124Generates string representation of the given simple document object.
125
126== Example
127
128<enscript highlight="scheme">
129(define cond1 ((doc:binop 2) (doc:text "a") (doc:text "==") (doc:text "b")))
130(define e1    ((doc:binop 2) (doc:text "a") (doc:text "<<") (doc:text "2")))
131(define e2    ((doc:binop 2) (doc:text "c") (doc:text "+") (doc:text "d")))
132
133(define doc1 ((doc:ifthen 2 (doc:text "if") (doc:text "then") (doc:text "else"))
134              cond1 e1 e2))
135
136(define doc2 ((doc:block 2 (doc:text "(") (doc:text ")")) doc1))
137
138(define doc3 ((doc:list 2 (lambda (x) x) doc:break) (list e1 e2)))
139(define doc4 ((doc:letblk 2 (doc:text "program") (doc:text "in") (doc:text "end"))
140              doc3 doc1))
141
142(print (sdoc->string (doc:format 32 doc4)))
143
144(print (sdoc->string (doc:format 10 doc4)))
145</enscript>
146
147== Authors
148
149Ivan Raikov
150
151== Version
152
153; 1.3 : Added doc:empty? procedure
154; 1.2 : Now using matchable extension
155; 1.1 : Added doc:connect to list of exports
156; 1.0 : Initial version
157
158== License
159
160Copyright 2008 Ivan Raikov and the Okinawa Institute of Science and
161Technology.
162
163This program is free software: you can redistribute it and/or modify
164it under the terms of the GNU General Public License as published by
165the Free Software Foundation, either version 3 of the License, or (at
166your option) any later version.
167
168This program is distributed in the hope that it will be useful, but
169WITHOUT ANY WARRANTY; without even the implied warranty of
170MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
171General Public License for more details.
172
173A full copy of the GPL license can be found at
174<http://www.gnu.org/licenses/>.
Note: See TracBrowser for help on using the repository browser.