]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/grafite/grafiteAst.ml
1. matitaEngine splitted into disambiguation (now in grafite_parser) and
[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 type direction = [ `LeftToRight | `RightToLeft ]
27
28 type loc = CicNotationPt.location
29
30 type ('term, 'lazy_term, 'ident) pattern =
31   'lazy_term option * ('ident * 'term) list * 'term
32
33 type ('term, 'ident) type_spec =
34    | Ident of 'ident
35    | Type of UriManager.uri * int 
36
37 type 'lazy_term reduction =
38   [ `Normalize
39   | `Reduce
40   | `Simpl
41   | `Unfold of 'lazy_term option
42   | `Whd ]
43
44 type ('term, 'lazy_term, 'reduction, 'ident) tactic =
45   | Absurd of loc * 'term
46   | Apply of loc * 'term
47   | Assumption of loc
48   | Auto of loc * int option * int option * string option * string option 
49       (* depth, width, paramodulation, full *) (* ALB *)
50   | Change of loc * ('term, 'lazy_term, 'ident) pattern * 'lazy_term
51   | Clear of loc * 'ident
52   | ClearBody of loc * 'ident
53   | Compare of loc * 'term
54   | Constructor of loc * int
55   | Contradiction of loc
56   | Cut of loc * 'ident option * 'term
57   | DecideEquality of loc
58   | Decompose of loc * ('term, 'ident) type_spec list * 'ident * 'ident list
59   | Discriminate of loc * 'term
60   | Elim of loc * 'term * 'term option * int option * 'ident list
61   | ElimType of loc * 'term * 'term option * int option * 'ident list
62   | Exact of loc * 'term
63   | Exists of loc
64   | Fail of loc
65   | Fold of loc * 'reduction * 'lazy_term * ('term, 'lazy_term, 'ident) pattern
66   | Fourier of loc
67   | FwdSimpl of loc * string * 'ident list
68   | Generalize of loc * ('term, 'lazy_term, 'ident) pattern * 'ident option
69   | Goal of loc * int (* change current goal, argument is goal number 1-based *)
70   | IdTac of loc
71   | Injection of loc * 'term
72   | Intros of loc * int option * 'ident list
73   | LApply of loc * int option * 'term list * 'term * 'ident option
74   | Left of loc
75   | LetIn of loc * 'term * 'ident
76   | Reduce of loc * 'reduction * ('term, 'lazy_term, 'ident) pattern 
77   | Reflexivity of loc
78   | Replace of loc * ('term, 'lazy_term, 'ident) pattern * 'lazy_term
79   | Rewrite of loc * direction * 'term *
80       ('term, 'lazy_term, 'ident) pattern
81   | Right of loc
82   | Ring of loc
83   | Split of loc
84   | Symmetry of loc
85   | Transitivity of loc * 'term
86
87 type search_kind = [ `Locate | `Hint | `Match | `Elim ]
88
89 type print_kind = [ `Env | `Coer ]
90
91 type 'term macro = 
92   (* Whelp's stuff *)
93   | WHint of loc * 'term 
94   | WMatch of loc * 'term 
95   | WInstance of loc * 'term 
96   | WLocate of loc * string
97   | WElim of loc * 'term
98   (* real macros *)
99 (*   | Abort of loc *)
100   | Print of loc * string
101   | Check of loc * 'term 
102   | Hint of loc
103   | Quit of loc
104 (*   | Redo of loc * int option
105   | Undo of loc * int option *)
106 (*   | Print of loc * print_kind *)
107   | Search_pat of loc * search_kind * string  (* searches with string pattern *)
108   | Search_term of loc * search_kind * 'term  (* searches with term pattern *)
109
110 type alias_spec =
111   | Ident_alias of string * string        (* identifier, uri *)
112   | Symbol_alias of string * int * string (* name, instance no, description *)
113   | Number_alias of int * string          (* instance no, description *)
114
115 type metadata =
116   | Dependency of string  (* baseuri without trailing slash *)
117   | Baseuri of string 
118
119 let compare_metadata = Pervasives.compare
120
121 let eq_metadata = (=)
122
123 (** To be increased each time the command type below changes, used for "safe"
124  * marshalling *)
125 let magic = 4
126
127 type ('term,'obj) command =
128   | Default of loc * string * UriManager.uri list
129   | Include of loc * string
130   | Set of loc * string * string
131   | Drop of loc
132   | Qed of loc
133       (** name.
134        * Name is needed when theorem was started without providing a name
135        *)
136   | Coercion of loc * 'term * bool (* add composites *)
137   | Alias of loc * alias_spec
138       (** parameters, name, type, fields *) 
139   | Obj of loc * 'obj
140   | Notation of loc * direction option * CicNotationPt.term * Gramext.g_assoc *
141       int * CicNotationPt.term
142       (* direction, l1 pattern, associativity, precedence, l2 pattern *)
143   | Interpretation of loc *
144       string * (string * CicNotationPt.argument_pattern list) *
145         CicNotationPt.cic_appl_pattern
146       (* description (i.e. id), symbol, arg pattern, appl pattern *)
147
148   | Metadata of loc * metadata
149
150     (* DEBUGGING *)
151   | Dump of loc (* dump grammar on stdout *)
152     (* DEBUGGING *)
153   | Render of loc * UriManager.uri (* render library object *)
154
155 (* composed magic: term + command magics. No need to change this value *)
156 let magic = magic + 10000 * CicNotationPt.magic
157
158 let reash_cmd_uris =
159   let reash_uri uri = UriManager.uri_of_string (UriManager.string_of_uri uri) in
160   function
161   | Default (loc, name, uris) ->
162       let uris = List.map reash_uri uris in
163       Default (loc, name, uris)
164   | Interpretation (loc, dsc, args, cic_appl_pattern) ->
165       let rec aux =
166         function
167         | CicNotationPt.UriPattern uri ->
168             CicNotationPt.UriPattern (reash_uri uri)
169         | CicNotationPt.ApplPattern args ->
170             CicNotationPt.ApplPattern (List.map aux args)
171         | CicNotationPt.VarPattern _
172         | CicNotationPt.ImplicitPattern as pat -> pat
173       in
174       let appl_pattern = aux cic_appl_pattern in
175       Interpretation (loc, dsc, args, appl_pattern)
176   | cmd -> cmd
177
178 type ('term, 'lazy_term, 'reduction, 'ident) tactical =
179   | Tactic of loc * ('term, 'lazy_term, 'reduction, 'ident) tactic
180   | Do of loc * int * ('term, 'lazy_term, 'reduction, 'ident) tactical
181   | Repeat of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical
182   | Seq of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical list
183       (* sequential composition *)
184   | Then of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical *
185       ('term, 'lazy_term, 'reduction, 'ident) tactical list
186   | First of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical list
187       (* try a sequence of loc * tactical until one succeeds, fail otherwise *)
188   | Try of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical
189       (* try a tactical and mask failures *)
190   | Solve of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical list
191
192   | Dot of loc
193   | Semicolon of loc
194   | Branch of loc
195   | Shift of loc
196   | Pos of loc * int
197   | Merge of loc
198   | Focus of loc * int list
199   | Unfocus of loc
200   | Skip of loc
201
202 let is_punctuation =
203   function
204   | Dot _ | Semicolon _ | Branch _ | Shift _ | Merge _ | Pos _ -> true
205   | _ -> false
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       * ('term, 'lazy_term, 'reduction, 'ident) tactical option(* punctuation *)
212              
213 type ('term, 'lazy_term, 'reduction, 'obj, 'ident) comment =
214   | Note of loc * string
215   | Code of loc * ('term, 'lazy_term, 'reduction, 'obj, 'ident) code
216              
217 type ('term, 'lazy_term, 'reduction, 'obj, 'ident) statement =
218   | Executable of loc * ('term, 'lazy_term, 'reduction, 'obj, 'ident) code
219   | Comment of loc * ('term, 'lazy_term, 'reduction, 'obj, 'ident) comment
220
221   (* statements meaningful for matitadep *)
222 type dependency =
223   | IncludeDep of string
224   | BaseuriDep of string
225   | UriDep of UriManager.uri
226