-
(** {2 Auxiliary functions} *)
let uri = UriManager.uri_of_string
let var ?(subst = []) uri = Cic.Var (uri, subst)
let mutconstruct ?(subst = []) uri typeno consno =
Cic.MutConstruct (uri, typeno, consno, subst)
+let mutind ?(subst = []) uri typeno = Cic.MutInd (uri, typeno, subst)
+
+let indtyuri_of_uri uri =
+ let index_sharp = String.index uri '#' in
+ let index_num = index_sharp + 3 in
+ (UriManager.uri_of_string (String.sub uri 0 index_sharp),
+ int_of_string(String.sub uri index_num (String.length uri - index_num)) - 1)
+
+let indconuri_of_uri uri =
+ let index_sharp = String.index uri '#' in
+ let index_div = String.rindex uri '/' in
+ let index_con = index_div + 1 in
+ (UriManager.uri_of_string (String.sub uri 0 index_sharp),
+ int_of_string
+ (String.sub uri (index_sharp + 3) (index_div - index_sharp - 3)) - 1,
+ int_of_string
+ (String.sub uri index_con (String.length uri - index_con)))
+
+let term_of_uri uri =
+ let s = UriManager.string_of_uri uri in
+ try
+ (* Constant *)
+ (* TODO explicit substitutions? *)
+ let len = String.length s in
+ let sub = String.sub s (len -4) 4 in
+ if sub = ".con" then
+ const uri
+ else if sub = ".var" then
+ var uri
+ else
+ (try
+ (* Inductive Type *)
+ let (uri, typeno) = indtyuri_of_uri s in
+ mutind uri typeno
+ with
+ | UriManager.IllFormedUri _ | Failure _ | Invalid_argument _ ->
+ (* Constructor of an Inductive Type *)
+ let (uri, typeno, consno) = indconuri_of_uri s in
+ mutconstruct uri typeno consno)
+ with
+ | Invalid_argument _ -> raise (UriManager.IllFormedUri s)
(** {2 Helm's objects shorthands} *)