]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/grafite/grafiteAst.ml
f3687789b4ffef162f9c341c14fae13008529b9a
[helm.git] / helm / ocaml / grafite / 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 search_kind = [ `Locate | `Hint | `Match | `Elim ]
90
91 type print_kind = [ `Env | `Coer ]
92
93 type 'term macro = 
94   (* Whelp's stuff *)
95   | WHint of loc * 'term 
96   | WMatch of loc * 'term 
97   | WInstance of loc * 'term 
98   | WLocate of loc * string
99   | WElim of loc * 'term
100   (* real macros *)
101 (*   | Abort of loc *)
102   | Print of loc * string
103   | Check of loc * 'term 
104   | Hint of loc
105   | Quit of loc
106 (*   | Redo of loc * int option
107   | Undo of loc * int option *)
108 (*   | Print of loc * print_kind *)
109   | Search_pat of loc * search_kind * string  (* searches with string pattern *)
110   | Search_term of loc * search_kind * 'term  (* searches with term pattern *)
111
112 type alias_spec =
113   | Ident_alias of string * string        (* identifier, uri *)
114   | Symbol_alias of string * int * string (* name, instance no, description *)
115   | Number_alias of int * string          (* instance no, description *)
116
117 type metadata =
118   | Dependency of string  (* baseuri without trailing slash *)
119   | Baseuri of string 
120
121 let compare_metadata = Pervasives.compare
122
123 let eq_metadata = (=)
124
125 (** To be increased each time the command type below changes, used for "safe"
126  * marshalling *)
127 let magic = 3
128
129 type ('term,'obj) command =
130   | Default of loc * string * UriManager.uri list
131   | Include of loc * string
132   | Set of loc * string * string
133   | Drop of loc
134   | Qed of loc
135       (** name.
136        * Name is needed when theorem was started without providing a name
137        *)
138   | Coercion of loc * 'term * bool (* add composites *)
139   | Alias of loc * alias_spec
140       (** parameters, name, type, fields *) 
141   | Obj of loc * 'obj
142   | Notation of loc * direction option * Ast.term * Gramext.g_assoc *
143       int * Ast.term
144       (* direction, l1 pattern, associativity, precedence, l2 pattern *)
145   | Interpretation of loc *
146       string * (string * Ast.argument_pattern list) *
147         Ast.cic_appl_pattern
148       (* description (i.e. id), symbol, arg pattern, appl pattern *)
149
150   | Metadata of loc * metadata
151
152     (* DEBUGGING *)
153   | Dump of loc (* dump grammar on stdout *)
154     (* DEBUGGING *)
155   | Render of loc * UriManager.uri (* render library object *)
156
157 (* composed magic: term + command magics. No need to change this value *)
158 let magic = magic + 10000 * CicNotationPt.magic
159
160 let reash_cmd_uris =
161   let reash_uri uri = UriManager.uri_of_string (UriManager.string_of_uri uri) in
162   function
163   | Default (loc, name, uris) ->
164       let uris = List.map reash_uri uris in
165       Default (loc, name, uris)
166   | Interpretation (loc, dsc, args, cic_appl_pattern) ->
167       let rec aux =
168         function
169         | CicNotationPt.UriPattern uri ->
170             CicNotationPt.UriPattern (reash_uri uri)
171         | CicNotationPt.ApplPattern args ->
172             CicNotationPt.ApplPattern (List.map aux args)
173         | CicNotationPt.VarPattern _
174         | CicNotationPt.ImplicitPattern as pat -> pat
175       in
176       let appl_pattern = aux cic_appl_pattern in
177       Interpretation (loc, dsc, args, appl_pattern)
178   | cmd -> cmd
179
180 type ('term, 'lazy_term, 'reduction, 'ident) tactical =
181   | Tactic of loc * ('term, 'lazy_term, 'reduction, 'ident) tactic
182   | Do of loc * int * ('term, 'lazy_term, 'reduction, 'ident) tactical
183   | Repeat of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical
184   | Seq of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical list
185       (* sequential composition *)
186   | Then of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical *
187       ('term, 'lazy_term, 'reduction, 'ident) tactical list
188   | First of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical list
189       (* try a sequence of loc * tactical until one succeeds, fail otherwise *)
190   | Try of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical
191       (* try a tactical and mask failures *)
192   | Solve of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical list
193
194   | Dot of loc
195   | Semicolon of loc
196   | Branch of loc
197   | Shift of loc
198   | Pos of loc * int
199   | Merge of loc
200   | Focus of loc * int list
201   | Unfocus of loc
202   | Skip of loc
203
204 let is_punctuation =
205   function
206   | Dot _ | Semicolon _ | Branch _ | Shift _ | Merge _ | Pos _ -> true
207   | _ -> false
208
209 type ('term, 'lazy_term, 'reduction, 'obj, 'ident) code =
210   | Command of loc * ('term,'obj) command
211   | Macro of loc * 'term macro 
212   | Tactical of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical
213       * ('term, 'lazy_term, 'reduction, 'ident) tactical option(* punctuation *)
214              
215 type ('term, 'lazy_term, 'reduction, 'obj, 'ident) comment =
216   | Note of loc * string
217   | Code of loc * ('term, 'lazy_term, 'reduction, 'obj, 'ident) code
218              
219 type ('term, 'lazy_term, 'reduction, 'obj, 'ident) statement =
220   | Executable of loc * ('term, 'lazy_term, 'reduction, 'obj, 'ident) code
221   | Comment of loc * ('term, 'lazy_term, 'reduction, 'obj, 'ident) comment
222
223   (* statements meaningful for matitadep *)
224 type dependency =
225   | IncludeDep of string
226   | BaseuriDep of string
227   | UriDep of UriManager.uri
228