1
(* packaging of annotated sexp functions *)
5
module M = Sexp.With_layout
7
TEST_MODULE "forget" = struct
10
let dumb_pos = {M.row = 0; col = 0}
11
let dumb_comment = M.Plain_comment (dumb_pos, "comment")
13
let atom x = M.Sexp (M.Atom (dumb_pos, x, None))
14
let list ts = M.Sexp (M.List (dumb_pos, ts, dumb_pos))
15
let comment = M.Comment dumb_comment
19
let a3 = list [comment; atom "yo"; comment; atom "yo"; comment; atom "ma"; comment]
20
let a4 = list [comment; a1; comment; a2; comment; a3; comment; a3]
21
let a5 = list [comment; a1; comment; a2; comment; a3; comment; a4]
23
let b2 = Sexp.Atom "hello"
24
let b3 = Sexp.List [Sexp.Atom "yo"; Sexp.Atom "yo"; Sexp.Atom "ma"]
25
let b4 = Sexp.List [b2; b3; b3]
26
let b5 = Sexp.List [b2; b3; b4]
28
TEST = M.Forget.t_or_comment a1 = None
29
TEST = M.Forget.t_or_comment a2 = Some b2
30
TEST = M.Forget.t_or_comment a3 = Some b3
31
TEST = M.Forget.t_or_comment a4 = Some b4
32
TEST = M.Forget.t_or_comment a5 = Some b5
34
module Simple_forget = struct
36
| M.Atom (_, x, _) -> Sexp.Atom x
37
| M.List (_, ts, _) -> Sexp.List (t_or_comments ts)
38
and t_or_comments = function
41
match t_or_comment t with
42
| None -> t_or_comments ts
43
| Some s -> s :: t_or_comments ts
44
and t_or_comment = function
45
| M.Sexp x -> Some (t x)
49
let same_as_simple x = M.Forget.t_or_comment x = Simple_forget.t_or_comment x
51
TEST = same_as_simple a1
52
TEST = same_as_simple a2
53
TEST = same_as_simple a3
54
TEST = same_as_simple a4
55
TEST = same_as_simple a5