| 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 |
DECLARE GLOBAL PLUGIN |
| 12 |
|
| 13 |
{ |
| 14 |
|
| 15 |
open Names |
| 16 |
open Libnames |
| 17 |
|
| 18 |
open Procq.Prim |
| 19 |
|
| 20 |
let local_make_qualid loc l id = make_qualid ~loc (DirPath.make l) id |
| 21 |
|
| 22 |
let my_int_of_string ?loc s = |
| 23 |
try |
| 24 |
int_of_string s |
| 25 |
with Failure _ -> |
| 26 |
CErrors.user_err ?loc (Pp.str "This number is too large.") |
| 27 |
|
| 28 |
let my_to_nat_string ?loc s = |
| 29 |
match NumTok.Unsigned.to_nat s with |
| 30 |
| Some n -> n |
| 31 |
| None -> |
| 32 |
CErrors.user_err ?loc Pp.(str "This number is not an integer.") |
| 33 |
|
| 34 |
let test_pipe_closedcurly = |
| 35 |
let open Procq.Lookahead in |
| 36 |
to_entry "test_pipe_closedcurly" begin |
| 37 |
lk_kw "|" >> lk_kw "}" >> check_no_space |
| 38 |
end |
| 39 |
|
| 40 |
let test_minus_nat = |
| 41 |
let open Procq.Lookahead in |
| 42 |
to_entry "test_minus_nat" begin |
| 43 |
lk_kw "-" >> lk_nat >> check_no_space |
| 44 |
end |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
GRAMMAR EXTEND Gram |
| 49 |
GLOBAL: |
| 50 |
bignat bigint natural integer identref name ident hyp preident |
| 51 |
fullyqualid qualid reference dirpath ne_lstring |
| 52 |
ne_string string lstring pattern_ident by_notation |
| 53 |
smart_global bar_cbrace strategy_level fields; |
| 54 |
preident: |
| 55 |
[ [ s = IDENT -> { s } ] ] |
| 56 |
; |
| 57 |
ident: |
| 58 |
[ [ s = IDENT -> { Id.of_string s } ] ] |
| 59 |
; |
| 60 |
pattern_ident: |
| 61 |
[ [ LEFTQMARK; id = ident -> { CAst.make ~loc id } ] ] |
| 62 |
; |
| 63 |
identref: |
| 64 |
[ [ id = ident -> { CAst.make ~loc id } ] ] |
| 65 |
; |
| 66 |
hyp: (* as identref, but interpreted as an hypothesis in tactic notations *) |
| 67 |
[ [ id = identref -> { id } ] ] |
| 68 |
; |
| 69 |
field: |
| 70 |
[ [ s = FIELD -> { Id.of_string s } ] ] |
| 71 |
; |
| 72 |
fields: |
| 73 |
[ RIGHTA [ id = field; f = fields -> { let (l,id') = f in (l@[id],id') } |
| 74 |
| id = field -> { ([],id) } |
| 75 |
] ] |
| 76 |
; |
| 77 |
fullyqualid: |
| 78 |
[ [ id = ident; f=fields -> { let (l,id') = f in CAst.make ~loc @@ id::List.rev (id'::l) } |
| 79 |
| id = ident -> { CAst.make ~loc [id] } |
| 80 |
] ] |
| 81 |
; |
| 82 |
name: |
| 83 |
[ [ IDENT "_" -> { CAst.make ~loc Anonymous } |
| 84 |
| id = ident -> { CAst.make ~loc @@ Name id } ] ] |
| 85 |
; |
| 86 |
reference: |
| 87 |
[ [ id = ident; f = fields -> { |
| 88 |
let (l,id') = f in |
| 89 |
local_make_qualid loc (l@[id]) id' } |
| 90 |
| id = ident -> { qualid_of_ident ~loc id } |
| 91 |
] ] |
| 92 |
; |
| 93 |
qualid: (* Synonymous to reference *) |
| 94 |
[ [ qid = reference -> { qid } ] ] |
| 95 |
; |
| 96 |
by_notation: |
| 97 |
[ [ s = ne_string; sc = OPT ["%"; key = IDENT -> { key } ] -> { (s, sc) } ] ] |
| 98 |
; |
| 99 |
smart_global: |
| 100 |
[ [ c = reference -> { CAst.make ~loc @@ Constrexpr.AN c } |
| 101 |
| ntn = by_notation -> { CAst.make ~loc @@ Constrexpr.ByNotation ntn } ] ] |
| 102 |
; |
| 103 |
ne_string: |
| 104 |
[ [ s = STRING -> |
| 105 |
{ if s="" then CErrors.user_err ~loc (Pp.str"Empty string."); s } |
| 106 |
] ] |
| 107 |
; |
| 108 |
ne_lstring: |
| 109 |
[ [ s = ne_string -> { CAst.make ~loc s } ] ] |
| 110 |
; |
| 111 |
dirpath: |
| 112 |
[ [ id = ident; l = LIST0 field -> |
| 113 |
{ DirPath.make (List.rev (id::l)) } ] ] |
| 114 |
; |
| 115 |
string: |
| 116 |
[ [ s = STRING -> { s } ] ] |
| 117 |
; |
| 118 |
lstring: |
| 119 |
[ [ s = string -> { CAst.make ~loc s } ] ] |
| 120 |
; |
| 121 |
integer: |
| 122 |
[ [ i = bigint -> { my_int_of_string ~loc i } ] ] |
| 123 |
; |
| 124 |
natural: |
| 125 |
[ [ i = bignat -> { my_int_of_string ~loc i } ] ] |
| 126 |
; |
| 127 |
bigint: |
| 128 |
[ [ i = bignat -> { i } |
| 129 |
| test_minus_nat; "-"; i = bignat -> { "-" ^ i } ] ] |
| 130 |
; |
| 131 |
bignat: |
| 132 |
[ [ i = NUMBER -> { my_to_nat_string ~loc i } ] ] |
| 133 |
; |
| 134 |
bar_cbrace: |
| 135 |
[ [ test_pipe_closedcurly; "|"; "}" -> { () } ] ] |
| 136 |
; |
| 137 |
strategy_level: |
| 138 |
[ [ IDENT "expand" -> { Conv_oracle.Expand } |
| 139 |
| IDENT "opaque" -> { Conv_oracle.Opaque } |
| 140 |
| n=integer -> { Conv_oracle.Level n } |
| 141 |
| IDENT "transparent" -> { Conv_oracle.transparent } ] ] |
| 142 |
; |
| 143 |
END |