Permalink
Browse files

introduce type aliases for simple padding and precision types

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14825 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information...
1 parent 6a8f120 commit 39ab064bafcc9b1f0d9e81bdbc4656f0edf13775 @gasche gasche committed May 12, 2014
Showing with 65 additions and 45 deletions.
  1. +23 −15 otherlibs/threads/pervasives.ml
  2. +2 −2 stdlib/camlinternalFormat.ml
  3. +23 −15 stdlib/pervasives.ml
  4. +17 −13 stdlib/pervasives.mli
@@ -638,6 +638,10 @@ type ('a, 'b) padding =
(* Padding as extra argument (ex: "%*d") *)
| Arg_padding : padty -> (int -> 'a, 'a) padding
+(* Some formats, such as %_d,
+ only accept an optional number as padding option (no extra argument) *)
+type pad_option = int option
+
(* Precision of floats and '0'-padding of integers. *)
type ('a, 'b) precision =
(* No precision (ex: "%f") *)
@@ -647,6 +651,10 @@ type ('a, 'b) precision =
(* Precision as extra argument (ex: "%.*f") *)
| Arg_precision : (int -> 'a, 'a) precision
+(* Some formats, such as %_f,
+ only accept an optional number as precision option (no extra argument) *)
+type prec_option = int option
+
(***)
(* Type used in Format_subst_ty and Format_subst constructors as "a proof"
@@ -770,11 +778,11 @@ and ('a, 'b, 'c, 'd, 'e, 'f) fmt =
('a, 'b, 'c, 'd, 'e, 'f) fmt
| Format_arg : (* %{...%} *)
- int option * ('x, 'b, 'c, 'q, 'r, 'u) fmtty *
+ pad_option * ('x, 'b, 'c, 'q, 'r, 'u) fmtty *
('a, 'b, 'c, 'd, 'e, 'f) fmt ->
(('x, 'b, 'c, 'q, 'r, 'u) format6 -> 'a, 'b, 'c, 'd, 'e, 'f) fmt
| Format_subst : (* %(...%) *)
- int option * ('d1, 'q1, 'd2, 'q2) reader_nb_unifier *
+ pad_option * ('d1, 'q1, 'd2, 'q2) reader_nb_unifier *
('x, 'b, 'c, 'd1, 'q1, 'u) fmtty *
('u, 'b, 'c, 'q1, 'e1, 'f) fmt ->
(('x, 'b, 'c, 'd2, 'q2, 'u) format6 -> 'x, 'b, 'c, 'd1, 'e1, 'f) fmt
@@ -797,7 +805,7 @@ and ('a, 'b, 'c, 'd, 'e, 'f) fmt =
('a, 'b, 'c, 'd, 'e, 'f) fmt ->
('x -> 'a, 'b, 'c, ('b -> 'x) -> 'd, 'e, 'f) fmt
| Scan_char_set : (* %[...] *)
- int option * char_set * ('a, 'b, 'c, 'd, 'e, 'f) fmt ->
+ pad_option * char_set * ('a, 'b, 'c, 'd, 'e, 'f) fmt ->
(string -> 'a, 'b, 'c, 'd, 'e, 'f) fmt
| Scan_get_counter : (* %[nlNL] *)
counter * ('a, 'b, 'c, 'd, 'e, 'f) fmt ->
@@ -818,31 +826,31 @@ and ('a, 'b, 'c, 'd, 'e, 'f) ignored =
| Ignored_caml_char : (* %_C *)
('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_string : (* %_s *)
- int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_caml_string : (* %_S *)
- int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_int : (* %_d *)
- int_conv * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ int_conv * pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_int32 : (* %_ld *)
- int_conv * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ int_conv * pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_nativeint : (* %_nd *)
- int_conv * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ int_conv * pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_int64 : (* %_Ld *)
- int_conv * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ int_conv * pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_float : (* %_f *)
- int option * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ pad_option * pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_bool : (* %_B *)
('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_format_arg : (* %_{...%} *)
- int option * ('x, 'b, 'c, 'y, 'z, 't) fmtty ->
+ pad_option * ('x, 'b, 'c, 'y, 'z, 't) fmtty ->
('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_format_subst : (* %_(...%) *)
- int option * ('a, 'b, 'c, 'd, 'e, 'f) fmtty ->
+ pad_option * ('a, 'b, 'c, 'd, 'e, 'f) fmtty ->
('a, 'b, 'c, 'd, 'e, 'f) ignored
| Ignored_reader : (* %_r *)
('a, 'b, 'c, ('b -> 'x) -> 'd, 'd, 'a) ignored
| Ignored_scan_char_set : (* %_[...] *)
- int option * char_set -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ pad_option * char_set -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_scan_get_counter : (* %_[nlNL] *)
counter -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
@@ -1026,12 +1034,12 @@ type ('a, 'b, 'c, 'd, 'e, 'f) param_format_ebb = Param_format_EBB :
('x -> 'a, 'b, 'c, 'd, 'e, 'f) fmt ->
('a, 'b, 'c, 'd, 'e, 'f) param_format_ebb
-(* Compute a padding associated to an int option (see "%_42d"). *)
+(* Compute a padding associated to a pad_option (see "%_42d"). *)
let pad_of_pad_opt pad_opt = match pad_opt with
| None -> No_padding
| Some width -> Lit_padding (Right, width)
-(* Compute a precision associated to an int option (see "%_.42f"). *)
+(* Compute a precision associated to a prec_option (see "%_.42f"). *)
let prec_of_prec_opt prec_opt = match prec_opt with
| None -> No_precision
| Some ndec -> Lit_precision ndec
@@ -1468,7 +1468,7 @@ let fmt_ebb_of_string str =
else incompatible_flag pct_ind str_ind symb "0"
in
- (* Get padding as an int option (see "%_", "%{", "%(" and "%[").
+ (* Get padding as a pad_option (see "%_", "%{", "%(" and "%[").
(no need for legacy mode tweaking, those were rejected by the
legacy parser as well) *)
let get_pad_opt c = match get_pad () with
@@ -1483,7 +1483,7 @@ let fmt_ebb_of_string str =
| Arg_padding _ -> incompatible_flag pct_ind str_ind c "'*'"
in
- (* Get precision as an int option (see "%_f").
+ (* Get precision as a prec_option (see "%_f").
(no need for legacy mode tweaking, those were rejected by the
legacy parser as well) *)
let get_prec_opt () = match get_prec () with
View
@@ -540,6 +540,10 @@ type ('a, 'b) padding =
(* Padding as extra argument (ex: "%*d") *)
| Arg_padding : padty -> (int -> 'a, 'a) padding
+(* Some formats, such as %_d,
+ only accept an optional number as padding option (no extra argument) *)
+type pad_option = int option
+
(* Precision of floats and '0'-padding of integers. *)
type ('a, 'b) precision =
(* No precision (ex: "%f") *)
@@ -549,6 +553,10 @@ type ('a, 'b) precision =
(* Precision as extra argument (ex: "%.*f") *)
| Arg_precision : (int -> 'a, 'a) precision
+(* Some formats, such as %_f,
+ only accept an optional number as precision option (no extra argument) *)
+type prec_option = int option
+
(***)
(* Type used in Format_subst_ty and Format_subst constructors as "a proof"
@@ -672,11 +680,11 @@ and ('a, 'b, 'c, 'd, 'e, 'f) fmt =
('a, 'b, 'c, 'd, 'e, 'f) fmt
| Format_arg : (* %{...%} *)
- int option * ('x, 'b, 'c, 'q, 'r, 'u) fmtty *
+ pad_option * ('x, 'b, 'c, 'q, 'r, 'u) fmtty *
('a, 'b, 'c, 'd, 'e, 'f) fmt ->
(('x, 'b, 'c, 'q, 'r, 'u) format6 -> 'a, 'b, 'c, 'd, 'e, 'f) fmt
| Format_subst : (* %(...%) *)
- int option * ('d1, 'q1, 'd2, 'q2) reader_nb_unifier *
+ pad_option * ('d1, 'q1, 'd2, 'q2) reader_nb_unifier *
('x, 'b, 'c, 'd1, 'q1, 'u) fmtty *
('u, 'b, 'c, 'q1, 'e1, 'f) fmt ->
(('x, 'b, 'c, 'd2, 'q2, 'u) format6 -> 'x, 'b, 'c, 'd1, 'e1, 'f) fmt
@@ -699,7 +707,7 @@ and ('a, 'b, 'c, 'd, 'e, 'f) fmt =
('a, 'b, 'c, 'd, 'e, 'f) fmt ->
('x -> 'a, 'b, 'c, ('b -> 'x) -> 'd, 'e, 'f) fmt
| Scan_char_set : (* %[...] *)
- int option * char_set * ('a, 'b, 'c, 'd, 'e, 'f) fmt ->
+ pad_option * char_set * ('a, 'b, 'c, 'd, 'e, 'f) fmt ->
(string -> 'a, 'b, 'c, 'd, 'e, 'f) fmt
| Scan_get_counter : (* %[nlNL] *)
counter * ('a, 'b, 'c, 'd, 'e, 'f) fmt ->
@@ -720,31 +728,31 @@ and ('a, 'b, 'c, 'd, 'e, 'f) ignored =
| Ignored_caml_char : (* %_C *)
('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_string : (* %_s *)
- int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_caml_string : (* %_S *)
- int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_int : (* %_d *)
- int_conv * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ int_conv * pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_int32 : (* %_ld *)
- int_conv * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ int_conv * pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_nativeint : (* %_nd *)
- int_conv * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ int_conv * pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_int64 : (* %_Ld *)
- int_conv * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ int_conv * pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_float : (* %_f *)
- int option * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ pad_option * prec_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_bool : (* %_B *)
('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_format_arg : (* %_{...%} *)
- int option * ('x, 'b, 'c, 'y, 'z, 't) fmtty ->
+ pad_option * ('x, 'b, 'c, 'y, 'z, 't) fmtty ->
('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_format_subst : (* %_(...%) *)
- int option * ('a, 'b, 'c, 'd, 'e, 'f) fmtty ->
+ pad_option * ('a, 'b, 'c, 'd, 'e, 'f) fmtty ->
('a, 'b, 'c, 'd, 'e, 'f) ignored
| Ignored_reader : (* %_r *)
('a, 'b, 'c, ('b -> 'x) -> 'd, 'd, 'a) ignored
| Ignored_scan_char_set : (* %_[...] *)
- int option * char_set -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ pad_option * char_set -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_scan_get_counter : (* %_[nlNL] *)
counter -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
@@ -927,12 +935,12 @@ type ('a, 'b, 'c, 'd, 'e, 'f) param_format_ebb = Param_format_EBB :
('x -> 'a, 'b, 'c, 'd, 'e, 'f) fmt ->
('a, 'b, 'c, 'd, 'e, 'f) param_format_ebb
-(* Compute a padding associated to an int option (see "%_42d"). *)
+(* Compute a padding associated to a pad_option (see "%_42d"). *)
let pad_of_pad_opt pad_opt = match pad_opt with
| None -> No_padding
| Some width -> Lit_padding (Right, width)
-(* Compute a precision associated to an int option (see "%_.42f"). *)
+(* Compute a precision associated to a prec_option (see "%_.42f"). *)
let prec_of_prec_opt prec_opt = match prec_opt with
| None -> No_precision
| Some ndec -> Lit_precision ndec
View
@@ -1005,11 +1005,15 @@ module CamlinternalFormatBasics : sig
| Lit_padding : padty * int -> ('a, 'a) padding
| Arg_padding : padty -> (int -> 'a, 'a) padding
+ type pad_option = int option
+
type ('a, 'b) precision =
| No_precision : ('a, 'a) precision
| Lit_precision : int -> ('a, 'a) precision
| Arg_precision : (int -> 'a, 'a) precision
+ type prec_option = int option
+
type ('d1, 'e1, 'd2, 'e2) reader_nb_unifier =
| Zero_reader :
('d1, 'd1, 'd2, 'd2) reader_nb_unifier
@@ -1111,11 +1115,11 @@ module CamlinternalFormatBasics : sig
char * ('a, 'b, 'c, 'd, 'e, 'f) fmt ->
('a, 'b, 'c, 'd, 'e, 'f) fmt
| Format_arg :
- int option * ('x, 'b, 'c, 'q, 'r, 'u) fmtty *
+ pad_option * ('x, 'b, 'c, 'q, 'r, 'u) fmtty *
('a, 'b, 'c, 'd, 'e, 'f) fmt ->
(('x, 'b, 'c, 'q, 'r, 'u) format6 -> 'a, 'b, 'c, 'd, 'e, 'f) fmt
| Format_subst :
- int option * ('d1, 'q1, 'd2, 'q2) reader_nb_unifier *
+ pad_option * ('d1, 'q1, 'd2, 'q2) reader_nb_unifier *
('x, 'b, 'c, 'd1, 'q1, 'u) fmtty *
('u, 'b, 'c, 'q1, 'e1, 'f) fmt ->
(('x,'b,'c,'d2, 'q2, 'u) format6 -> 'x, 'b, 'c, 'd1, 'e1, 'f) fmt
@@ -1132,7 +1136,7 @@ module CamlinternalFormatBasics : sig
('a, 'b, 'c, 'd, 'e, 'f) fmt ->
('x -> 'a, 'b, 'c, ('b -> 'x) -> 'd, 'e, 'f) fmt
| Scan_char_set :
- int option * char_set * ('a, 'b, 'c, 'd, 'e, 'f) fmt ->
+ pad_option * char_set * ('a, 'b, 'c, 'd, 'e, 'f) fmt ->
(string -> 'a, 'b, 'c, 'd, 'e, 'f) fmt
| Scan_get_counter :
counter * ('a, 'b, 'c, 'd, 'e, 'f) fmt ->
@@ -1149,31 +1153,31 @@ module CamlinternalFormatBasics : sig
| Ignored_caml_char :
('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_string :
- int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_caml_string :
- int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_int :
- int_conv * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ int_conv * pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_int32 :
- int_conv * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ int_conv * pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_nativeint :
- int_conv * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ int_conv * pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_int64 :
- int_conv * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ int_conv * pad_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_float :
- int option * int option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ pad_option * prec_option -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_bool :
('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_format_arg :
- int option * ('x, 'b, 'c, 'y, 'z, 't) fmtty ->
+ pad_option * ('x, 'b, 'c, 'y, 'z, 't) fmtty ->
('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_format_subst :
- int option * ('a, 'b, 'c, 'd, 'e, 'f) fmtty ->
+ pad_option * ('a, 'b, 'c, 'd, 'e, 'f) fmtty ->
('a, 'b, 'c, 'd, 'e, 'f) ignored
| Ignored_reader :
('a, 'b, 'c, ('b -> 'x) -> 'd, 'd, 'a) ignored
| Ignored_scan_char_set :
- int option * char_set -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
+ pad_option * char_set -> ('a, 'b, 'c, 'd, 'd, 'a) ignored
| Ignored_scan_get_counter :
counter -> ('a, 'b, 'c, 'd, 'd, 'a) ignored

0 comments on commit 39ab064

Please sign in to comment.