exception InvalidSuffix of string;;
exception InductiveTypeURIExpected;;
exception UnknownIdentifier of string;;
+ exception ExplicitNamedSubstitutionAppliedToRel;;
+ exception TheLeftHandSideOfAnExplicitNamedSubstitutionMustBeAVariable;;
let uri_of_id_map = Hashtbl.create 53;;
| _::tl -> aux (i+1) tl
in
aux 1
-;;
+ ;;
(* Returns the first meta whose number is above the *)
(* number of the higher meta. *)
aux (1,canonical_context)
;;
+ let term_of_con_uri uri exp_named_subst =
+ Const (uri,exp_named_subst)
+ ;;
+
+ let term_of_var_uri uri exp_named_subst =
+ Var (uri,exp_named_subst)
+ ;;
+
+ let term_of_indty_uri (uri,tyno) exp_named_subst =
+ MutInd (uri, tyno, exp_named_subst)
+ ;;
+
+ let term_of_indcon_uri (uri,tyno,consno) exp_named_subst =
+ MutConstruct (uri, tyno, consno, exp_named_subst)
+ ;;
+
+ let term_of_uri uri =
+ match uri with
+ CicTextualParser0.ConUri uri -> term_of_con_uri uri
+ | CicTextualParser0.VarUri uri -> term_of_var_uri uri
+ | CicTextualParser0.IndTyUri (uri,tyno) -> term_of_indty_uri (uri,tyno)
+ | CicTextualParser0.IndConUri (uri,tyno,consno) ->
+ term_of_indcon_uri (uri,tyno,consno)
+ ;;
+
+ let var_uri_of_id id =
+ try
+ (match Hashtbl.find uri_of_id_map id with
+ CicTextualParser0.VarUri uri -> uri
+ | _ -> raise TheLeftHandSideOfAnExplicitNamedSubstitutionMustBeAVariable
+ )
+ with
+ Not_found ->
+ match !CicTextualParser0.locate_object id with
+ None -> raise (UnknownIdentifier id)
+ | Some (CicTextualParser0.VarUri uri as varuri) ->
+ Hashtbl.add uri_of_id_map id varuri;
+ uri
+ | Some _ ->
+ raise TheLeftHandSideOfAnExplicitNamedSubstitutionMustBeAVariable
+ ;;
+
%}
%token <string> ID
%token <int> META
%token <int> NUM
%token <UriManager.uri> CONURI
+%token <UriManager.uri> VARURI
%token <UriManager.uri * int> INDTYURI
%token <UriManager.uri * int * int> INDCONURI
%token ALIAS
| EOF { raise CicTextualParser0.Eof }
;
expr2:
- CONURI
- { let uri = UriManager.string_of_uri $1 in
- let suff = (String.sub uri (String.length uri - 3) 3) in
- match suff with
-(*CSC: parsare anche le explicit named substitutions *)
- "con" -> Const ($1,[])
- | "var" -> Var ($1,[])
- | _ -> raise (InvalidSuffix suff)
- }
- | INDTYURI
-/*CSC: parsare anche le explicit named substitutions */
- { MutInd (fst $1, snd $1, []) }
- | INDCONURI
- { let (uri,tyno,consno) = $1 in
-(*CSC: parsare anche le explicit named substitutions *)
- MutConstruct (uri, tyno, consno, []) }
- | ID
+ CONURI exp_named_subst
+ { term_of_con_uri $1 $2 }
+ | VARURI exp_named_subst
+ { term_of_var_uri $1 $2 }
+ | INDTYURI exp_named_subst
+ { term_of_indty_uri $1 $2 }
+ | INDCONURI exp_named_subst
+ { term_of_indcon_uri $1 $2 }
+ | ID exp_named_subst
{ try
+ let res =
Rel (get_index_in_list (Name $1) !CicTextualParser0.binders)
+ in
+ if $2 = [] then res else raise (ExplicitNamedSubstitutionAppliedToRel)
with
Not_found ->
try
- Hashtbl.find uri_of_id_map $1
+ term_of_uri (Hashtbl.find uri_of_id_map $1) $2
with
Not_found ->
- match ! CicTextualParser0.locate_object $1 with
+ match !CicTextualParser0.locate_object $1 with
| None -> raise (UnknownIdentifier $1)
- | Some term -> Hashtbl.add uri_of_id_map $1 term; term
+ | Some uri ->
+ Hashtbl.add uri_of_id_map $1 uri;
+ term_of_uri uri $2
}
| CASE LPAREN expr COLON INDTYURI SEMICOLON expr RPAREN LCURLY branches RCURLY
{ MutCase (fst $5, snd $5, $7, $3, $10) }
with
Not_found ->
match Hashtbl.find uri_of_id_map $5 with
- MutInd (uri,typeno,_) ->
+ CicTextualParser0.IndTyUri (uri,typeno) ->
MutCase (uri, typeno, $7, $3, $10)
| _ -> raise InductiveTypeURIExpected
}
| META LBRACKET substitutionlist RBRACKET { Meta ($1, $3) }
| LPAREN expr expr exprlist RPAREN { Appl ([$2;$3]@$4) }
;
+exp_named_subst :
+ { [] }
+ | LCURLY named_substs RCURLY
+ { $2 }
+;
+named_substs :
+ VARURI LETIN expr2
+ { [$1,$3] }
+ | ID LETIN expr2
+ { [var_uri_of_id $1,$3] }
+ | VARURI LETIN expr2 SEMICOLON named_substs
+ { ($1,$3)::$5 }
+ | ID LETIN expr2 SEMICOLON named_substs
+ { (var_uri_of_id $1,$3)::$5 }
+;
expr :
pihead expr
{ CicTextualParser0.binders := List.tl !CicTextualParser0.binders ;
;
alias:
ALIAS ID CONURI
- { Hashtbl.add uri_of_id_map $2 (Cic.Const ($3,[])) }
+ { Hashtbl.add uri_of_id_map $2 (CicTextualParser0.ConUri $3) }
+ | ALIAS ID VARURI
+ { Hashtbl.add uri_of_id_map $2 (CicTextualParser0.VarUri $3) }
| ALIAS ID INDTYURI
- { Hashtbl.add uri_of_id_map $2 (Cic.MutInd (fst $3, snd $3, [])) }
+ { Hashtbl.add uri_of_id_map $2
+ (CicTextualParser0.IndTyUri (fst $3, snd $3))
+ }
| ALIAS ID INDCONURI
{ let uri,indno,consno = $3 in
Hashtbl.add uri_of_id_map $2
- (Cic.MutConstruct (uri, indno, consno, []))
+ (CicTextualParser0.IndConUri (uri, indno, consno))
}
-
-
-