Skip to content

Commit 741bc92

Browse files
committed
Backport PR rocq-prover#20839: [classifier] visibility on attributes
2 parents 373dd92 + b7fce3a commit 741bc92

File tree

6 files changed

+23
-14
lines changed

6 files changed

+23
-14
lines changed

coqpp/coqpp_main.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ let print_rule_classifier fmt r = match r.vernac_class with
369369
| Some f ->
370370
let no_binder = function ExtTerminal _ -> true | ExtNonTerminal _ -> false in
371371
if List.for_all no_binder r.vernac_toks then
372-
fprintf fmt "Some @[%a@]" print_code f
372+
fprintf fmt "Some @[(fun ~atts -> %a)@]" print_code f
373373
else
374-
fprintf fmt "Some @[(fun %a-> %a)@]" print_binders r.vernac_toks print_code f
374+
fprintf fmt "Some @[(fun %a ~atts -> %a)@]" print_binders r.vernac_toks print_code f
375375

376376
(* let print_atts fmt = function *)
377377
(* | None -> fprintf fmt "@[let () = Attributes.unsupported_attributes atts in@] " *)
@@ -482,11 +482,11 @@ let print_classifier fmt = function
482482
when the block level classifier is specified *)
483483
| ClassifDefault -> fprintf fmt ""
484484
| ClassifName "QUERY" ->
485-
fprintf fmt "~classifier:(fun _ -> Vernacextend.classify_as_query)"
485+
fprintf fmt "~classifier:(fun ~atts:_ _ -> Vernacextend.classify_as_query)"
486486
| ClassifName "SIDEFF" ->
487-
fprintf fmt "~classifier:(fun _ -> Vernacextend.classify_as_sideeff)"
487+
fprintf fmt "~classifier:(fun ~atts:_ _ -> Vernacextend.classify_as_sideeff)"
488488
| ClassifName s -> fatal (Printf.sprintf "Unknown classifier %s" s)
489-
| ClassifCode c -> fprintf fmt "~classifier:(%s)" c.code
489+
| ClassifCode c -> fprintf fmt "~classifier:(fun ~atts -> %s)" c.code
490490

491491
let print_entry fmt = function
492492
| None -> fprintf fmt "None"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
overlay elpi https://github.com/gares/coq-elpi vernac-class-atts 20839
2+
3+
overlay metarocq https://github.com/gares/metarocq vernac-class-atts 20839

dev/top_printers.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ let () =
664664
let ty_constr = Extend.TUentry (get_arg_tag Stdarg.wit_constr) in
665665
let cmd_sig = TyTerminal("PrintConstr", TyNonTerminal(ty_constr, TyNil)) in
666666
let cmd_fn c ?loc:_ ~atts () = vtdefault (fun () -> in_current_context econstr_display c) in
667-
let cmd_class _ = VtQuery in
667+
let cmd_class _ ~atts:_ = VtQuery in
668668
let cmd : ty_ml = TyML (false, cmd_sig, cmd_fn, Some cmd_class) in
669669
static_vernac_extend ~plugin:None ~command:"PrintConstr" [cmd]
670670

@@ -674,7 +674,7 @@ let () =
674674
let ty_constr = Extend.TUentry (get_arg_tag Stdarg.wit_constr) in
675675
let cmd_sig = TyTerminal("PrintPureConstr", TyNonTerminal(ty_constr, TyNil)) in
676676
let cmd_fn c ?loc:_ ~atts () = vtdefault (fun () -> in_current_context print_pure_econstr c) in
677-
let cmd_class _ = VtQuery in
677+
let cmd_class _ ~atts:_ = VtQuery in
678678
let cmd : ty_ml = TyML (false, cmd_sig, cmd_fn, Some cmd_class) in
679679
static_vernac_extend ~plugin:None ~command:"PrintPureConstr" [cmd]
680680

vernac/vernac_classifier.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ let classify_vernac e =
8383
(* Plugins should classify their commands *)
8484
| VernacLoad _ -> VtSideff ([], VtNow)
8585
| VernacExtend (s,l) ->
86-
try Vernacextend.get_vernac_classifier s l
86+
try Vernacextend.get_vernac_classifier s ~atts l
8787
with Not_found -> anomaly(str"No classifier for"++spc()++str s.ext_entry ++str".")
8888
in
8989
let static_pure_classifier ~atts e = match e with

vernac/vernacextend.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ let type_vernac opn converted_args ?loc ~atts =
9292

9393
(** VERNAC EXTEND registering *)
9494

95-
type classifier = Genarg.raw_generic_argument list -> vernac_classification
95+
type classifier =
96+
Genarg.raw_generic_argument list ->
97+
atts:Attributes.vernac_flags ->
98+
vernac_classification
9699

97100
(** Classifiers *)
98101
module StringPair =
@@ -119,7 +122,7 @@ let classify_as_sideeff = VtSideff ([], VtLater)
119122
let classify_as_proofstep = VtProofStep { proof_block_detection = None}
120123

121124
type (_, _) ty_sig =
122-
| TyNil : (vernac_command, vernac_classification) ty_sig
125+
| TyNil : (vernac_command, atts:Attributes.vernac_flags -> vernac_classification) ty_sig
123126
| TyTerminal : string * ('r, 's) ty_sig -> ('r, 's) ty_sig
124127
| TyNonTerminal : ('a, 'b, 'c) Extend.ty_user_symbol * ('r, 's) ty_sig -> ('a -> 'r, 'a -> 's) ty_sig
125128

@@ -199,7 +202,7 @@ let static_vernac_extend ~plugin ~command ?classifier ?entry ext =
199202
| Some cl -> untype_classifier ty cl
200203
| None ->
201204
match classifier with
202-
| Some cl -> fun _ -> cl command
205+
| Some cl -> fun _ ~atts -> cl ~atts command
203206
| None ->
204207
let e = match entry with
205208
| None -> "COMMAND"

vernac/vernacextend.mli

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ val type_vernac : Vernacexpr.extend_name -> plugin_args -> vernac_command
7575

7676
(** {5 VERNAC EXTEND} *)
7777

78-
type classifier = Genarg.raw_generic_argument list -> vernac_classification
78+
type classifier =
79+
Genarg.raw_generic_argument list ->
80+
atts:Attributes.vernac_flags ->
81+
vernac_classification
7982

8083
type (_, _) ty_sig =
81-
| TyNil : (vernac_command, vernac_classification) ty_sig
84+
| TyNil : (vernac_command, atts:Attributes.vernac_flags -> vernac_classification) ty_sig
8285
| TyTerminal : string * ('r, 's) ty_sig -> ('r, 's) ty_sig
8386
| TyNonTerminal :
8487
('a, 'b, 'c) Extend.ty_user_symbol * ('r, 's) ty_sig ->
@@ -100,7 +103,7 @@ type ty_ml = TyML : bool (* deprecated *) * ('r, 's) ty_sig * 'r * 's option ->
100103
val static_vernac_extend :
101104
plugin:string option ->
102105
command:string ->
103-
?classifier:(string -> vernac_classification) ->
106+
?classifier:(atts:Attributes.vernac_flags -> string -> vernac_classification) ->
104107
?entry:Vernacexpr.vernac_expr Procq.Entry.t ->
105108
ty_ml list -> unit
106109

0 commit comments

Comments
 (0)