Debian Codegraph @

test/sexp_grammar/test_regular_variants.ml

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