module Ast = NotationPt
-let visit_ast ?(special_k = fun _ -> assert false)
+let visit_ast ?(special_k = fun _ -> assert false)
+ ?(clear_interpretation= false)
?(map_xref_option= fun x -> x) ?(map_case_indty= fun x -> x)
?(map_case_outtype=
fun k x -> match x with None -> None | Some x -> Some (k x))
definitions
in
Ast.LetRec (kind, definitions, k term)
- | Ast.Ident (name, Some substs) ->
- Ast.Ident (name, Some (aux_substs substs))
- | Ast.Uri (name, Some substs) -> Ast.Uri (name, Some (aux_substs substs))
| Ast.Meta (index, substs) -> Ast.Meta (index, List.map aux_opt substs)
| (Ast.AttributedTerm _
| Ast.Layout _
| Ast.Literal _
| Ast.Magic _
| Ast.Variable _) as t -> special_k t
- | (Ast.Ident _
+ | Ast.Ident (id,_) when clear_interpretation -> Ast.Ident (id,`Ambiguous)
+ | Ast.Symbol (s,_) when clear_interpretation -> Ast.Symbol (s,None)
+ | Ast.Num (n,_) when clear_interpretation -> Ast.Num (n,None)
+ | ( Ast.Ident _
+ | Ast.Symbol _
+ | Ast.Num _
| Ast.NRef _
| Ast.NCic _
| Ast.Implicit _
- | Ast.Num _
| Ast.Sort _
- | Ast.Symbol _
- | Ast.Uri _
| Ast.UserInput) as t -> t
and aux_opt = function
| None -> None
Ast.Pattern (head, hrefs, vars), term ->
Ast.Pattern (head, k_xref hrefs, List.map aux_capture_variable vars), k term
| Ast.Wildcard, term -> Ast.Wildcard, k term
- and aux_subst (name, term) = (name, k term)
- and aux_substs substs = List.map aux_subst substs
in
aux
let rec aux = function
| Ast.AttributedTerm (_, t) -> aux t
| Ast.Layout l -> Ast.Layout (visit_layout aux l)
- | Ast.Literal (`Keyword k) as t ->
+ | Ast.Literal (_,`Keyword (k,_)) as t ->
add_keyword k;
t
| Ast.Literal _ as t -> t
let rec get_idrefs =
function
- | Ast.AttributedTerm (`IdRef id, t) -> id :: get_idrefs t
- | Ast.AttributedTerm (_, t) -> get_idrefs t
+ | Ast.Symbol (csym,Some (uri,desc)) -> [csym,uri,desc]
| _ -> []
let meta_names_of_term term =
| Ast.LetRec (_, definitions, body) ->
List.iter aux_definition definitions ;
aux body
- | Ast.Uri (_, Some substs) -> aux_substs substs
- | Ast.Ident (_, Some substs) -> aux_substs substs
| Ast.Meta (_, substs) -> aux_meta_substs substs
| Ast.Implicit _
| Ast.Num _
| Ast.Sort _
| Ast.Symbol _
- | Ast.Uri _
| Ast.UserInput -> ()
| Ast.Magic magic -> aux_magic magic
List.iter aux_capture_var params ;
aux_capture_var var ;
aux term
- and aux_substs substs = List.iter (fun (_, term) -> aux term) substs
and aux_meta_substs meta_substs = List.iter aux_opt meta_substs
and aux_variable = function
| Ast.NumVar name -> add_name name
done;
List.rev !lists
+let href s = function
+ | None, None -> s
+ | Some u, None -> "<A href=\"" ^ u ^ "\">" ^ s ^ "</A>"
+ | None, Some desc ->
+ "<A href=\"cic:/fakeuri.con\" title=\"" ^ desc ^ "\">" ^ s ^ "</A>"
+ | Some u, Some desc ->
+ "<A href=\"" ^ u ^ "\" title=\"" ^ desc ^ "\">" ^ s ^ "</A>"
+
let string_of_literal = function
- | `Symbol s
- | `Keyword s
- | `Number s -> s
+ | `Symbol (s,x)
+ | `Keyword (s,x)
+ | `Number (s,x) -> href s x
+
+let html_of_literal = function
+ | `Symbol (s,x)
+ | `Keyword (s,x)
+ | `Number (s,x) ->
+ href (Netencoding.Html.encode ~in_enc:`Enc_utf8 ()
+ (Utf8Macro.unicode_of_tex s)) x
let boxify = function
| [ a ] -> a
(* FG: "η" is not an identifier (it is rendered, but not be parsed) *)
let fresh_name () = "eta" ^ string_of_int (fresh_id ())
+(* XXX FIXME: was used to add instance indices to symbols/numbers
+ * do we even need a similar operation?
+ * currently an identity function! *)
let rec freshen_term ?(index = ref 0) term =
let freshen_term = freshen_term ~index in
let fresh_instance () = incr index; !index in
| _ -> assert false
in
match term with
- | Ast.Symbol (s, instance) -> Ast.Symbol (s, fresh_instance ())
- | Ast.Num (s, instance) -> Ast.Num (s, fresh_instance ())
+ | Ast.Symbol (s, x) -> Ast.Symbol (s, x (* fresh_instance () *))
+ | Ast.Num (s, x) -> Ast.Num (s, x (* fresh_instance () *))
| t -> visit_ast ~special_k freshen_term t
let freshen_obj obj =