chickadee » strictly-pretty

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

strictly-pretty

Introduction

The strictly-pretty library is an implementation of the algebraic pretty printer described by Christian Lindig in his paper Strictly Pretty.

Library procedures

doc?:procedure

A predicate that returns true if the given argument is a pretty-printer object constructed with the procedures in this library.

doc:empty?:procedure

Returns true if the given document object is empty, false otherwise.

doc:empty:procedure

Returns an empty document object.

doc:cons:procedure

Returns a document object that contains the concatenated pair of documents.

doc:text:procedure

Returns a document object that contains the given string.

doc:nest:procedure

Returns an inner document group that contains the given document, which will be broken up at the given indentation.

doc:break:procedure

Returns an optional line break object.

doc:break-with:procedure

Returns an optional line break object that uses the given string to delimit the break.

doc:group:procedure

Returns a document group that contains the given document.

doc:concat:procedure

Concatenates the documents in the given list.

doc:binop:procedure

A parameterizable formatter for infix binary operation expressions. Given an indentation level INDENT, returns a procedure that takes a left operand (document object), operator (string), and a right operand (document object) and returns a document object that contains the formatted expression.

doc:ifthen:procedure

A parameterizable formatter for if-then-else expressions. Given an indentation level INDENT, and document objects that represent if,then,else keywords, respectively, returns a procedure that takes a condition (document object), true branch (string), and false branch (document object) and returns a document object that contains the formatted expression.

doc:list:procedure

A parameterizable formatter for list expressions. Given an indentation level INDENT, a procedure that creates document object representations of the elements of the list, and a document object that represents the list element separator, returns a procedure that takes a list of elements and returns a document object that contains the formatted expression.

doc:block:procedure

A parameterizable formatter for block expressions. Given an indentation level INDENT, and document objects that represent block open and close markers, returns a procedure that takes a document object and returns a new document object that encloses the given object in a block.

doc:letblk:procedure

A parameterizable formatter for let expressions (local binding). Given an indentation level INDENT, and document objects that represent let,in,end keywords, respectively, returns a procedure that takes bindings block (document object) and body block (document object) and returns a document object that contains the formatted expression.

doc:display:procedure

Formatted display procedure.

doc:format:procedure

A procedure that generates simple document representation of the given document object.

sdoc?:procedure

A predicate that returns true if the given argument is a simple document object.

sdoc->string:procedure

Generates string representation of the given simple document object.

Example

(define cond1 ((doc:binop 2) (doc:text "a") (doc:text "==") (doc:text "b")))
(define e1    ((doc:binop 2) (doc:text "a") (doc:text "<<") (doc:text "2")))
(define e2    ((doc:binop 2) (doc:text "c") (doc:text "+") (doc:text "d")))

(define doc1 ((doc:ifthen 2 (doc:text "if") (doc:text "then") (doc:text "else"))
	      cond1 e1 e2))

(define doc2 ((doc:block 2 (doc:text "(") (doc:text ")")) doc1))

(define doc3 ((doc:list 2 (lambda (x) x) doc:break) (list e1 e2)))
(define doc4 ((doc:letblk 2 (doc:text "program") (doc:text "in") (doc:text "end"))
	      doc3 doc1))

(print (sdoc->string (doc:format 32 doc4)))

(print (sdoc->string (doc:format 10 doc4)))

Author

Ivan Raikov

Version

1.4
Ported to Chicken 4
1.3
Added doc:empty? procedure
1.2
Now using matchable extension
1.1
Added doc:connect to list of exports
1.0
Initial version

License

Copyright 2008-2010 Ivan Raikov and the Okinawa Institute of Science
and Technology.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details. 

A full copy of the GPL license can be found at
<http://www.gnu.org/licenses/>.

Contents »