3 (* --------------------------------------------------------------------- *)
5 let rec get_before a
= function
7 let (elem
,ea
) = get_before_element a elem
in
8 let (seq
,sla
) = get_before ea seq
in
9 (Past.Seq
(elem
,seq
),sla
)
10 | Past.Empty
-> (Past.Empty
,a
)
11 | Past.SExists
(var
,seq
) -> failwith
"not possible"
13 and get_before_element a
= function
14 Past.Term
(term
) as s
-> (s
,[s
])
15 | Past.Or
(seq1
,seq2
) ->
16 let (seq1
,seq1a
) = get_before a seq1
in
17 let (seq2
,seq2a
) = get_before a seq2
in
18 (Past.Or
(seq1
,seq2
),Common.union_set seq1a seq2a
)
19 | Past.DInfo
(dots
,_
,seq_aft
) ->
20 let dots = get_before_dots a
dots in
21 (Past.DInfo
(dots,a
,seq_aft
),a
)
22 | Past.EExists
(var
,seq
) -> failwith
"not possible"
24 and get_before_dots a
= function
25 Past.Dots
-> Past.Dots
27 let (seq
,_
) = get_before a seq
in
29 | Past.When
(dots,seq
) ->
30 let dots = get_before_dots a
dots in
31 let (seq
,_
) = get_before [] seq
in
33 | Past.DExists
(var
,dots) -> failwith
"not possible"
35 (* --------------------------------------------------------------------- *)
37 let rec get_after a
= function
39 let (seq
,sla
) = get_after a seq
in
40 let (elem
,ea
) = get_after_element sla elem
in
41 (Past.Seq
(elem
,seq
),ea
)
42 | Past.Empty
-> (Past.Empty
,a
)
43 | Past.SExists
(var
,seq
) -> failwith
"not possible"
45 and get_after_element a
= function
46 Past.Term
(term
) as s
-> (s
,[s
])
47 | Past.Or
(seq1
,seq2
) ->
48 let (seq1
,seq1a
) = get_after a seq1
in
49 let (seq2
,seq2a
) = get_after a seq2
in
50 (Past.Or
(seq1
,seq2
),Common.union_set seq1a seq2a
)
51 | Past.DInfo
(dots,seq_bef
,_
) ->
52 let dots = get_after_dots a
dots in
53 (Past.DInfo
(dots,seq_bef
,a
),a
)
54 | Past.EExists
(var
,seq
) -> failwith
"not possible"
56 and get_after_dots a
= function
57 Past.Dots
-> Past.Dots
59 let (seq
,_
) = get_after (Common.union_set
(get_first
[] seq
) a
) seq
in
61 | Past.When
(dots,seq
) ->
62 let dots = get_after_dots a
dots in
63 let (seq
,_
) = get_after [] seq
in
65 | Past.DExists
(var
,dots) -> failwith
"not possible"
67 (* --------------------------------------------------------------------- *)
68 (* like get_after, but just returns the a component; doesn't modify the term *)
70 and get_first a
= function
72 let sla = get_first a seq
in
73 let ea = get_first_element
sla elem
in
76 | Past.SExists
(var
,seq
) -> failwith
"not possible"
78 and get_first_element a
= function
79 Past.Term
(term
) as s
-> [s
]
80 | Past.Or
(seq1
,seq2
) ->
81 Common.union_set
(get_first a seq1
) (get_first a seq2
)
82 | Past.DInfo
(dots,_
,_
) -> a
83 | Past.EExists
(var
,seq
) -> failwith
"not possible"
85 (* --------------------------------------------------------------------- *)
88 let insert_befaft sl
=
89 let (sl
,_
) = get_before [] sl
in
90 let (sl
,_
) = get_after [] sl
in