/
outline_utils.ml
41 lines (34 loc) · 1.01 KB
/
outline_utils.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
type offset = History.offset
type position = Lexing.position
type kind =
| Enter_module
| Leave_module
| Definition
| Rollback
| Done
| Unterminated
| Syntax_error of Location.t
| Exception of exn
exception Chunk of kind * position
(** Used to ignore first-class modules.
* The construct "let module = … in " allows to define a module
* locally inside a definition, but our outline parser cannot work
* inside a definition (it is either correct as a whole,
* or incorrect).
* [nesting] is incremented at the beginning of such constructions
* (here, [let module]) and decremented at its end (here, after the
* module expression is parsed).No module definition is reported
* while [!nesting > 0].
*)
let nesting = ref 0
let reset () = nesting := 0
let enter_sub () =
incr nesting
let leave_sub () =
(if !nesting <= 0
then failwith "Outline_utils.leave: invalid nesting");
decr nesting
let emit_top c pos =
(*prerr_endline "emit";*)
if !nesting = 0 then
raise (Chunk (c,pos))