@@ -22,6 +22,20 @@ module LM = Map.Make (Int)
22
22
23
23
module SM = Map. Make (Stateid )
24
24
25
+ type proof_block_type =
26
+ | TheoremKind of Decls .theorem_kind
27
+ | DefinitionType of Decls .definition_object_kind
28
+
29
+ type outline_element = {
30
+ id : sentence_id ;
31
+ name : string ;
32
+ type_ : proof_block_type ;
33
+ statement : string ;
34
+ range : Range .t
35
+ }
36
+
37
+ type outline = outline_element list
38
+
25
39
type parsed_ast = {
26
40
ast : Synterp .vernac_control_entry ;
27
41
classification : Vernacextend .vernac_classification ;
@@ -71,15 +85,12 @@ type document = {
71
85
parsing_errors_by_end : parsing_error LM .t ;
72
86
comments_by_end : comment LM .t ;
73
87
schedule : Scheduler .schedule ;
88
+ outline : outline ;
74
89
parsed_loc : int ;
75
90
raw_doc : RawDocument .t ;
76
91
init_synterp_state : Vernacstate.Synterp .t ;
77
92
}
78
93
79
- let schedule doc = doc.schedule
80
-
81
- let raw_document doc = doc.raw_doc
82
-
83
94
let range_of_sentence raw (sentence : sentence ) =
84
95
let start = RawDocument. position_of_loc raw sentence.start in
85
96
let end_ = RawDocument. position_of_loc raw sentence.stop in
@@ -100,6 +111,61 @@ let range_of_id_with_blank_space document id =
100
111
| None -> CErrors. anomaly Pp. (str" Trying to get range of non-existing sentence " ++ Stateid. print id)
101
112
| Some sentence -> range_of_sentence_with_blank_space document.raw_doc sentence
102
113
114
+
115
+ let record_outline document id (ast : Synterp.vernac_control_entry ) classif (outline : outline ) =
116
+ let open Vernacextend in
117
+ match classif with
118
+ | VtStartProof (_ , names ) ->
119
+ let vernac_gen_expr = ast.v.expr in
120
+ let type_ = match vernac_gen_expr with
121
+ | VernacSynterp _ -> None
122
+ | VernacSynPure pure ->
123
+ match pure with
124
+ | Vernacexpr. VernacStartTheoremProof (kind , _ ) -> Some (TheoremKind kind)
125
+ | Vernacexpr. VernacDefinition ((_ , def ), _ , _ ) -> Some (DefinitionType def)
126
+ | _ -> None
127
+ in
128
+ let name = match names with
129
+ | [] -> " default"
130
+ | n :: _ -> Names.Id. to_string n
131
+ in
132
+ let statement = " " in
133
+ begin match type_ with
134
+ | None -> outline
135
+ | Some type_ ->
136
+ let range = range_of_id document id in
137
+ let element = {id; type_; name; statement; range} in
138
+ element :: outline
139
+ end
140
+ | VtSideff (names , _ ) ->
141
+ let vernac_gen_expr = ast.v.expr in
142
+ let type_ = match vernac_gen_expr with
143
+ | VernacSynterp _ -> None
144
+ | VernacSynPure pure ->
145
+ match pure with
146
+ | Vernacexpr. VernacStartTheoremProof (kind , _ ) -> Some (TheoremKind kind)
147
+ | Vernacexpr. VernacDefinition ((_ , def ), _ , _ ) -> Some (DefinitionType def)
148
+ | _ -> None
149
+ in
150
+ let name = match names with
151
+ | [] -> " default"
152
+ | n :: _ -> Names.Id. to_string n
153
+ in
154
+ let statement = " " in
155
+ begin match type_ with
156
+ | None -> outline
157
+ | Some type_ ->
158
+ let range = range_of_id document id in
159
+ let element = {id; type_; name; statement; range} in
160
+ element :: outline
161
+ end
162
+ | _ -> outline
163
+
164
+ let schedule doc = doc.schedule
165
+
166
+ let raw_document doc = doc.raw_doc
167
+
168
+ let outline doc = doc.outline
103
169
let parse_errors parsed =
104
170
List. map snd (LM. bindings parsed.parsing_errors_by_end)
105
171
@@ -111,19 +177,23 @@ let add_sentence parsed parsing_start start stop (ast: parsed_ast) synterp_state
111
177
in
112
178
(* FIXME may invalidate scheduler_state_XXX for following sentences -> propagate? *)
113
179
let sentence = { parsing_start; start; stop; ast; id; synterp_state; scheduler_state_before; scheduler_state_after } in
114
- { parsed with sentences_by_end = LM. add stop sentence parsed.sentences_by_end;
180
+ let document = {
181
+ parsed with sentences_by_end = LM. add stop sentence parsed.sentences_by_end;
115
182
sentences_by_id = SM. add id sentence parsed.sentences_by_id;
116
- schedule
117
- }, scheduler_state_after
183
+ schedule;
184
+ } in
185
+ let outline = record_outline document id ast.ast ast.classification parsed.outline in
186
+ {document with outline}, scheduler_state_after
118
187
119
188
let remove_sentence parsed id =
120
189
match SM. find_opt id parsed.sentences_by_id with
121
190
| None -> parsed
122
191
| Some sentence ->
123
192
let sentences_by_id = SM. remove id parsed.sentences_by_id in
124
193
let sentences_by_end = LM. remove sentence.stop parsed.sentences_by_end in
194
+ let outline = List. filter (fun (e : outline_element ) -> e.id != id) parsed.outline in
125
195
(* TODO clean up the schedule and free cached states *)
126
- { parsed with sentences_by_id; sentences_by_end; }
196
+ { parsed with sentences_by_id; sentences_by_end; outline }
127
197
128
198
let sentences parsed =
129
199
List. map snd @@ SM. bindings parsed.sentences_by_id
@@ -490,6 +560,7 @@ let create_document init_synterp_state text =
490
560
parsing_errors_by_end = LM. empty;
491
561
comments_by_end = LM. empty;
492
562
schedule = initial_schedule;
563
+ outline = [] ;
493
564
init_synterp_state;
494
565
}
495
566
0 commit comments