| 1 | open Base |
| 2 | |
| 3 | [@@@warning "-37"] |
| 4 | |
| 5 | module _ = struct |
| 6 | type 'a t = |
| 7 | [ `A |
| 8 | | `B |
| 9 | ] |
| 10 | [@@deriving_inline sexp_grammar] |
| 11 | |
| 12 | let _ = fun (_ : 'a t) -> () |
| 13 | |
| 14 | let t_sexp_grammar : 'a. 'a Sexplib0.Sexp_grammar.t -> 'a t Sexplib0.Sexp_grammar.t = |
| 15 | fun _'a_sexp_grammar -> |
| 16 | { untyped = |
| 17 | Variant |
| 18 | { case_sensitivity = Case_sensitive |
| 19 | ; clauses = |
| 20 | [ No_tag { name = "A"; clause_kind = Atom_clause } |
| 21 | ; No_tag { name = "B"; clause_kind = Atom_clause } |
| 22 | ] |
| 23 | } |
| 24 | } |
| 25 | ;; |
| 26 | |
| 27 | let _ = t_sexp_grammar |
| 28 | |
| 29 | [@@@end] |
| 30 | end |
| 31 | |
| 32 | module _ = struct |
| 33 | module With_sexp = struct |
| 34 | type t = |
| 35 | [ `A of int * int |
| 36 | | `B of string |
| 37 | ] |
| 38 | [@@deriving sexp_of] |
| 39 | end |
| 40 | |
| 41 | type t = |
| 42 | [ `A of int * int |
| 43 | | `B of string |
| 44 | ] |
| 45 | [@@deriving_inline sexp_grammar] |
| 46 | |
| 47 | let _ = fun (_ : t) -> () |
| 48 | |
| 49 | let (t_sexp_grammar : t Sexplib0.Sexp_grammar.t) = |
| 50 | { untyped = |
| 51 | Lazy |
| 52 | (lazy |
| 53 | (Variant |
| 54 | { case_sensitivity = Case_sensitive |
| 55 | ; clauses = |
| 56 | [ No_tag |
| 57 | { name = "A" |
| 58 | ; clause_kind = |
| 59 | List_clause |
| 60 | { args = |
| 61 | Cons |
| 62 | ( List |
| 63 | (Cons |
| 64 | ( int_sexp_grammar.untyped |
| 65 | , Cons (int_sexp_grammar.untyped, Empty) )) |
| 66 | , Empty ) |
| 67 | } |
| 68 | } |
| 69 | ; No_tag |
| 70 | { name = "B" |
| 71 | ; clause_kind = |
| 72 | List_clause |
| 73 | { args = Cons (string_sexp_grammar.untyped, Empty) } |
| 74 | } |
| 75 | ] |
| 76 | })) |
| 77 | } |
| 78 | ;; |
| 79 | |
| 80 | let _ = t_sexp_grammar |
| 81 | |
| 82 | [@@@end] |
| 83 | |
| 84 | open Expect_test_helpers_base |
| 85 | |
| 86 | let%expect_test _ = |
| 87 | print_s (With_sexp.sexp_of_t (`A (1, 2))); |
| 88 | print_s (With_sexp.sexp_of_t (`B "foo")); |
| 89 | [%expect {| |
| 90 | (A (1 2)) |
| 91 | (B foo) |
| 92 | |}] |
| 93 | ;; |
| 94 | end |
| 95 | |
| 96 | module _ = struct |
| 97 | module With_sexp = struct |
| 98 | type t = |
| 99 | [ `Int of int |
| 100 | | `List of int list |
| 101 | | `Sexp_dot_list of int list [@sexp.list] |
| 102 | ] |
| 103 | [@@deriving sexp] |
| 104 | end |
| 105 | |
| 106 | type t = |
| 107 | [ `Int of int |
| 108 | | `List of int list |
| 109 | | `Sexp_dot_list of int list [@sexp.list] |
| 110 | ] |
| 111 | [@@deriving_inline sexp_grammar] |
| 112 | |
| 113 | let _ = fun (_ : t) -> () |
| 114 | |
| 115 | let (t_sexp_grammar : t Sexplib0.Sexp_grammar.t) = |
| 116 | { untyped = |
| 117 | Lazy |
| 118 | (lazy |
| 119 | (Variant |
| 120 | { case_sensitivity = Case_sensitive |
| 121 | ; clauses = |
| 122 | [ No_tag |
| 123 | { name = "Int" |
| 124 | ; clause_kind = |
| 125 | List_clause { args = Cons (int_sexp_grammar.untyped, Empty) } |
| 126 | } |
| 127 | ; No_tag |
| 128 | { name = "List" |
| 129 | ; clause_kind = |
| 130 | List_clause |
| 131 | { args = |
| 132 | Cons ((list_sexp_grammar int_sexp_grammar).untyped, Empty) |
| 133 | } |
| 134 | } |
| 135 | ; No_tag |
| 136 | { name = "Sexp_dot_list" |
| 137 | ; clause_kind = |
| 138 | List_clause { args = Many int_sexp_grammar.untyped } |
| 139 | } |
| 140 | ] |
| 141 | })) |
| 142 | } |
| 143 | ;; |
| 144 | |
| 145 | let _ = t_sexp_grammar |
| 146 | |
| 147 | [@@@end] |
| 148 | |
| 149 | let (T : (With_sexp.t, t) Type_equal.t) = T |
| 150 | |
| 151 | open Expect_test_helpers_base |
| 152 | |
| 153 | let%expect_test _ = |
| 154 | print_s (With_sexp.sexp_of_t (`Int 1)); |
| 155 | List.iter |
| 156 | [ []; [ 1 ]; [ 1; 2 ] ] |
| 157 | ~f:(fun l -> |
| 158 | print_s (With_sexp.sexp_of_t (`List l)); |
| 159 | print_s (With_sexp.sexp_of_t (`Sexp_dot_list l))); |
| 160 | [%expect |
| 161 | {| |
| 162 | (Int 1) |
| 163 | (List ()) |
| 164 | (Sexp_dot_list) |
| 165 | (List (1)) |
| 166 | (Sexp_dot_list 1) |
| 167 | (List (1 2)) |
| 168 | (Sexp_dot_list 1 2) |
| 169 | |}] |
| 170 | ;; |
| 171 | end |