| 1 | (************************************************************************) |
| 2 | (* * The Rocq Prover / The Rocq Development Team *) |
| 3 | (* v * Copyright INRIA, CNRS and contributors *) |
| 4 | (* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 5 | (* \VV/ **************************************************************) |
| 6 | (* // * This file is distributed under the terms of the *) |
| 7 | (* * GNU Lesser General Public License Version 2.1 *) |
| 8 | (* * (see LICENSE file for the text of the license) *) |
| 9 | (************************************************************************) |
| 10 | |
| 11 | (** Vernacular Extension data *) |
| 12 | |
| 13 | (* A vernac classifier provides information about the exectuion of a |
| 14 | command: |
| 15 | |
| 16 | - vernac_when: encodes if the vernac may alter the parser [thus |
| 17 | forcing immediate execution], or if indeed it is pure and parsing |
| 18 | can continue without its execution. |
| 19 | |
| 20 | - vernac_type: if it is starts, ends, continues a proof or |
| 21 | alters the global state or is a control command like BackTo or is |
| 22 | a query like Check. |
| 23 | |
| 24 | The classification works on the assumption that we have 3 states: |
| 25 | parsing, execution (global environment, etc...), and proof |
| 26 | state. For example, commands that only alter the proof state are |
| 27 | considered safe to delegate to a worker. |
| 28 | |
| 29 | *) |
| 30 | |
| 31 | type vernac_keep_as = VtKeepAxiom | VtKeepDefined | VtKeepOpaque |
| 32 | |
| 33 | type vernac_qed_type = VtKeep of vernac_keep_as | VtDrop |
| 34 | |
| 35 | type vernac_when = |
| 36 | | VtNow |
| 37 | | VtLater |
| 38 | |
| 39 | type vernac_classification = |
| 40 | (* Start of a proof *) |
| 41 | | VtStartProof of vernac_start |
| 42 | (* Command altering the global state, bad for parallel |
| 43 | processing. *) |
| 44 | | VtSideff of vernac_sideff_type |
| 45 | (* End of a proof *) |
| 46 | | VtQed of vernac_qed_type |
| 47 | (* A proof step *) |
| 48 | | VtProofStep of { |
| 49 | proof_block_detection : proof_block_name option |
| 50 | } |
| 51 | (* Queries are commands assumed to be "pure", that is to say, they |
| 52 | don't modify the interpretation state. *) |
| 53 | | VtQuery |
| 54 | (* Commands that change the current proof mode *) |
| 55 | | VtProofMode of Pvernac.proof_mode |
| 56 | (* To be removed *) |
| 57 | | VtMeta |
| 58 | and vernac_start = opacity_guarantee * Names.Id.t list |
| 59 | and vernac_sideff_type = Names.Id.t list * vernac_when |
| 60 | and opacity_guarantee = |
| 61 | | GuaranteesOpacity (** Only generates opaque terms at [Qed] *) |
| 62 | | Doesn'tGuaranteeOpacity (** May generate transparent terms even with [Qed].*) |
| 63 | |
| 64 | and solving_tac = bool (** a terminator *) |
| 65 | |
| 66 | and anon_abstracting_tac = bool (** abstracting anonymously its result *) |
| 67 | |
| 68 | and proof_block_name = string (** open type of delimiters *) |
| 69 | |
| 70 | type vernac_command = ?loc:Loc.t -> atts:Attributes.vernac_flags -> unit -> Vernactypes.typed_vernac |
| 71 | |
| 72 | type plugin_args = Genarg.raw_generic_argument list |
| 73 | |
| 74 | val type_vernac : Vernacexpr.extend_name -> plugin_args -> vernac_command |
| 75 | |
| 76 | (** {5 VERNAC EXTEND} *) |
| 77 | |
| 78 | type classifier = |
| 79 | Genarg.raw_generic_argument list -> |
| 80 | atts:Attributes.vernac_flags -> |
| 81 | vernac_classification |
| 82 | |
| 83 | type (_, _) ty_sig = |
| 84 | | TyNil : (vernac_command, atts:Attributes.vernac_flags -> vernac_classification) ty_sig |
| 85 | | TyTerminal : string * ('r, 's) ty_sig -> ('r, 's) ty_sig |
| 86 | | TyNonTerminal : |
| 87 | ('a, 'b, 'c) Extend.ty_user_symbol * ('r, 's) ty_sig -> |
| 88 | ('a -> 'r, 'a -> 's) ty_sig |
| 89 | |
| 90 | type ty_ml = TyML : bool (* deprecated *) * ('r, 's) ty_sig * 'r * 's option -> ty_ml |
| 91 | |
| 92 | (** Statically extend vernacular commands. |
| 93 | |
| 94 | This is used by coqpp VERNAC EXTEND. |
| 95 | It should not be used directly, use [declare_dynamic_vernac_extend] instead. |
| 96 | |
| 97 | Commands added by plugins at Declare ML Module / Require time should provide [plugin]. |
| 98 | |
| 99 | Commands added without providing [plugin] cannot be removed from |
| 100 | the grammar or modified. Not passing [plugin] is possible for |
| 101 | non-plugin rocq-runtime commands and deprecated for all other callers. |
| 102 | *) |
| 103 | val static_vernac_extend : |
| 104 | plugin:string option -> |
| 105 | command:string -> |
| 106 | ?classifier:(atts:Attributes.vernac_flags -> string -> vernac_classification) -> |
| 107 | ?entry:Vernacexpr.vernac_expr Procq.Entry.t -> |
| 108 | ignore_kw:bool -> |
| 109 | ty_ml list -> unit |
| 110 | |
| 111 | (** Used to tell the system that all future vernac extends are from plugins. *) |
| 112 | val static_linking_done : unit -> unit |
| 113 | |
| 114 | (** Dynamically extend vernacular commands (for instance when importing some module). |
| 115 | |
| 116 | Reusing a [command] string will replace previous uses. The result |
| 117 | is undefined and probably produces anomalies if the previous |
| 118 | grammar rule is still active and was different from the new one. |
| 119 | |
| 120 | The polymorphic arguments are as in [TyML]. |
| 121 | |
| 122 | The declared grammar extension is disabled, one needs to call |
| 123 | [Egramml.extend_vernac_command_grammar] in order to enable it. |
| 124 | That call should use [undoable:true] to make it possible to |
| 125 | disable the extension, e.g. by backtracking over the command which |
| 126 | enabled it. |
| 127 | *) |
| 128 | val declare_dynamic_vernac_extend |
| 129 | : command:Vernacexpr.extend_name |
| 130 | -> ?entry:Vernacexpr.vernac_expr Procq.Entry.t |
| 131 | -> depr:bool |
| 132 | -> 's (* classifier *) |
| 133 | -> ('r, 's) ty_sig (* grammar *) |
| 134 | -> 'r (* command interpretation *) |
| 135 | -> Vernacexpr.extend_name |
| 136 | |
| 137 | (** {5 VERNAC ARGUMENT EXTEND} *) |
| 138 | |
| 139 | type 'a argument_rule = |
| 140 | | Arg_alias of 'a Procq.Entry.t |
| 141 | (** This is used because CAMLP5 parser can be dumb about rule factorization, |
| 142 | which sometimes requires two entries to be the same. *) |
| 143 | | Arg_rules of 'a Procq.Production.t list |
| 144 | (** There is a discrepancy here as we use directly extension rules and thus |
| 145 | entries instead of ty_user_symbol and thus arguments as roots. *) |
| 146 | |
| 147 | type 'a vernac_argument = { |
| 148 | arg_printer : Environ.env -> Evd.evar_map -> 'a -> Pp.t; |
| 149 | arg_parsing : 'a argument_rule; |
| 150 | } |
| 151 | |
| 152 | val vernac_argument_extend : plugin:string option -> name:string -> ignore_kw:bool -> |
| 153 | 'a vernac_argument -> |
| 154 | 'a Genarg.vernac_genarg_type * 'a Procq.Entry.t |
| 155 | |
| 156 | (** {5 STM classifiers} *) |
| 157 | val get_vernac_classifier : Vernacexpr.extend_name -> classifier |
| 158 | |
| 159 | (** Standard constant classifiers *) |
| 160 | val classify_as_query : vernac_classification |
| 161 | val classify_as_sideeff : vernac_classification |
| 162 | val classify_as_proofstep : vernac_classification |