module Output: sig
.. end
Intermediate output format before going to strings
type
t
type
t' =
| |
Kwd' of string |
| |
Ident' of Ulib.Text.t |
| |
Num' of int |
type
id_annot =
| |
Term_const of bool * bool |
| |
Term_field |
| |
Term_method |
| |
Term_var |
| |
Term_var_toplevel |
| |
Term_spec |
| |
Type_ctor of bool * bool |
| |
Type_var |
| |
Nexpr_var |
| |
Module_name |
| |
Class_name |
| |
Target |
| |
Component |
kind annotation for latex'd identifiers
constructing output
val emp : t
Empty output
val kwd : string -> t
kwd s
constructs the output for keyword s
val num : int -> t
num i
constructs the output for number i
val str : Ulib.Text.t -> t
str s
constructs the output for string constant s
val ws : Ast.lex_skips -> t
Whitespace
val err : string -> t
err message
is an error output. An exception is thrown with the given message
if this output is created. Used for marking problems.
val meta : string -> t
meta s
creates a string directly as output such that the formatting can't interfere
with string s
any more
: string -> t
A comment
: int option -> string list -> t
comment_block min_width_opt content
comment a whole
list of lines in a block.
val new_line : t
a new line
val space : t
a single space
val texspace : t
??? Unsure what it is. Some kind of tex specific space, similar to space, but
treated slightly differently by the Latex backend. It seems to be for example removed
at beginnings and ends of lines and multiple ones are collapsed into a single space.
val id : id_annot -> Ulib.Text.t -> t
An identifier
val (^) : t -> t -> t
o1 ^ o2
appends to outputs to each other
val flat : t list -> t
flat [o0; ...; on]
appends all the outputs in the list, i.e.
it does o0 ^ ... ^ on
.
val concat : t -> t list -> t
concat sep [o0; ...; on]
appends all the outputs in the list using
the separator sep
, i.e.
it does o0 ^ sep ^ o1 ^ ... sep ^ tn
.
val prefix_if_not_emp : t -> t -> t
prefix_if_not_emp o1 o2
returns o1 ^ o2
if o2
is not empty and
emp
otherwise
Pretty Printing
Blocks
Blocks are used for pretty printing if the original whitespace should not be used.
This is usually the case, if the source was generated by some macro, such that
either no original spacing is present or it is likely to be broken.
If the first argument of a block is true
this block and all it's content is
printed using OCaml's Format
library. The other arguments of blocks correspond
to blocks in the Format
library. They describe indentation, the type of block and the
content.
val block : bool -> int -> t -> t
val block_h : bool -> int -> t -> t
val block_v : bool -> int -> t -> t
val block_hv : bool -> int -> t -> t
val block_hov : bool -> int -> t -> t
val core : t -> t
core out
is a marker for marking the most important part of some output. It marks for example the
rhs of a definition. Together with extract_core
this is used to sometimes only print the most essential part
of some output
val remove_core : t -> t
remove_core o
removes all occurences of core form t
by replacing core o'
with just o'
.
: t -> t list
extract_core o
extracts all top-level cores from output o
.
Spacing
val remove_initial_ws : t -> t
removes intial whitespace (including comments) from output
val break_hint : bool -> int -> t
break_hint add_space ind
is a general hint for a line-break. If add_space
is set
a space is added in case no line-break is needed. Otherwise a line-break with the given
indentation ind
is applied.
val break_hint_cut : t
break_hint_cut
is short for break_hint false 0
. It allows a newline at this posistion
without indentation. If no newline is needed don't add any space.
val break_hint_space : int -> t
break_hint_space ind
is short for break_hint true ind
.
It adds a space or a newline. If a newline is needed use the given indentation.
val ensure_newline : t
Make sure there is a newline starting here. This inserts a newline if necessary.
Output to Rope
val to_rope : Ulib.Text.t ->
(Ast.lex_skip -> Ulib.Text.t) ->
(t' -> t' -> bool) -> t -> Ulib.Text.t
to_rope quote_char lex_skips_to_rope need_space t
formats the output t
as an unicode text.
The quote_char
argument is used around strings. The function lex_skips_to_rope
is used to format
whitespace. Finally the function need_space
is used to determine, whether an extra space is needed between
simplified outputs.
: Ast.ml_comment -> Ulib.Text.t
ml_comment_to_rope com
formats an ML-comment as a text by putting (*
and *)
around it.
Latex Output
val to_rope_tex : t -> Ulib.Text.t
to_rope_tex t
corresponds to to_rope
for the Latex backend. Since it is used for only one backend,
the backend parameters of to_rope
can be hard-coded.
val to_rope_option_tex : t -> Ulib.Text.t option
to_rope_option_tex t
is similar to to_rope_tex t
. However, it checks whether the
result is an empty text and returns None
is in this case.
val tex_escape : Ulib.Text.t -> Ulib.Text.t
val tex_command_escape : Ulib.Text.t -> Ulib.Text.t
val tex_command_label : Ulib.Text.t -> Ulib.Text.t
val tex_command_name : Ulib.Text.t -> Ulib.Text.t