@@ -163,8 +163,14 @@ let parenthesize_if_neg ppf fmt v isneg =
163163
164164
165165let print_out_value ppf tree =
166- let rec print_tree_1 ppf =
167- function
166+ let rec print_tree_1 ppf outcome =
167+ let tag =
168+ if Reason_version. print_supports Reason_version. HashVariantsColonMethodCallStarClassTypes then
169+ " #"
170+ else
171+ " `"
172+ in
173+ match outcome with
168174 (* for the next few cases , please see context at https ://github.com/facebook/reason/pull/1516#issuecomment-337069150 * )
169175 | Oval_constr (name , [Oval_constr ((Oide_ident { printed_name = "()" } ), [] )]) ->
170176 (* for normal variants, but sugar Foo(()) to Foo() *)
@@ -177,10 +183,10 @@ let print_out_value ppf tree =
177183 (print_tree_list print_tree_1 " ," ) params
178184 | Oval_variant (name , Some (Oval_constr ((Oide_ident { printed_name = "()" } ), [] ))) ->
179185 (* for polymorphic variants, but sugar `foo(()) to `foo() *)
180- fprintf ppf " @[<2>`%s ()@]" name
186+ fprintf ppf " @[<2>%s%s ()@]" tag name
181187 | Oval_variant (name , Some param ) ->
182188 (* for polymorphic variants *)
183- fprintf ppf " @[<2>`%s (%a)@]" name print_constr_param param
189+ fprintf ppf " @[<2>%s%s (%a)@]" tag name print_constr_param param
184190 | tree -> print_simple_tree ppf tree
185191 and print_constr_param ppf = function
186192 | Oval_int i -> parenthesize_if_neg ppf " %i" i (i < 0 )
@@ -206,7 +212,13 @@ let print_out_value ppf tree =
206212 | Oval_array tl ->
207213 fprintf ppf " @[<2>[|%a|]@]" (print_tree_list print_tree_1 " ," ) tl
208214 | Oval_constr (name , [] ) -> print_ident ppf name
209- | Oval_variant (name , None) -> fprintf ppf " `%s" name
215+ | Oval_variant (name , None) ->
216+ let opn =
217+ if Reason_version. print_supports
218+ Reason_version. HashVariantsColonMethodCallStarClassTypes then " #"
219+ else " `"
220+ in
221+ fprintf ppf " %s%s" opn name
210222 | Oval_stuff s -> pp_print_string ppf s
211223 | Oval_record fel ->
212224 fprintf ppf " @[<1>{%a}@]" (cautious (print_fields true )) fel
@@ -249,8 +261,12 @@ let rec print_list pr sep ppf =
249261 | [a] -> pr ppf a
250262 | a :: l -> pr ppf a; sep ppf; print_list pr sep ppf l
251263
252- let pr_present =
253- print_list (fun ppf s -> fprintf ppf " `%s" s) (fun ppf -> fprintf ppf " @ " )
264+ let pr_present () =
265+ if Reason_version. print_supports
266+ Reason_version. HashVariantsColonMethodCallStarClassTypes then
267+ print_list (fun ppf s -> fprintf ppf " #%s" s) (fun ppf -> fprintf ppf " @ " )
268+ else
269+ print_list (fun ppf s -> fprintf ppf " `%s" s) (fun ppf -> fprintf ppf " @ " )
254270
255271let pr_vars =
256272 print_list (fun ppf s -> fprintf ppf " '%s" s) (fun ppf -> fprintf ppf " @ " )
@@ -266,8 +282,7 @@ let get_label lbl =
266282 Optional (String. sub lbl 1 @@ String. length lbl - 1 )
267283 else Labeled lbl
268284
269- let rec print_out_type ppf =
270- function
285+ let rec print_out_type ppf outcome = match outcome with
271286 | Otyp_alias (ty , s ) ->
272287 fprintf ppf " @[%a@ as '%s@]" print_out_type ty s
273288 | Otyp_poly (sl , ty ) ->
@@ -305,7 +320,7 @@ and print_out_type_1 ~uncurried ppf =
305320 in
306321 pp_open_box ppf 0 ;
307322 let (args, result) = collect_args [] x in
308- let should_wrap_with_parens =
323+ let should_wrap =
309324 (* uncurried arguments are always wrapped in parens *)
310325 if uncurried then true
311326 else match args with
@@ -315,10 +330,15 @@ and print_out_type_1 ~uncurried ppf =
315330 | [" " , _] -> false
316331 | _ -> true
317332 in
318- if should_wrap_with_parens then pp_print_string ppf " (" ;
333+
334+ let opn, close =
335+ if Reason_version. print_supports AngleBracketTypes then " <" , " >"
336+ else " (" , " )"
337+ in
338+ if should_wrap then pp_print_string ppf opn;
319339 if uncurried then fprintf ppf " .@ " ;
320340 print_list print_arg (fun ppf -> fprintf ppf " ,@ " ) ppf args;
321- if should_wrap_with_parens then pp_print_string ppf " ) " ;
341+ if should_wrap then pp_print_string ppf close ;
322342
323343 pp_print_string ppf " =>" ;
324344 pp_print_space ppf () ;
@@ -442,7 +462,7 @@ and print_simple_out_type ppf =
442462 let print_present ppf =
443463 function
444464 None | Some [] -> ()
445- | Some l -> fprintf ppf " @;<1 -2>> @[<hov>%a@]" pr_present l
465+ | Some l -> fprintf ppf " @;<1 -2>> @[<hov>%a@]" ( pr_present () ) l
446466 in
447467 let print_fields ppf =
448468 function
@@ -490,13 +510,20 @@ and print_row_field ppf (l, opt_amp, tyl) =
490510 let pr_of ppf =
491511 if opt_amp then fprintf ppf " &@ "
492512 else fprintf ppf " " in
513+ let tag =
514+ if Reason_version. print_supports Reason_version. HashVariantsColonMethodCallStarClassTypes then
515+ " #"
516+ else
517+ " `"
518+ in
493519 let parens = match tyl with
494520 | [ (Otyp_tuple _) ] -> false (* tuples already have parentheses *)
495521 (* [< `Ok(string & int) ] ----> string & int
496522 * [< `Ok(string) ] -----> string *)
497523 | _ ::_ -> true
498524 | _ -> false in
499- fprintf ppf " @[<hv 2>`%s%t%s%a%s@]"
525+ fprintf ppf " @[<hv 2>%s%s%t%s%a%s@]"
526+ tag
500527 l
501528 pr_of
502529 (if parens then " (" else " " )
@@ -516,19 +543,23 @@ and print_out_wrap_type ppf =
516543 | (Otyp_constr (_ , _ ::_ )) as ty ->
517544 print_out_type ppf ty
518545 | ty -> print_simple_out_type ppf ty
519- and print_typargs ppf =
520- function
521- [] -> ()
546+ and print_typargs ppf args =
547+ let opn, close =
548+ if Reason_version. print_supports AngleBracketTypes then " <" , " >"
549+ else " (" , " )"
550+ in
551+ match args with
552+ | [] -> ()
522553 | [ty1] ->
523- pp_print_string ppf " ( " ;
554+ pp_print_string ppf opn ;
524555 print_out_wrap_type ppf ty1;
525- pp_print_string ppf " ) "
556+ pp_print_string ppf close
526557 | tyl ->
527- pp_print_string ppf " ( " ;
558+ pp_print_string ppf opn ;
528559 pp_open_box ppf 1 ;
529560 print_typlist print_out_wrap_type " ," ppf tyl;
530561 pp_close_box ppf () ;
531- pp_print_string ppf " ) "
562+ pp_print_string ppf close
532563
533564let out_type = ref print_out_type
534565
@@ -736,14 +767,19 @@ and print_out_type_decl kwd ppf td =
736767 td.otype_cstrs
737768 in
738769 let type_defined ppf =
770+ let opn, close =
771+ if Reason_version. print_supports AngleBracketTypes then " <" , " >" else " (" , " )"
772+ in
739773 match td.otype_params with
740774 [] -> pp_print_string ppf td.otype_name
741- | [param] -> fprintf ppf " @[%s(%a) @]" td.otype_name type_parameter param
775+ | [param] -> fprintf ppf " @[%s%s%a%s @]" td.otype_name opn type_parameter param close
742776 | _ ->
743- fprintf ppf " @[%s( @[%a@]) @]"
777+ fprintf ppf " @[%s%s @[%a@]%s @]"
744778 td.otype_name
779+ opn
745780 (print_list type_parameter (fun ppf -> fprintf ppf " ,@ " ))
746781 td.otype_params
782+ close
747783 in
748784 let print_manifest ppf =
749785 function
0 commit comments