]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_notation/grafiteAst.ml
ocaml 3.09 transition
[helm.git] / helm / ocaml / cic_notation / grafiteAst.ml
1 (* Copyright (C) 2004, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 module Ast = CicNotationPt
27
28 type direction = [ `LeftToRight | `RightToLeft ]
29
30 type loc = Ast.location
31
32 type ('term, 'lazy_term, 'ident) pattern =
33   'lazy_term option * ('ident * 'term) list * 'term
34
35 type ('term, 'ident) type_spec =
36    | Ident of 'ident
37    | Type of UriManager.uri * int 
38
39 type reduction =
40   [ `Normalize
41   | `Reduce
42   | `Simpl
43   | `Unfold of CicNotationPt.term option
44   | `Whd ]
45
46 type ('term, 'lazy_term, 'reduction, 'ident) tactic =
47   | Absurd of loc * 'term
48   | Apply of loc * 'term
49   | Assumption of loc
50   | Auto of loc * int option * int option * string option * string option 
51       (* depth, width, paramodulation, full *) (* ALB *)
52   | Change of loc * ('term, 'lazy_term, 'ident) pattern * 'lazy_term
53   | Clear of loc * 'ident
54   | ClearBody of loc * 'ident
55   | Compare of loc * 'term
56   | Constructor of loc * int
57   | Contradiction of loc
58   | Cut of loc * 'ident option * 'term
59   | DecideEquality of loc
60   | Decompose of loc * ('term, 'ident) type_spec list * 'ident * 'ident list
61   | Discriminate of loc * 'term
62   | Elim of loc * 'term * 'term option * int option * 'ident list
63   | ElimType of loc * 'term * 'term option * int option * 'ident list
64   | Exact of loc * 'term
65   | Exists of loc
66   | Fail of loc
67   | Fold of loc * 'reduction * 'lazy_term * ('term, 'lazy_term, 'ident) pattern
68   | Fourier of loc
69   | FwdSimpl of loc * string * 'ident list
70   | Generalize of loc * ('term, 'lazy_term, 'ident) pattern * 'ident option
71   | Goal of loc * int (* change current goal, argument is goal number 1-based *)
72   | IdTac of loc
73   | Injection of loc * 'term
74   | Intros of loc * int option * 'ident list
75   | LApply of loc * int option * 'term list * 'term * 'ident option
76   | Left of loc
77   | LetIn of loc * 'term * 'ident
78   | Reduce of loc * 'reduction * ('term, 'lazy_term, 'ident) pattern 
79   | Reflexivity of loc
80   | Replace of loc * ('term, 'lazy_term, 'ident) pattern * 'lazy_term
81   | Rewrite of loc * direction * 'term *
82       ('term, 'lazy_term, 'ident) pattern
83   | Right of loc
84   | Ring of loc
85   | Split of loc
86   | Symmetry of loc
87   | Transitivity of loc * 'term
88
89 type thm_flavour = Cic.object_flavour
90
91   (** <name, inductive/coinductive, type, constructor list>
92   * true means inductive, false coinductive *)
93 type 'term inductive_type = string * bool * 'term * (string * 'term) list
94
95 type search_kind = [ `Locate | `Hint | `Match | `Elim ]
96
97 type print_kind = [ `Env | `Coer ]
98
99 type 'term macro = 
100   (* Whelp's stuff *)
101   | WHint of loc * 'term 
102   | WMatch of loc * 'term 
103   | WInstance of loc * 'term 
104   | WLocate of loc * string
105   | WElim of loc * 'term
106   (* real macros *)
107 (*   | Abort of loc *)
108   | Print of loc * string
109   | Check of loc * 'term 
110   | Hint of loc
111   | Quit of loc
112 (*   | Redo of loc * int option
113   | Undo of loc * int option *)
114 (*   | Print of loc * print_kind *)
115   | Search_pat of loc * search_kind * string  (* searches with string pattern *)
116   | Search_term of loc * search_kind * 'term  (* searches with term pattern *)
117
118 type alias_spec =
119   | Ident_alias of string * string        (* identifier, uri *)
120   | Symbol_alias of string * int * string (* name, instance no, description *)
121   | Number_alias of int * string          (* instance no, description *)
122
123 type obj =
124   | Inductive of (string * Ast.term) list *
125       Ast.term inductive_type list
126       (** parameters, list of loc * mutual inductive types *)
127   | Theorem of thm_flavour * string * Ast.term * Ast.term option
128       (** flavour, name, type, body
129        * - name is absent when an unnamed theorem is being proved, tipically in
130        *   interactive usage
131        * - body is present when its given along with the command, otherwise it
132        *   will be given in proof editing mode using the tactical language
133        *)
134   | Record of (string * Ast.term) list * string * Ast.term *
135       (string * Ast.term) list
136       (** left parameters, name, type, fields *)
137
138 type metadata =
139   | Dependency of string  (* baseuri without trailing slash *)
140   | Baseuri of string 
141
142 let compare_metadata = Pervasives.compare
143
144 let eq_metadata = (=)
145
146 (** To be increased each time the command type below changes, used for "safe"
147  * marshalling *)
148 let magic = 2
149
150 type ('term,'obj) command =
151   | Default of loc * string * UriManager.uri list
152   | Include of loc * string
153   | Set of loc * string * string
154   | Drop of loc
155   | Qed of loc
156       (** name.
157        * Name is needed when theorem was started without providing a name
158        *)
159   | Coercion of loc * 'term
160   | Alias of loc * alias_spec
161       (** parameters, name, type, fields *) 
162   | Obj of loc * 'obj
163   | Notation of loc * direction option * Ast.term * Gramext.g_assoc *
164       int * Ast.term
165       (* direction, l1 pattern, associativity, precedence, l2 pattern *)
166   | Interpretation of loc *
167       string * (string * Ast.argument_pattern list) *
168         Ast.cic_appl_pattern
169       (* description (i.e. id), symbol, arg pattern, appl pattern *)
170
171   | Metadata of loc * metadata
172
173     (* DEBUGGING *)
174   | Dump of loc (* dump grammar on stdout *)
175     (* DEBUGGING *)
176   | Render of loc * UriManager.uri (* render library object *)
177
178 (* composed magic: term + command magics. No need to change this value *)
179 let magic = magic + 10000 * CicNotationPt.magic
180
181 let reash_cmd_uris =
182   let reash_uri uri = UriManager.uri_of_string (UriManager.string_of_uri uri) in
183   function
184   | Default (loc, name, uris) ->
185       let uris = List.map reash_uri uris in
186       Default (loc, name, uris)
187   | Interpretation (loc, dsc, args, cic_appl_pattern) ->
188       let rec aux =
189         function
190         | CicNotationPt.UriPattern uri ->
191             CicNotationPt.UriPattern (reash_uri uri)
192         | CicNotationPt.ApplPattern args ->
193             CicNotationPt.ApplPattern (List.map aux args)
194         | CicNotationPt.VarPattern _
195         | CicNotationPt.ImplicitPattern as pat -> pat
196       in
197       let appl_pattern = aux cic_appl_pattern in
198       Interpretation (loc, dsc, args, appl_pattern)
199   | cmd -> cmd
200
201 type ('term, 'lazy_term, 'reduction, 'ident) tactical =
202   | Tactic of loc * ('term, 'lazy_term, 'reduction, 'ident) tactic
203   | Do of loc * int * ('term, 'lazy_term, 'reduction, 'ident) tactical
204   | Repeat of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical
205   | Seq of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical list
206       (* sequential composition *)
207   | Then of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical *
208       ('term, 'lazy_term, 'reduction, 'ident) tactical list
209   | First of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical list
210       (* try a sequence of loc * tactical until one succeeds, fail otherwise *)
211   | Try of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical
212       (* try a tactical and mask failures *)
213   | Solve of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical list
214
215   | Dot of loc
216   | Semicolon of loc
217   | Branch of loc
218   | Shift of loc
219   | Pos of loc * int
220   | Merge of loc
221   | Focus of loc * int list
222   | Unfocus of loc
223   | Skip of loc
224
225 let is_punctuation =
226   function
227   | Dot _ | Semicolon _ | Branch _ | Shift _ | Merge _ | Pos _ -> true
228   | _ -> false
229
230 type ('term, 'lazy_term, 'reduction, 'obj, 'ident) code =
231   | Command of loc * ('term,'obj) command
232   | Macro of loc * 'term macro 
233   | Tactical of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical
234       * ('term, 'lazy_term, 'reduction, 'ident) tactical option(* punctuation *)
235              
236 type ('term, 'lazy_term, 'reduction, 'obj, 'ident) comment =
237   | Note of loc * string
238   | Code of loc * ('term, 'lazy_term, 'reduction, 'obj, 'ident) code
239              
240 type ('term, 'lazy_term, 'reduction, 'obj, 'ident) statement =
241   | Executable of loc * ('term, 'lazy_term, 'reduction, 'obj, 'ident) code
242   | Comment of loc * ('term, 'lazy_term, 'reduction, 'obj, 'ident) comment
243
244   (* statements meaningful for matitadep *)
245 type dependency =
246   | IncludeDep of string
247   | BaseuriDep of string
248   | UriDep of UriManager.uri
249