Debian Codegraph @

vernac/pvernac.ml

raw symbols SCIP
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 open Procq
12
13 type proof_mode_entry = ProofMode : {
14 command_entry : Vernacexpr.vernac_expr Entry.t;
15 wit_tactic_expr : ('raw,_,unit) Genarg.genarg_type;
16 tactic_expr_entry : 'raw Entry.t;
17 } -> proof_mode_entry
18
19 type proof_mode = string
20
21 (* Tactic parsing modes *)
22 let register_proof_mode, find_proof_mode, lookup_proof_mode, list_proof_modes =
23 let proof_mode : (string, proof_mode_entry) Hashtbl.t =
24 Hashtbl.create 19 in
25 let register_proof_mode ename e = Hashtbl.add proof_mode ename e; ename in
26 let find_proof_mode ename =
27 try Hashtbl.find proof_mode ename
28 with Not_found ->
29 CErrors.anomaly Pp.(str "proof mode not found: " ++ str ename) in
30 let lookup_proof_mode name =
31 if Hashtbl.mem proof_mode name then Some name
32 else None
33 in
34 let list_proof_modes () =
35 Hashtbl.fold CString.Map.add proof_mode CString.Map.empty
36 in
37 register_proof_mode, find_proof_mode, lookup_proof_mode, list_proof_modes
38
39 let proof_mode_to_string name = name
40
41 (* Default proof mode, to be set at the beginning of proofs for
42 programs that cannot be statically classified. *)
43 let proof_mode_opt_name = ["Default";"Proof";"Mode"]
44
45 let noedit_mode = Entry.make "noedit_command"
46 let noedit_tactic_expr = Entry.make "noedit_tactic_expr"
47
48 let noedit_mode_entry = ProofMode {
49 command_entry = noedit_mode;
50 wit_tactic_expr = Stdarg.wit_unit;
51 tactic_expr_entry = noedit_tactic_expr;
52 }
53
54 let { Goptions.get = get_default_proof_mode } =
55 Goptions.declare_interpreted_string_option_and_ref
56 ~stage:Summary.Stage.Synterp
57 ~key:proof_mode_opt_name
58 ~value:(register_proof_mode "Noedit" noedit_mode_entry)
59 (fun name -> match lookup_proof_mode name with
60 | Some pm -> pm
61 | None -> CErrors.user_err Pp.(str (Format.sprintf "No proof mode named \"%s\"." name)))
62 proof_mode_to_string
63 ()
64
65 let command_entry_ref = ref None
66
67 module Vernac_ =
68 struct
69 (* The different kinds of vernacular commands *)
70 let gallina = Entry.make "gallina"
71 let gallina_ext = Entry.make "gallina_ext"
72 let command = Entry.make "command"
73 let syntax = Entry.make "syntax_command"
74 let vernac_control = Entry.make "vernac_control"
75 let inductive_or_record_definition = Entry.make "inductive_or_record_definition"
76 let fix_definition = Entry.make "fix_definition"
77 let red_expr = Entry.make "red_expr"
78 let hint_info = Entry.make "hint_info"
79 (* Main vernac entry *)
80 let main_entry = Entry.make "vernac"
81 let noedit_mode = noedit_mode
82
83 let () =
84 let act_vernac v loc = Some v in
85 let act_eoi _ loc = None in
86 let rule = [
87 Procq.(Production.make (Rule.next Rule.stop (Symbol.token Tok.PEOI)) act_eoi);
88 Procq.(Production.make (Rule.next Rule.stop (Symbol.nterm vernac_control)) act_vernac);
89 ] in
90 (* NB ignore_kw doesn't matter, no potential keywords here *)
91 Procq.(grammar_extend ~ignore_kw:true main_entry
92 (Fresh (Gramlib.Gramext.First, [None, None, rule])))
93
94 let select_command_entry spec =
95 match spec with
96 | None -> noedit_mode
97 | Some ename ->
98 let ProofMode mode = find_proof_mode ename in
99 mode.command_entry
100
101 let parse_generic_tactic strm =
102 let (let+) x f = Result.map f x in
103 let mode = get_default_proof_mode () in
104 let ProofMode mode = find_proof_mode mode in
105 let+ v = Procq.Entry.parse_token_stream mode.tactic_expr_entry strm in
106 Gentactic.of_raw_genarg Genarg.(in_gen (rawwit mode.wit_tactic_expr) v)
107
108 let command_entry =
109 Procq.Entry.(of_parser "command_entry"
110 { parser_fun = (fun _kwstate strm -> Procq.Entry.parse_token_stream (select_command_entry !command_entry_ref) strm) })
111
112 let generic_tactic =
113 Procq.Entry.(of_parser "generic_tactic"
114 { parser_fun = (fun _kwstate strm -> parse_generic_tactic strm) })
115
116 end
117
118 module Unsafe = struct
119 let set_tactic_entry oname = command_entry_ref := oname
120 end
121
122 let main_entry proof_mode =
123 Unsafe.set_tactic_entry proof_mode;
124 Vernac_.main_entry
125
126 let () =
127 register_grammar Redexpr.wit_red_expr (Vernac_.red_expr);
128 register_grammar Gentactic.wit_generic_tactic Vernac_.generic_tactic