1
1
(************************************************************************)
2
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2010 *)
3
(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2011 *)
4
4
(* \VV/ **************************************************************)
5
5
(* // * This file is distributed under the terms of the *)
6
6
(* * GNU Lesser General Public License Version 2.1 *)
7
7
(************************************************************************)
9
(* $Id: egrammar.ml 13329 2010-07-26 11:05:39Z herbelin $ *)
9
(* $Id: egrammar.ml 14779 2011-12-07 21:54:18Z herbelin $ *)
169
169
failwith "") symbs
171
171
let extend_constr (entry,level) (n,assoc) mkact forpat rules =
172
List.fold_left (fun nb pt ->
173
173
let symbs = make_constr_prod_item assoc n forpat pt in
174
174
let pure_sublevels = pure_sublevels level symbs in
175
175
let needed_levels = register_empty_levels forpat pure_sublevels in
176
176
let pos,p4assoc,name,reinit = find_position forpat assoc level in
177
let nb_decls = List.length needed_levels + 1 in
177
178
List.iter (prepare_empty_levels forpat) needed_levels;
178
grammar_extend entry pos reinit [(name, p4assoc, [symbs, mkact pt])]) rules
179
grammar_extend entry pos reinit [(name, p4assoc, [symbs, mkact pt])];
180
182
let extend_constr_notation (n,assoc,ntn,rules) =
181
183
(* Add the notation in constr *)
182
184
let mkact loc env = CNotation (loc,ntn,env) in
183
185
let e = interp_constr_entry_key false (ETConstr (n,())) in
184
extend_constr e (ETConstr(n,()),assoc) (make_constr_action mkact) false rules;
186
let nb = extend_constr e (ETConstr(n,()),assoc) (make_constr_action mkact) false rules in
185
187
(* Add the notation in cases_pattern *)
186
188
let mkact loc env = CPatNotation (loc,ntn,env) in
187
189
let e = interp_constr_entry_key true (ETConstr (n,())) in
188
extend_constr e (ETConstr (n,()),assoc) (make_cases_pattern_action mkact)
191
extend_constr e (ETConstr (n,()),assoc) (make_cases_pattern_action mkact) true rules in
191
194
(**********************************************************************)
192
195
(** Making generic actions in type generic_argument *)
273
276
(TacAtom(loc,TacAlias(loc,s,l,tac)):raw_tactic_expr) in
274
277
make_rule univ (mkact key tac) make_prod_item prods in
275
278
synchronize_level_positions ();
276
grammar_extend entry pos None [(None, None, List.rev [rules])]
279
grammar_extend entry pos None [(None, None, List.rev [rules])];
278
282
(**********************************************************************)
279
283
(** State of the grammar extensions *)
290
294
(string * int * grammar_prod_item list *
291
295
(dir_path * Tacexpr.glob_tactic_expr))
293
let (grammar_state : all_grammar_command list ref) = ref []
297
let (grammar_state : (int * all_grammar_command) list ref) = ref []
295
299
let extend_grammar gram =
300
let nb = match gram with
297
301
| Notation (_,_,a) -> extend_constr_notation a
298
| TacticGrammar g -> add_tactic_entry g);
299
grammar_state := gram :: !grammar_state
302
| TacticGrammar g -> add_tactic_entry g in
303
grammar_state := (nb,gram) :: !grammar_state
301
305
let recover_notation_grammar ntn prec =
302
306
let l = map_succeed (function
303
| Notation (prec',vars,(_,_,ntn',_ as x)) when prec = prec' & ntn = ntn' ->
307
| _, Notation (prec',vars,(_,_,ntn',_ as x)) when prec = prec' & ntn = ntn' ->
306
310
failwith "") !grammar_state in
320
324
if l1 == l2 then ([], [], l1) else list_share_tails l1 l2
322
326
let number_of_entries gcl =
325
| Notation _ -> n + 2 (* 1 for operconstr, 1 for pattern *)
326
| TacticGrammar _ -> n + 1)
327
List.fold_left (fun n (p,_) -> n + p) 0 gcl
329
329
let unfreeze (grams, lex) =
330
330
let (undo, redo, common) = factorize_grams !grammar_state grams in