package frama-c
Install
dune-project
Dependency
Authors
-
MMichele Alberti
-
TThibaud Antignac
-
GGergö Barany
-
PPatrick Baudin
-
NNicolas Bellec
-
TThibaut Benjamin
-
AAllan Blanchard
-
LLionel Blatter
-
FFrançois Bobot
-
RRichard Bonichon
-
VVincent Botbol
-
QQuentin Bouillaguet
-
DDavid Bühler
-
ZZakaria Chihani
-
SSylvain Chiron
-
LLoïc Correnson
-
JJulien Crétin
-
PPascal Cuoq
-
ZZaynah Dargaye
-
BBasile Desloges
-
JJean-Christophe Filliâtre
-
PPhilippe Herrmann
-
MMaxime Jacquemin
-
BBenjamin Jorge
-
FFlorent Kirchner
-
AAlexander Kogtenkov
-
RRemi Lazarini
-
TTristan Le Gall
-
KKilyan Le Gallic
-
JJean-Christophe Léchenet
-
MMatthieu Lemerre
-
DDara Ly
-
DDavid Maison
-
CClaude Marché
-
AAndré Maroneze
-
TThibault Martin
-
FFonenantsoa Maurica
-
MMelody Méaulle
-
BBenjamin Monate
-
YYannick Moy
-
PPierre Nigron
-
AAnne Pacalet
-
VValentin Perrelle
-
GGuillaume Petiot
-
DDario Pinto
-
VVirgile Prevosto
-
AArmand Puccetti
-
FFélix Ridoux
-
VVirgile Robles
-
JJan Rochel
-
MMuriel Roger
-
CCécile Ruet-Cros
-
JJulien Signoles
-
NNicolas Stouls
-
KKostyantyn Vorobyov
-
BBoris Yakobowski
Maintainers
Sources
sha256=a94384f00d53791cbb4b4d83ab41607bc71962d42461f02d71116c4ff6dca567
doc/frama-c.kernel/Frama_c_kernel/Pretty_utils/index.html
Module Frama_c_kernel.Pretty_utils
Pretty-printer utilities.
null formatters
val null : Format.formatterPrints nothing.
val nullprintf : ('a, Format.formatter, unit) format -> 'aDiscards the message and returns unit.
val with_null : (unit -> 'b) -> ('a, Format.formatter, unit, 'b) format4 -> 'aDiscards the message and call the continuation.
pretty-printing to a string
val ksfprintf :
(string -> 'b) ->
('a, Format.formatter, unit, 'b) format4 ->
'asimilar to Format.kfprintf, but the continuation is given the result string instead of a formatter.
val to_string : ?margin:int -> (Format.formatter -> 'a -> unit) -> 'a -> stringpretty-prints the supplied value into a string. margin is the maximal width of the box before a line-break is inserted. See Format.set_margin
separators
pretty printers for standard types
type sformat = (unit, Format.formatter, unit) formattype 'a formatter = Format.formatter -> 'a -> unittype ('a, 'b) formatter2 = Format.formatter -> 'a -> 'b -> unitval pp_list :
?pre:sformat ->
?sep:sformat ->
?last:sformat ->
?suf:sformat ->
?empty:sformat ->
'a formatter ->
'a list formatterpretty prints a list. The optional arguments stands for
- the prefix to output before a non-empty list (default: open a box)
- the separator between two elements (default: nothing)
- the last separator to be put just before the last element (default:sep)
- the suffix to output after a non-empty list (default: close box)
- what to print if the list is empty (default: nothing)
val pp_array :
?pre:sformat ->
?sep:sformat ->
?suf:sformat ->
?empty:sformat ->
(int, 'a) formatter2 ->
'a array formatterpretty prints an array. The optional arguments stands for
- the prefix to output before a non-empty array (default: open a box)
- the separator between two elements (default: nothing)
- the suffix to output after a non-empty array (default: close box)
- what to print if the array is empty (default: nothing)
val pp_iter :
?pre:sformat ->
?sep:sformat ->
?suf:sformat ->
(('a -> unit) -> 'b -> unit) ->
'a formatter ->
'b formatterpretty prints any structure using an iterator on it. The argument pre (resp. suf) is output before (resp. after) the iterator is started (resp. has ended). The optional argument sep is output between two calls to the 'a formatter. Default: open a box for pre, close a box for suf, nothing for sep.
val pp_iter2 :
?pre:sformat ->
?sep:sformat ->
?suf:sformat ->
?between:sformat ->
(('key -> 'v -> unit) -> 'a -> unit) ->
'key formatter ->
'v formatter ->
'a formatterpretty prints any map-like structure using an iterator on it. The argument pre (resp. suf) is output before (resp. after) the iterator is started (resp. has ended). The optional argument sep is output between two calls to the 'a formatter. The optional argument between is output between the key and the value. Default: open a box for pre, close a box for suf, nothing for sep, break-space for between.
pretty-prints an optional value. Prefix and suffix default to "@" and "@" respectively. If the value is None, pretty-print using none.
pp_cond cond f s pretty-prints s if cond is true and the optional pr_false, which defaults to nothing, otherwise
val pp_pair :
?pre:sformat ->
?sep:sformat ->
?suf:sformat ->
'a formatter ->
'b formatter ->
('a * 'b) formatterpp_pair ?pre ?sep ?suf pp_a pp_b (a,b) pretty prints the pair (a,b), using the pretty printers pp_a and pp_b, with optional prefix/separator/suffix, whose default values are:
- pre: open a box
- sep: print a comma character
- suf: close a box.
val pp_open_block :
Format.formatter ->
('a, Format.formatter, unit) format ->
'aval pp_close_block :
Format.formatter ->
('a, Format.formatter, unit) format ->
'apretty-prints its contents inside an '(** ... **)' horizontal block trailed with '*'
Description Lists (margins)
val pp_items :
?align:align ->
?margin:int ->
?min:int ->
?max:int ->
title:('a -> string) ->
iter:(('a -> unit) -> unit) ->
?pp_title:string formatter ->
pp_item:(string formatter -> 'a formatter) ->
Format.formatter ->
unitPrints a collection of elements, with the possibility of aligning titles with each others.
The collection of 'a to print is provided by iterator ~iter which is called twice: one for computing the maximal size of titles, obtained via function ~title for each item. The second pass pretty-print each item using ~pp_item pp where the passed pp printer can be used to pretty-print titles with alignment.
A typical usage for printing values, a list of (string*int) items:
pp_items
~title:(fun (a,_) -> a)
~iter:(fun f -> List.iter f values)
~pp_title:(fun fmt a -> Format.fprintf fmt "%s:" a)
~pp_item:(fun pp fmt (a,n) -> Format.fprintf fmt "%a %d@\n" pp a n)
fmtAlignment of titles can be centered, right or left justified. This is rendered by adding spaces around each title. A min and max size can also be specified and a margin can be added to all title sizes. Titles will be truncated if necessary.
The pretty-printer for titles will render each (possibly truncated) title with ~pp_title. Surrounding spaces are not printed via ~pp_title.
The (optional) parameters have the following meaning:
?alignalignment mode (default is`Center)?marginis added to text size (default0)?minminimum size (~marginincluded, default0)?maxmaximum size (~marginincluded, default80)~titlereturns the title for each element (only size is relevant)~iteriterate over the elements to be printed?pp_titlepretty-printer used to the (possibly truncated) title (default isFormat.pp_print_string)~pp_itempretty-printer to print each element.
There is also a low-level API to this feature, provided by marger, pp_margin and add_margin below.
val marger : unit -> margerCreate an empty marger
val add_margin :
marger ->
?margin:int ->
?min:int ->
?max:int ->
string ->
unitUpdates the marger with new text dimension. The marger width is updated with the width of the provided text. The optional parameters are used to adjust the text width as follows:
?marginis added to text size (default0)?minminimum size (~marginincluded, default0)?maxmaximum size (~marginincluded, default80)
Prints a text with margins wrt to marger. If the text does not fit the marger, it would be truncated and/or ellipsed.
?alignalignment mode (default is`Center)?pppretty-printer used to the (possibly truncated) title (default isFormat.pp_print_string)
Typical usage:
begin
(* first, collect title margins *)
let m = marger () in
List.iter (fun (a,_) -> add_margin m ~margins:2 a) data ;
(* second, print aligned data *)
List.iter
(fun (a,d) -> Format.printf "[%a] %s@\n" (pp_margin m) a d)
data ;
end