1 /* Copyright (C) 2000, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
28 module U = UriManager;;
30 exception InvalidSuffix of string;;
31 exception InductiveTypeURIExpected;;
32 exception UnknownIdentifier of string;;
34 let uri_of_id_map = Hashtbl.create 53;;
36 let get_index_in_list e =
40 | (Some he)::_ when he = e -> i
41 | _::tl -> aux (i+1) tl
46 let get_cookingno uri =
47 UriManager.relative_depth !CicTextualParser0.current_uri uri 0
50 (* Returns the first meta whose number is above the *)
51 (* number of the higher meta. *)
52 (*CSC: cut&pasted from proofEngine.ml *)
58 | None,(n,_,_)::tl -> aux (Some n,tl)
59 | Some m,(n,_,_)::tl -> if n > m then aux (Some n,tl) else aux (Some m,tl)
61 1 + aux (None,!CicTextualParser0.metasenv)
64 (* identity_relocation_list_for_metavariable i canonical_context *)
65 (* returns the identity relocation list, which is the list [1 ; ... ; n] *)
66 (* where n = List.length [canonical_context] *)
67 (*CSC: ma mi basta la lunghezza del contesto canonico!!!*)
68 (*CSC: cut&pasted from proofEngine.ml *)
69 let identity_relocation_list_for_metavariable canonical_context =
70 let canonical_context_length = List.length canonical_context in
74 | (n,None::tl) -> None::(aux ((n+1),tl))
75 | (n,_::tl) -> (Some (Cic.Rel n))::(aux ((n+1),tl))
77 aux (1,canonical_context)
84 %token <UriManager.uri> CONURI
85 %token <UriManager.uri * int> INDTYURI
86 %token <UriManager.uri * int * int> INDCONURI
88 %token LPAREN RPAREN PROD LAMBDA COLON DOT SET PROP TYPE CAST IMPLICIT NONE
89 %token LETIN FIX COFIX SEMICOLON LCURLY RCURLY CASE ARROW LBRACKET RBRACKET EOF
92 %type <Cic.term option> main
97 | EOF { raise CicTextualParser0.Eof }
101 { let uri = UriManager.string_of_uri $1 in
102 let suff = (String.sub uri (String.length uri - 3) 3) in
105 let cookingno = get_cookingno $1 in
108 | _ -> raise (InvalidSuffix suff)
111 { let cookingno = get_cookingno (fst $1) in
112 MutInd (fst $1, cookingno, snd $1) }
114 { let (uri,tyno,consno) = $1 in
115 let cookingno = get_cookingno uri in
116 MutConstruct (uri, cookingno, tyno, consno) }
119 Rel (get_index_in_list (Name $1) !CicTextualParser0.binders)
123 Hashtbl.find uri_of_id_map $1
126 match ! CicTextualParser0.locate_object $1 with
127 | None -> raise (UnknownIdentifier $1)
128 | Some term -> Hashtbl.add uri_of_id_map $1 term; term
130 | CASE LPAREN expr COLON INDTYURI SEMICOLON expr RPAREN LCURLY branches RCURLY
131 { let cookingno = get_cookingno (fst $5) in
132 MutCase (fst $5, cookingno, snd $5, $7, $3, $10) }
133 | CASE LPAREN expr COLON ID SEMICOLON expr RPAREN LCURLY branches RCURLY
135 let _ = get_index_in_list (Name $5) !CicTextualParser0.binders in
136 raise InductiveTypeURIExpected
139 match Hashtbl.find uri_of_id_map $5 with
140 MutInd (uri,cookingno,typeno) ->
141 MutCase (uri, cookingno, typeno, $7, $3, $10)
142 | _ -> raise InductiveTypeURIExpected
144 | fixheader LCURLY exprseplist RCURLY
145 { let fixfunsdecls = snd $1 in
146 let fixfunsbodies = $3 in
150 [] -> raise Not_found
151 | (name,_,_)::_ when name = (fst $1) -> idx
152 | _::tl -> find (idx+1) tl
157 List.map2 (fun (name,recindex,ty) bo -> (name,recindex,ty,bo))
158 fixfunsdecls fixfunsbodies
160 for i = 1 to List.length fixfuns do
161 CicTextualParser0.binders := List.tl !CicTextualParser0.binders
165 | cofixheader LCURLY exprseplist RCURLY
166 { let cofixfunsdecls = (snd $1) in
167 let cofixfunsbodies = $3 in
171 [] -> raise Not_found
172 | (name,_)::_ when name = (fst $1) -> idx
173 | _::tl -> find (idx+1) tl
175 find 0 cofixfunsdecls
178 List.map2 (fun (name,ty) bo -> (name,ty,bo))
179 cofixfunsdecls cofixfunsbodies
181 for i = 1 to List.length cofixfuns do
182 CicTextualParser0.binders := List.tl !CicTextualParser0.binders
184 CoFix (idx,cofixfuns)
187 { let newmeta = new_meta () in
188 let new_canonical_context = [] in
190 identity_relocation_list_for_metavariable new_canonical_context
192 CicTextualParser0.metasenv :=
193 [newmeta, new_canonical_context, Sort Type ;
194 newmeta+1, new_canonical_context, Meta (newmeta,irl);
195 newmeta+2, new_canonical_context, Meta (newmeta+1,irl)
196 ] @ !CicTextualParser0.metasenv ;
202 | LPAREN expr CAST expr RPAREN { Cast ($2,$4) }
203 | META LBRACKET substitutionlist RBRACKET { Meta ($1, $3) }
204 | LPAREN expr expr exprlist RPAREN { Appl ([$2;$3]@$4) }
208 { CicTextualParser0.binders := List.tl !CicTextualParser0.binders ;
209 Prod (fst $1, snd $1,$2) }
211 { CicTextualParser0.binders := List.tl !CicTextualParser0.binders ;
212 Lambda (fst $1, snd $1,$2) }
214 { CicTextualParser0.binders := List.tl !CicTextualParser0.binders ;
215 LetIn (fst $1, snd $1,$2) }
220 FIX ID LCURLY fixfunsdecl RCURLY
221 { let bs = List.rev_map (function (name,_,_) -> Some (Name name)) $4 in
222 CicTextualParser0.binders := bs@(!CicTextualParser0.binders) ;
227 ID LPAREN NUM RPAREN COLON expr
229 | ID LPAREN NUM RPAREN COLON expr SEMICOLON fixfunsdecl
233 COFIX ID LCURLY cofixfunsdecl RCURLY
234 { let bs = List.rev_map (function (name,_) -> Some (Name name)) $4 in
235 CicTextualParser0.binders := bs@(!CicTextualParser0.binders) ;
242 | ID COLON expr SEMICOLON cofixfunsdecl
246 PROD ID COLON expr DOT
247 { CicTextualParser0.binders := (Some (Name $2))::!CicTextualParser0.binders;
250 { CicTextualParser0.binders := (Some Anonimous)::!CicTextualParser0.binders ;
252 | LPAREN expr RPAREN ARROW
253 { CicTextualParser0.binders := (Some Anonimous)::!CicTextualParser0.binders ;
257 LAMBDA ID COLON expr DOT
258 { CicTextualParser0.binders := (Some (Name $2))::!CicTextualParser0.binders ;
262 LAMBDA ID LETIN expr DOT
263 { CicTextualParser0.binders := (Some (Name $2))::!CicTextualParser0.binders ;
268 | expr SEMICOLON branches { $1::$3 }
273 | expr exprlist { $1::$2 }
277 | expr SEMICOLON exprseplist { $1::$3 }
281 | expr SEMICOLON substitutionlist { (Some $1)::$3 }
282 | NONE SEMICOLON substitutionlist { None::$3 }
286 { let cookingno = get_cookingno $3 in
287 Hashtbl.add uri_of_id_map $2 (Cic.Const ($3,cookingno)) }
289 { let cookingno = get_cookingno (fst $3) in
290 Hashtbl.add uri_of_id_map $2 (Cic.MutInd (fst $3, cookingno, snd $3)) }
292 { let uri,indno,consno = $3 in
293 let cookingno = get_cookingno uri in
294 Hashtbl.add uri_of_id_map $2
295 (Cic.MutConstruct (uri, cookingno, indno ,consno))