Module Frontend.Pretty_printing

Some helpers to produce nice error messages and for auto-formatting Stan programs

val comments : Ast.comment_type list Core.ref

To avoid cluttering the AST, comments are not associated with any particular AST node but instead come in a separate list. The pretty printer uses the AST nodes' location metadata to insert whitespace and comments. The comment list is stored in a global state that is accessed by set_comments, get_comments, and skip_comments.

val skipped : ([ `Block | `Include | `Line ] * string list * Middle.Location_span.t) list Core.ref
val set_comments : ?inline_includes:bool -> ?strip_comments:bool -> Ast.comment_type list -> unit
val get_comments : Middle.Location.t -> ([> `Block | `Include | `Line ] * string list * Middle.Location_span.t) list
val get_comments_until_separator : Middle.Location.t -> ([> `Block | `Include | `Line ] * string list * Middle.Location_span.t) list
val skip_comments : Middle.Location.t -> unit
val remaining_comments : unit -> ([ `Block | `Include | `Line ] * string list * Middle.Location_span.t) Base__List.t
val print_included : bool Core.ref

If false, don't print any statements which came from another file

val should_skip : Middle.Location.t -> bool

Checks if something should be skipped based on the print_included setting

val pp_space : bool -> Stdlib.Format.formatter -> (Middle.Location.t * Middle.Location.t) -> unit
val pp_comment : Stdlib.Format.formatter -> ([< `Block | `Include | `Line ] * string list * Middle.Location_span.t) -> unit
val pp_spacing : ?newline:bool -> Middle.Location.t option -> Middle.Location.t option -> Stdlib.Format.formatter -> ([< `Block | `Include | `Line Include Line ] * string list * Middle.Location_span.t) list -> unit
val pp_comments_spacing : bool -> ('a -> ([< `Block | `Include | `Line Block ] * string list * Middle.Location_span.t) list) -> Stdlib.Format.formatter -> 'b -> unit
val comma_no_break : unit Fmt.t
val indented_box : ?offset:int -> 'a Fmt.t -> Stdlib.Format.formatter -> 'b -> unit
val pp_unsizedtype : Middle.UnsizedType.t Fmt.t
val pp_autodifftype : Stdlib.Format.formatter -> Middle.UnsizedType.autodifftype -> unit
val pp_returntype : Stdlib.Format.formatter -> Middle.UnsizedType.returntype -> unit
val pp_identifier : Stdlib.Format.formatter -> Ast.identifier -> unit
val pp_operator : Stdlib.Format.formatter -> Middle.Operator.t -> unit
val pp_list_of : (Stdlib.Format.formatter -> 'a -> unit) -> ('a0 -> Middle.Location_span.t) -> Stdlib.Format.formatter -> ('a1 list * Middle.Location_span.t) -> unit
val pp_index : Ast.untyped_expression Ast.index Fmt.t
val pp_list_of_indices : Stdlib.Format.formatter -> Ast.untyped_expression Ast.index list -> unit
val pp_expression : Stdlib.Format.formatter -> Ast.untyped_expression -> unit
val pp_list_of_expression : Stdlib.Format.formatter -> (Ast.untyped_expression list * Middle.Location_span.t) -> unit
val pp_lvalue : Stdlib.Format.formatter -> ((Ast.located_meta, unit) Ast.expr_with, Ast.located_meta) Ast.lval_with Ast.lvalue_pack -> unit
val pp_assignmentoperator : Stdlib.Format.formatter -> Ast.assignmentoperator -> unit
val pp_truncation : Stdlib.Format.formatter -> Ast.untyped_expression Ast.truncation -> unit
val pp_printable : Stdlib.Format.formatter -> Ast.untyped_expression Ast.printable -> unit
val pp_list_of_printables : Stdlib.Format.formatter -> Ast.untyped_expression Ast.printable list -> unit
val pp_bracketed_transform : Stdlib.Format.formatter -> Ast.untyped_expression Middle.Transformation.t -> unit
val pp_indent_unless_block : Stdlib.Format.formatter -> (Ast.untyped_statement * Middle.Location.t) -> unit

This function helps write chained if-then-else-if-... blocks correctly. Without it, each IfThenElse would trigger a new vbox in front of the if, adding spaces for each level of IfThenElse.

val pp_statement : Ast.untyped_statement Fmt.t
val pp_args : Stdlib.Format.formatter -> (Middle.UnsizedType.autodifftype * Middle.UnsizedType.t * Ast.identifier) -> unit
val pp_typed_expression : Stdlib.Format.formatter -> Ast.typed_expression -> unit