]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_notation/grafiteAst.ml
bugfix: reash uris embedded in cic appl patterns
[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
51       (* depth, width, paramodulation *)
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 *
128       Ast.term option
129       (** flavour, name, type, body
130        * - name is absent when an unnamed theorem is being proved, tipically in
131        *   interactive usage
132        * - body is present when its given along with the command, otherwise it
133        *   will be given in proof editing mode using the tactical language
134        *)
135   | Record of (string * Ast.term) list * string * Ast.term *
136       (string * Ast.term) list
137       (** left parameters, name, type, fields *)
138
139 (** To be increased each time the command type below changes, used for "safe"
140  * marshalling *)
141 let magic = 1
142
143 type ('term,'obj) command =
144   | Default of loc * string * UriManager.uri list
145   | Include of loc * string
146   | Set of loc * string * string
147   | Drop of loc
148   | Qed of loc
149       (** name.
150        * Name is needed when theorem was started without providing a name
151        *)
152   | Coercion of loc * 'term
153   | Alias of loc * alias_spec
154       (** parameters, name, type, fields *) 
155   | Obj of loc * 'obj
156   | Notation of loc * direction option * Ast.term * Gramext.g_assoc *
157       int * Ast.term
158       (* direction, l1 pattern, associativity, precedence, l2 pattern *)
159   | Interpretation of loc *
160       string * (string * Ast.argument_pattern list) *
161         Ast.cic_appl_pattern
162       (* description (i.e. id), symbol, arg pattern, appl pattern *)
163
164     (* DEBUGGING *)
165   | Dump of loc (* dump grammar on stdout *)
166     (* DEBUGGING *)
167   | Render of loc * UriManager.uri (* render library object *)
168
169 (* composed magic: term + command magics. No need to change this value *)
170 let magic = magic + 10000 * CicNotationPt.magic
171
172 let reash_cmd_uris =
173   let reash_uri uri = UriManager.uri_of_string (UriManager.string_of_uri uri) in
174   function
175   | Default (loc, name, uris) ->
176       let uris = List.map reash_uri uris in
177       Default (loc, name, uris)
178   | Interpretation (loc, dsc, args, cic_appl_pattern) ->
179       let rec aux =
180         function
181         | CicNotationPt.UriPattern uri ->
182             CicNotationPt.UriPattern (reash_uri uri)
183         | CicNotationPt.ApplPattern args ->
184             CicNotationPt.ApplPattern (List.map aux args)
185         | CicNotationPt.VarPattern _
186         | CicNotationPt.ImplicitPattern as pat -> pat
187       in
188       let appl_pattern = aux cic_appl_pattern in
189       Interpretation (loc, dsc, args, appl_pattern)
190   | cmd -> cmd
191
192 type ('term, 'lazy_term, 'reduction, 'ident) tactical =
193   | Tactic of loc * ('term, 'lazy_term, 'reduction, 'ident) tactic
194   | Do of loc * int * ('term, 'lazy_term, 'reduction, 'ident) tactical
195   | Repeat of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical
196   | Seq of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical list
197       (* sequential composition *)
198   | Then of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical *
199       ('term, 'lazy_term, 'reduction, 'ident) tactical list
200   | First of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical list
201       (* try a sequence of loc * tacticals until one succeeds, fail otherwise *)
202   | Try of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical
203       (* try a tactical and mask failures *)
204   | Solve of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical list
205
206
207 type ('term, 'lazy_term, 'reduction, 'obj, 'ident) code =
208   | Command of loc * ('term,'obj) command
209   | Macro of loc * 'term macro 
210   | Tactical of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical
211              
212 type ('term, 'lazy_term, 'reduction, 'obj, 'ident) comment =
213   | Note of loc * string
214   | Code of loc * ('term, 'lazy_term, 'reduction, 'obj, 'ident) code
215              
216 type ('term, 'lazy_term, 'reduction, 'obj, 'ident) statement =
217   | Executable of loc * ('term, 'lazy_term, 'reduction, 'obj, 'ident) code
218   | Comment of loc * ('term, 'lazy_term, 'reduction, 'obj, 'ident) comment
219
220   (* statements meaningful for matitadep *)
221 type dependency =
222   | IncludeDep of string
223   | BaseuriDep of string
224   | UriDep of UriManager.uri
225