Debian Codegraph @

ide/rocqide/document.mli

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 (* An 'a document is a structure to hold and manipulate list of sentences.
12 Sentences are equipped with an id = Stateid.t and can carry arbitrary
13 data ('a).
14
15 When added (push) to the document, a sentence has no id, it has
16 be manually assigned just afterward or the sentence has to be removed
17 (pop) before any other sentence can be pushed.
18 This exception is useful since the process of assigning an id to
19 a sentence may fail (parse error) and an error handler may want to annotate
20 a script buffer with the error message. This handler needs to find the
21 sentence in question, and it is simpler if the sentence is in the document.
22 Only the functions pop, find, fold_all and find_map can be called on a
23 document with a tip that has no id (and assign_tip_id of course).
24
25 The document can be focused (non recursively) to a zone. After that
26 some functions operate on the focused zone only. When unfocused the
27 context (the part of the document out of focus) is restored.
28 *)
29
30 exception Empty
31
32 type 'a document
33 type id = Stateid.t
34
35 val create : unit -> 'a document
36
37 (* Functions that work on the focused part of the document ******************* *)
38
39 (** The last sentence.
40 @raise Invalid_argument if tip has no id.
41 @raise Empty *)
42 val tip : 'a document -> id
43
44 (** The last sentence.
45 @raise Empty *)
46 val tip_data : 'a document -> 'a
47
48 (** Add a sentence on the top (with no state_id) *)
49 val push : 'a document -> 'a -> unit
50
51 (** Remove the tip setence.
52 @raise Empty *)
53 val pop : 'a document -> 'a
54
55 (** preserve the last error(s) (tooltip fix) *)
56 val set_errors : 'a document -> string list -> unit
57
58 (** get the last error(s) (tooltip fix) *)
59 val get_errors : 'a document -> string list
60
61 (** Assign the state_id of the tip.
62 @raise Empty *)
63 val assign_tip_id : 'a document -> id -> unit
64
65 (** [cut_at d id] cuts the document at [id] that is the new tip.
66 Returns the list of sentences that were cut.
67 @raise Not_found *)
68 val cut_at : 'a document -> id -> 'a list
69
70 (* Functions that work on the whole document ********************************* *)
71
72 (** returns the id of the topmost sentence validating the predicate and
73 a boolean that is true if one needs to unfocus the document to access
74 such sentence.
75 @raise Not_found *)
76 val find_id : 'a document -> (id -> 'a -> bool) -> id * bool
77
78 (** look for a sentence validating the predicate. The boolean is true
79 if the sentence is in the zone currently focused.
80 @raise Not_found *)
81 val find : 'a document -> (bool -> id option -> 'a -> bool) -> 'a
82 val find_map : 'a document -> (bool -> id option -> 'a -> 'b option) -> 'b
83
84 (** After [focus s c1 c2] the top of [s] is the topmost element [x] such that
85 [c1 x] is [true] and the bottom is the first element [y] following [x]
86 such that [c2 y] is [true].
87 @raise Invalid_argument if there is no such [x] and [y] or already focused *)
88 val focus :
89 'a document ->
90 cond_top:(id -> 'a -> bool) -> cond_bot:(id -> 'a -> bool) -> unit
91
92 (** Undoes a [focus].
93 @raise Invalid_argument "CStack.unfocus" if the stack is not focused *)
94 val unfocus : 'a document -> unit
95
96 (** Is the document focused *)
97 val focused : 'a document -> bool
98
99 (** No sentences at all *)
100 val is_empty : 'a document -> bool
101
102 (** returns the 1 to-last sentence, and true if we need to unfocus to reach it.
103 @raise Not_found *)
104 val before_tip : 'a document -> id * bool
105
106 (** Is the id in the focused zone? *)
107 val is_in_focus : 'a document -> id -> bool
108
109 (** Folds over the whole document starting from the topmost (maybe unfocused)
110 sentence. *)
111 val fold_all :
112 'a document -> 'c -> ('c -> bool -> id option -> 'a -> 'c) -> 'c
113
114 (** Returns (top,bot) such that the document is morally [top @ s @ bot] where
115 s is the focused part.
116 @raise Invalid_argument *)
117 val context : 'a document -> (id * 'a) list * (id * 'a) list
118
119 (** debug print *)
120 val print :
121 'a document -> (bool -> id option -> 'a -> Pp.t) -> Pp.t
122
123 (** Callbacks on documents *)
124
125 class type ['a] signals =
126 object
127 method popped : callback:('a -> ('a list * 'a list) option -> unit) -> unit
128 method pushed : callback:('a -> ('a list * 'a list) option -> unit) -> unit
129 end
130
131 val connect : 'a document -> 'a signals