Debian Codegraph @

parsing/extend.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 (** Entry keys for constr notations *)
12
13 type production_position =
14 | BorderProd of Constrexpr.side * Gramlib.Gramext.g_assoc option
15 | InternalProd
16
17 type production_level =
18 | NextLevel
19 | NumLevel of int
20 | DefaultLevel (** Interpreted differently at the border or inside a rule *)
21
22 let production_level_eq lev1 lev2 =
23 match lev1, lev2 with
24 | NextLevel, NextLevel -> true
25 | NumLevel n1, NumLevel n2 -> Int.equal n1 n2
26 | DefaultLevel, DefaultLevel -> true
27 | (NextLevel | NumLevel _| DefaultLevel), _ -> false
28
29 (** User-level types used to tell how to parse or interpret of the non-terminal *)
30
31 type ('custom,'a) constr_entry_key_gen =
32 | ETIdent
33 | ETName
34 | ETGlobal
35 | ETBigint
36 | ETBinder of bool (* open list of binders if true, closed list of binders otherwise *)
37 | ETConstr of 'custom Constrexpr.notation_entry_gen * Notation_term.notation_binder_kind option * 'a
38 | ETPattern of bool * int option (* true = strict pattern, i.e. not a single variable *)
39
40 let constr_entry_key_eq_gen binder_kind_eq v1 v2 = match v1, v2 with
41 | ETIdent, ETIdent -> true
42 | ETName, ETName -> true
43 | ETGlobal, ETGlobal -> true
44 | ETBigint, ETBigint -> true
45 | ETBinder b1, ETBinder b2 -> b1 == b2
46 | ETConstr (s1,bko1,_lev1), ETConstr (s2,bko2,_lev2) ->
47 Notationextern.notation_entry_eq s1 s2 && binder_kind_eq bko1 bko2
48 | ETPattern (b1,n1), ETPattern (b2,n2) -> b1 = b2 && Option.equal Int.equal n1 n2
49 | (ETIdent | ETName | ETGlobal | ETBigint | ETBinder _ | ETConstr _ | ETPattern _), _ -> false
50
51 let constr_entry_key_eq = constr_entry_key_eq_gen (Option.equal Notationextern.notation_binder_kind_eq)
52
53 let constr_entry_key_eq_ignore_binder_kind = constr_entry_key_eq_gen (fun _ _ -> true)
54
55 (** Entries level (left-hand side of grammar rules) *)
56
57 type constr_entry_key =
58 (Globnames.CustomName.t, production_level * production_position) constr_entry_key_gen
59
60 (** Entries used in productions, vernac side (e.g. "x bigint" or "x ident") *)
61
62 type 'custom simple_constr_prod_entry_key =
63 ('custom, production_level) constr_entry_key_gen
64
65 (** Entries used in productions (in right-hand-side of grammar rules), to parse non-terminals *)
66
67 type binder_target = ForBinder | ForTerm
68
69 type binder_entry_kind = ETBinderOpen | ETBinderClosed of constr_prod_entry_key option * (bool * string) list
70
71 and constr_prod_entry_key =
72 | ETProdIdent (* Parsed as an ident *)
73 | ETProdName (* Parsed as a name (ident or _) *)
74 | ETProdGlobal (* Parsed as a global reference *)
75 | ETProdBigint (* Parsed as an (unbounded) integer *)
76 | ETProdOneBinder of bool (* Parsed as name, or name:type or 'pattern, possibly in closed form *)
77 | ETProdConstr of Constrexpr.notation_entry * (production_level * production_position) (* Parsed as constr or custom when extending a constr or custom entry; parsed as pattern or custom pattern when extending a pattern or custom pattern entry *)
78 | ETProdPattern of int (* Parsed as pattern as a binder (as subpart of a constr) *)
79 | ETProdConstrList of Constrexpr.notation_entry * (production_level * production_position) * (bool * string) list (* Parsed as a non-empty list of constr or custom entry *)
80 | ETProdBinderList of binder_entry_kind (* Parsed as non-empty list of local binders *)
81
82 (** {5 AST for user-provided entries} *)
83
84 type 'a user_symbol =
85 | Ulist1 of 'a user_symbol
86 | Ulist1sep of 'a user_symbol * string
87 | Ulist0 of 'a user_symbol
88 | Ulist0sep of 'a user_symbol * string
89 | Uopt of 'a user_symbol
90 | Uentry of 'a
91 | Uentryl of 'a * int
92
93 type ('a,'b,'c) ty_user_symbol =
94 | TUlist1 : ('a,'b,'c) ty_user_symbol -> ('a list,'b list,'c list) ty_user_symbol
95 | TUlist1sep : ('a,'b,'c) ty_user_symbol * string -> ('a list,'b list,'c list) ty_user_symbol
96 | TUlist0 : ('a,'b,'c) ty_user_symbol -> ('a list,'b list,'c list) ty_user_symbol
97 | TUlist0sep : ('a,'b,'c) ty_user_symbol * string -> ('a list,'b list,'c list) ty_user_symbol
98 | TUopt : ('a,'b,'c) ty_user_symbol -> ('a option, 'b option, 'c option) ty_user_symbol
99 | TUentry : ('a, 'b, 'c) Genarg.ArgT.tag -> ('a,'b,'c) ty_user_symbol
100 | TUentryl : ('a, 'b, 'c) Genarg.ArgT.tag * int -> ('a,'b,'c) ty_user_symbol