Expand description
Rendering the OCaml CST. Spec §5.
One style, the one ocamlformat produces with its defaults: two
spaces per level, a leading | on every variant constructor and
every match arm, (** … *) for documentation.
Two things are decided here that are not decided in the sibling renderers, and both are lexical:
- A comment’s text is sanitised. OCaml comments nest and
contain string literals: the manual’s “Lexical conventions”
require a comment to hold well-formed strings, and
ocamlcreportsThis comment contains an unterminated string literalfor a(* … " … *). A*)inside a comment closes it early and a(*opens a nested one that then never closes. None of those is a hazard in C, Go, Rust or Java, and a documentation comment here is assembled from IDL text.comment_safeis where the three are neutralised. - Types are postfix and left-associative.
int32 array optionis an option of an array;int32 option arrayis an array of options. Nesting therefore needs no brackets at all — except around a tuple, which is whyType::Tuplealways renders parenthesised.
Nothing else is decided. What is a group and what is a single
declaration is settled in zerodds_lang_rules::adapter::ocaml,
because it is a property of the type graph and not of the text.
Functions§
- codec_
chain - A chain of codec functions:
let rec f … and g …. One chain, so a recursive or mutually recursive type’s codecs resolve whatever order the walk visited them in. - comment_
safe - Text that cannot end, nest or unbalance the comment holding it.
- decl
- Render one declaration, for a caller that has only one.
- file
- Render a whole file.
- ident
- The identifier a name renders as, for a caller assembling one.
- type_
- Render one type, for a caller that has only one.
- value_
chain - A chain of value functions — the Table 9 defaulters.