package coq-core
Install
Dune Dependency
Authors
Maintainers
Sources
md5=66e57ea55275903bef74d5bf36fbe0f1
sha512=1a7eac6e2f58724a3f9d68bbb321e4cfe963ba1a5551b9b011db4b3f559c79be433d810ff262593d753770ee41ea68fbd6a60daa1e2319ea00dff64c8851d70b
doc/coq-core.parsing/Pcoq/index.html
Module Pcoq
Source
The parser of Coq
include Gramlib.Grammar.S
with type keyword_state := CLexer.keyword_state
and type te := Tok.t
and type 'a pattern := 'a Tok.p
and type 'a with_gstate := 'a
and type 'a with_kwstate := 'a
and type 'a with_estate := 'a
and type 'a mod_estate := 'a
Type combinators to factor the module type between explicit state passing in Grammar and global state in Pcoq
type 'a single_extend_statement =
string option * Gramlib.Gramext.g_assoc option * 'a Production.t list
type 'a extend_statement =
| Reuse of string option * 'a Production.t list
(*Extend an existing level by its optional given name. If None, picks the topmost level.
*)| Fresh of Gramlib.Gramext.position * 'a single_extend_statement list
(*Create a level at the given position.
*)
val generalize_symbol :
('a, 'tr, 'c) Symbol.t ->
('b, Gramlib.Grammar.norec, 'c) Symbol.t option
The parser of Coq is built from three kinds of rule declarations:
- dynamic rules declared at the evaluation of Coq files (using e.g. Notation, Infix, or Tactic Notation)
- static rules explicitly defined in files g_*.mlg
- static rules macro-generated by ARGUMENT EXTEND, TACTIC EXTEND and VERNAC EXTEND (see e.g. file extratactics.mlg)
Note that parsing a Coq document is in essence stateful: the parser needs to recognize commands that start proofs and use a different parsing entry point for them.
We thus provide two different interfaces: the "raw" parsing interface, in the style of camlp5, which provides more flexibility, and a more specialize "parse_vernac" one, which will indeed adjust the state as needed.
Dynamic extension of rules
For constr notations, dynamic addition of new rules is done in several steps:
- "x + y" (user gives a notation string of type Topconstr.notation) | (together with a constr entry level, e.g. 50, and indications of) | (subentries, e.g. x in constr next level and y constr same level) | | splitting into tokens by Metasyntax.split_notation_string V
String "x"; String "+"; String "y"
: symbol_token list | | interpreted as a mixed parsing/printing production | by Metasyntax.analyse_notation_tokens VNonTerminal "x"; Terminal "+"; NonTerminal "y"
: symbol list | | translated to a parsing production by Metasyntax.make_production VGramConstrNonTerminal (ETConstr (NextLevel,(BorderProd Left,LeftA)), Some "x"); GramConstrTerminal ("","+"); GramConstrNonTerminal (ETConstr (NextLevel,(BorderProd Right,LeftA)), Some "y")
: grammar_constr_prod_item list | | Egrammar.make_constr_prod_item V Gramext.g_symbol list which is sent to camlp5
For user level tactic notations, dynamic addition of new rules is also done in several steps:
- "f" constr(x) (user gives a Tactic Notation command) | | parsing V
TacTerm "f"; TacNonTerm ("constr", Some "x")
: grammar_tactic_prod_item_expr list | | Metasyntax.interp_prod_item VGramTerminal "f"; GramNonTerminal (ConstrArgType, Aentry ("constr","constr"), Some "x")
: grammar_prod_item list | | Egrammar.make_prod_item V Gramext.g_symbol list
For TACTIC/VERNAC/ARGUMENT EXTEND, addition of new rules is done as follows:
- "f" constr(x) (developer gives an EXTEND rule) | | macro-generation in tacextend.mlg/vernacextend.mlg/argextend.mlg V
GramTerminal "f"; GramNonTerminal (ConstrArgType, Aentry ("constr","constr"), Some "x")
| | Egrammar.make_prod_item V Gramext.g_symbol list
Parse a string
val create_generic_entry2 :
string ->
('a, Genarg.rlevel) Genarg.abstract_argument_type ->
'a Entry.t
Type-safe grammar extension
Extending the parser without synchronization
Extend the grammar of Coq, without synchronizing it with the backtracking mechanism. This means that grammar extensions defined this way will survive an undo.
Extending the parser with summary-synchronized commands
Extension with parsing rules
Type of synchronized parsing extensions. The 'a
type should be marshallable.
Type of reinitialization data
type extend_rule =
| ExtendRule : 'a Entry.t * 'a extend_statement -> extend_rule
| ExtendRuleReinit : 'a Entry.t * gram_reinit * 'a extend_statement -> extend_rule
type 'a grammar_extension = {
gext_fun : 'a -> GramState.t -> extend_rule list * GramState.t;
gext_eq : 'a -> 'a -> bool;
}
Grammar extension entry point. Given some 'a
and a current grammar state, such a function must produce the list of grammar extensions that will be applied in the same order and kept synchronized w.r.t. the summary, together with a new state. It should be pure.
Create a new grammar-modifying command with the given name. The extension function is called to generate the rules for a given data.
Extend the grammar of Coq with the given data.
Extension with parsing entries
Type of synchronized entry creation. The 'a
type should be marshallable.
type ('a, 'b) entry_extension = {
eext_fun : 'a -> GramState.t -> string list * GramState.t;
eext_eq : 'a -> 'a -> bool;
}
Entry extension entry point. Given some 'a
and a current grammar state, such a function must produce the list of entry extensions that will be created and kept synchronized w.r.t. the summary, together with a new state. It should be pure.
Create a new entry-creating command with the given name. The extension function is called to generate the new entries for a given data.
Create new synchronized entries using the provided data.
Find an entry generated by the synchronized system in the current state.
Protection w.r.t. backtrack
Registering grammars by name