Module Parenthesizer.Make

Parameters

Signature

include Support.Imperative_state.IMPERATIVE_STATE with type state = Format_state.state
type state = Format_state.state
val traverse_tuple2 : state -> (state -> 'a1 -> 'b1) -> (state -> 'a2 -> 'b2) -> ('a1 * 'a2) -> 'b1 * 'b2
val traverse_tuple3 : state -> (state -> 'a1 -> 'b1) -> (state -> 'a2 -> 'b2) -> (state -> 'a3 -> 'b3) -> ('a1 * 'a2 * 'a3) -> 'b1 * 'b2 * 'b3
val traverse_list : state -> (state -> 'a -> 'b) -> 'a Support.List.t -> 'b Support.List.t

traverse_list state f [x1; x2; ...; xn] is [y1; y2; ...; yn] where yi = f state xi, and y1, y2, ..., yn are computed in order, meaning that y1 is computed first, then y2, etc.

val traverse_list1 : state -> (state -> 'a -> 'b) -> 'a Support.List1.t -> 'b Support.List1.t
val traverse_list2 : state -> (state -> 'a -> 'b) -> 'a Support.List2.t -> 'b Support.List2.t
val iter_list : state -> (state -> 'a -> Stdlib.Unit.t) -> 'a Support.List.t -> Stdlib.Unit.t

iter_list state f [x1; x2; ...; xn] is f state x1; f state x2; ...; f state xn.

val iter_list1 : state -> (state -> 'a -> Stdlib.Unit.t) -> 'a Support.List1.t -> Stdlib.Unit.t
val iter_list2 : state -> (state -> 'a -> Stdlib.Unit.t) -> 'a Support.List2.t -> Stdlib.Unit.t
val traverse_reverse_list : state -> (state -> 'a -> 'b) -> 'a Support.List.t -> 'b Support.List.t

traverse_reverse_list state f [x1; x2; ...; xn] is [y1; y2; ...; yn] where yi = f state xi, and y1, y2, ..., yn are computed in reverse order, meaning that yn is computed first, then y(n-1), etc.

val traverse_reverse_list1 : state -> (state -> 'a -> 'b) -> 'a Support.List1.t -> 'b Support.List1.t
val traverse_reverse_list2 : state -> (state -> 'a -> 'b) -> 'a Support.List2.t -> 'b Support.List2.t
val iter_rev_list : state -> (state -> 'a -> Stdlib.Unit.t) -> 'a Support.List.t -> Stdlib.Unit.t

iter_rev_list state f [x1; x2; ...; xn] is f state xn; f state x(n-1); ...; f state x1.

val iter_rev_list1 : state -> (state -> 'a -> Stdlib.Unit.t) -> 'a Support.List1.t -> Stdlib.Unit.t
val iter_rev_list2 : state -> (state -> 'a -> Stdlib.Unit.t) -> 'a Support.List2.t -> Stdlib.Unit.t
val traverse_option : state -> (state -> 'a -> 'b) -> 'a Support.Option.t -> 'b Support.Option.t
val iter_option : state -> (state -> 'a -> Stdlib.Unit.t) -> 'a Support.Option.t -> Stdlib.Unit.t
val seq_list : state -> (state -> 'a) Support.List.t -> 'a Support.List.t
val seq_list1 : state -> (state -> 'a) Support.List1.t -> 'a Support.List1.t
val iter_seq : state -> (state -> Stdlib.Unit.t) Support.List.t -> Stdlib.Unit.t
type precedence = Precedence.t
val parenthesize_term_of_lesser_precedence : state -> (state -> 'a -> precedence) -> parent_precedence:precedence -> (state -> 'a -> Stdlib.Unit.t) -> 'a -> Stdlib.Unit.t

parenthesize_term_of_lesser_precedence is a parenthesizing formatter that adds parentheses to the term if it has a strictly lesser precedence than that of its parent node in the AST.

val parenthesize_term_of_lesser_than_or_equal_precedence : state -> (state -> 'a -> precedence) -> parent_precedence:precedence -> (state -> 'a -> Stdlib.Unit.t) -> 'a -> Stdlib.Unit.t

parenthesize_term_of_lesser_than_or_equal_precedence is a parenthesizing formatter that adds parentheses to the term if it has a lesser than or equal precedence with the precedence of its parent node in the AST.

val parenthesize_left_argument_left_associative_operator : state -> (state -> 'a -> precedence) -> parent_precedence:precedence -> (state -> 'a -> Stdlib.Unit.t) -> 'a -> Stdlib.Unit.t

parenthesize_left_argument_left_associative_operator is a parenthesizing formatter for a term appearing as a left argument to an infix left-associative operator.

val parenthesize_right_argument_left_associative_operator : state -> (state -> 'a -> precedence) -> parent_precedence:precedence -> (state -> 'a -> Stdlib.Unit.t) -> 'a -> Stdlib.Unit.t

parenthesize_right_argument_left_associative_operator is a parenthesizing formatter for a term appearing as a right argument to an infix left-associative operator.

val parenthesize_left_argument_right_associative_operator : state -> (state -> 'a -> precedence) -> parent_precedence:precedence -> (state -> 'a -> Stdlib.Unit.t) -> 'a -> Stdlib.Unit.t

parenthesize_left_argument_right_associative_operator is a parenthesizing formatter for a term appearing as a left argument to an infix right-associative operator.

val parenthesize_right_argument_right_associative_operator : state -> (state -> 'a -> precedence) -> parent_precedence:precedence -> (state -> 'a -> Stdlib.Unit.t) -> 'a -> Stdlib.Unit.t

parenthesize_right_argument_right_associative_operator is a parenthesizing formatter for a term appearing as a right argument to an infix right-associative operator.

val parenthesize_argument_non_associative_operator : state -> (state -> 'a -> precedence) -> parent_precedence:precedence -> (state -> 'a -> Stdlib.Unit.t) -> 'a -> Stdlib.Unit.t

parenthesize_argument_non_associative_operator is a parenthesizing formatter for a term appearing as an argument to an infix non-associative operator.

val parenthesize_argument_prefix_operator : state -> (state -> 'a -> precedence) -> parent_precedence:precedence -> (state -> 'a -> Stdlib.Unit.t) -> 'a -> Stdlib.Unit.t

parenthesize_argument_prefix_operator is a parenthesizing formatter for a term appearing as an argument to a prefix operator.

val parenthesize_argument_postfix_operator : state -> (state -> 'a -> precedence) -> parent_precedence:precedence -> (state -> 'a -> Stdlib.Unit.t) -> 'a -> Stdlib.Unit.t

parenthesize_argument_postfix_operator is a parenthesizing formatter for a term appearing as an argument to a postifx operator.

val pp_application : state -> indent:Support.Int.t -> guard_operator: (state -> 'applicand -> [ `Operator of Operator.t | `Operand ]) -> guard_operator_application: (state -> 'argument -> [ `Operator_application of Operator.t | `Operator of Operator.t | `Operand ]) -> precedence_of_applicand:(state -> 'applicand -> precedence) -> precedence_of_argument:(state -> 'argument -> precedence) -> pp_applicand:(state -> 'applicand -> Stdlib.Unit.t) -> pp_argument:(state -> 'argument -> Stdlib.Unit.t) -> parent_precedence:precedence -> 'applicand -> 'argument Support.List1.t -> Stdlib.Unit.t
  pp_application state ~indent ~guard_operator
    ~guard_operator_application ~precedence_of_applicand
    ~precedence_of_argument ~pp_applicand ~pp_argument
    ~parent_precedence applicand arguments

pretty-prints the application of applicand with arguments as a juxtaposition of terms delimited by whitespaces, with minimal parentheses.

This pretty-printer supports applicands having a type different from that of its arguments. This allows for pretty-printing LF type-level applications, which have LF types as applicands and LF terms as arguments.

  • ~guard_operator state applicand is `Operator operator if applicand is an operator, and `Operand otherwise.
  • ~guard_operator_application state argument is `Operator_application operator if argument is the application of an operator, `Operator operator if operator is an operator in forced prefix notation (which requires parentheses), and `Operand otherwise.
  • ~precedence_of_applicand state applicand is the precedence of applicand.
  • ~precedence_of_argument state argument is the precedence of argument.
  • ~pp_applicand state is a pretty-printer for the applicand.
  • ~pp_argument state is a pretty-printer for an argument in the application.
  • ~parent_precedence is the precedence of the AST node parent to applicand and arguments, meaning that it is the precedence of the application.