Commit | Line | Data |
---|---|---|
951c7801 C |
1 | module Past = Ast_popl |
2 | ||
3 | (* --------------------------------------------------------------------- *) | |
4 | ||
5 | let rec get_before a = function | |
6 | Past.Seq(elem,seq) -> | |
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" | |
12 | ||
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" | |
23 | ||
24 | and get_before_dots a = function | |
25 | Past.Dots -> Past.Dots | |
26 | | Past.Nest(seq) -> | |
27 | let (seq,_) = get_before a seq in | |
28 | Past.Nest(seq) | |
29 | | Past.When(dots,seq) -> | |
30 | let dots = get_before_dots a dots in | |
31 | let (seq,_) = get_before [] seq in | |
32 | Past.When(dots,seq) | |
33 | | Past.DExists(var,dots) -> failwith "not possible" | |
34 | ||
35 | (* --------------------------------------------------------------------- *) | |
36 | ||
37 | let rec get_after a = function | |
38 | Past.Seq(elem,seq) -> | |
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" | |
44 | ||
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" | |
55 | ||
56 | and get_after_dots a = function | |
57 | Past.Dots -> Past.Dots | |
58 | | Past.Nest(seq) -> | |
59 | let (seq,_) = get_after (Common.union_set (get_first [] seq) a) seq in | |
60 | Past.Nest(seq) | |
61 | | Past.When(dots,seq) -> | |
62 | let dots = get_after_dots a dots in | |
63 | let (seq,_) = get_after [] seq in | |
64 | Past.When(dots,seq) | |
65 | | Past.DExists(var,dots) -> failwith "not possible" | |
66 | ||
67 | (* --------------------------------------------------------------------- *) | |
68 | (* like get_after, but just returns the a component; doesn't modify the term *) | |
69 | ||
70 | and get_first a = function | |
71 | Past.Seq(elem,seq) -> | |
72 | let sla = get_first a seq in | |
73 | let ea = get_first_element sla elem in | |
74 | ea | |
75 | | Past.Empty -> a | |
76 | | Past.SExists(var,seq) -> failwith "not possible" | |
77 | ||
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" | |
84 | ||
85 | (* --------------------------------------------------------------------- *) | |
86 | (* Entry point *) | |
87 | ||
88 | let insert_befaft sl = | |
89 | let (sl,_) = get_before [] sl in | |
90 | let (sl,_) = get_after [] sl in | |
91 | sl |