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

  1. Outdated egg!
  2. strictly-pretty
    1. Introduction
    2. Library procedures
    3. Example
    4. Author
    5. Version
    6. License

Introduction

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

Library procedures

[procedure] doc?:: OBJECT -> BOOL

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

[procedure] doc:empty?:: DOC -> BOOL

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

[procedure] doc:empty:: () -> DOC

Returns an empty document object.

[procedure] doc:cons:: DOC * DOC -> DOC

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

[procedure] doc:text:: STRING -> DOC

Returns a document object that contains the given string.

[procedure] doc:nest:: INDENT * DOC -> DOC

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

[procedure] doc:break:: () -> DOC

Returns an optional line break object.

[procedure] doc:break-with:: STRING -> DOC

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

[procedure] doc:group:: DOC -> DOC

Returns a document group that contains the given document.

[procedure] doc:concat:: LST -> DOC

Concatenates the documents in the given list.

[procedure] doc:binop:: INDENT -> LEFT * OPER * RIGHT -> DOC

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.

[procedure] doc:ifthen:: INDENT * IF * THEN * ELSE -> COND * IFTRUE * IFFALSE -> DOC

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.

[procedure] doc:list:: INDENT * ELEM->DOC * SEP -> LST -> DOC

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.

[procedure] doc:block:: INDENT * OPEN * CLOSE -> BODY -> DOC

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.

[procedure] doc:letblk:: INDENT * LET * IN * END -> E1 * E2 -> DOC

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.

[procedure] doc:display:: WIDTH * DOC -> UNDEFINED

Formatted display procedure.

[procedure] doc:format:: WIDTH * DOC -> SDOC

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

[procedure] sdoc?:: OBJECT -> BOOL

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

[procedure] sdoc->string:: SDOC -> STRING

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/>.