1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(* $Id: syntax_def.ml 11512 2008-10-27 12:28:36Z herbelin $ *)
20
(* Syntactic definitions. *)
22
let syntax_table = ref (KNmap.empty : interpretation KNmap.t)
24
let _ = Summary.declare_summary
26
{ Summary.freeze_function = (fun () -> !syntax_table);
27
Summary.unfreeze_function = (fun ft -> syntax_table := ft);
28
Summary.init_function = (fun () -> syntax_table := KNmap.empty);
29
Summary.survive_module = false;
30
Summary.survive_section = false }
32
let add_syntax_constant kn c =
33
syntax_table := KNmap.add kn c !syntax_table
35
let load_syntax_constant i ((sp,kn),(local,pat,onlyparse)) =
36
if Nametab.exists_cci sp then
37
errorlabstrm "cache_syntax_constant"
38
(pr_id (basename sp) ++ str " already exists");
39
add_syntax_constant kn pat;
40
Nametab.push_syntactic_definition (Nametab.Until i) sp kn;
42
(* Declare it to be used as long name *)
43
Notation.declare_uninterpretation (Notation.SynDefRule kn) pat
45
let open_syntax_constant i ((sp,kn),(_,pat,onlyparse)) =
46
Nametab.push_syntactic_definition (Nametab.Exactly i) sp kn;
48
(* Redeclare it to be used as (short) name in case an other (distfix)
49
notation was declared inbetween *)
50
Notation.declare_uninterpretation (Notation.SynDefRule kn) pat
52
let cache_syntax_constant d =
53
load_syntax_constant 1 d
55
let subst_syntax_constant ((sp,kn),subst,(local,pat,onlyparse)) =
56
(local,subst_interpretation subst pat,onlyparse)
58
let classify_syntax_constant (_,(local,_,_ as o)) =
59
if local then Dispose else Substitute o
61
let export_syntax_constant (local,_,_ as o) =
62
if local then None else Some o
64
let (in_syntax_constant, out_syntax_constant) =
65
declare_object {(default_object "SYNTAXCONSTANT") with
66
cache_function = cache_syntax_constant;
67
load_function = load_syntax_constant;
68
open_function = open_syntax_constant;
69
subst_function = subst_syntax_constant;
70
classify_function = classify_syntax_constant;
71
export_function = export_syntax_constant }
73
type syndef_interpretation = (identifier * subscopes) list * aconstr
75
(* Coercions to the general format of notation that also supports
76
variables bound to list of expressions *)
77
let in_pat (ids,ac) = ((ids,[]),ac)
78
let out_pat ((ids,idsl),ac) = assert (idsl=[]); (ids,ac)
80
let declare_syntactic_definition local id onlyparse pat =
81
let _ = add_leaf id (in_syntax_constant (local,in_pat pat,onlyparse)) in ()
83
let search_syntactic_definition loc kn =
84
out_pat (KNmap.find kn !syntax_table)
86
let locate_global_with_alias (loc,qid) =
87
match Nametab.extended_locate qid with
88
| TrueGlobal ref -> ref
90
match search_syntactic_definition dummy_loc kn with
93
user_err_loc (loc,"",pr_qualid qid ++
94
str " is bound to a notation that does not denote a reference")
96
let inductive_of_reference_with_alias r =
97
match locate_global_with_alias (qualid_of_reference r) with
100
user_err_loc (loc_of_reference r,"global_inductive",
101
pr_reference r ++ spc () ++ str "is not an inductive type")
103
let global_with_alias r =
104
let (loc,qid as lqid) = qualid_of_reference r in
105
try locate_global_with_alias lqid
106
with Not_found -> Nametab.error_global_not_found_loc loc qid