| 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 |
open Procq |
| 15 |
open Procq.Prim |
| 16 |
open Procq.Constr |
| 17 |
open Pvernac.Vernac_ |
| 18 |
|
| 19 |
open Util |
| 20 |
open Locus |
| 21 |
open Genredexpr |
| 22 |
|
| 23 |
let all_with ~head delta = |
| 24 |
let all = [FBeta;FMatch;FFix;FCofix;FZeta;delta] in |
| 25 |
Redops.make_red_flag (if head then FHead :: all else all) |
| 26 |
|
| 27 |
let int_or_var = Entry.make "int_or_var" |
| 28 |
let nat_or_var = Entry.make "nat_or_var" |
| 29 |
let pattern_occ = Entry.make "pattern_occ" |
| 30 |
let unfold_occ = Entry.make "unfold_occ" |
| 31 |
let ref_or_pattern_occ = Entry.make "ref_or_pattern_occ" |
| 32 |
let occs_nums = Entry.make "occs_nums" |
| 33 |
let occs = Entry.make "occs" |
| 34 |
let delta_flag = Entry.make "delta_flag" |
| 35 |
let strategy_flag = Entry.make "strategy_flag" |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
GRAMMAR EXTEND Gram |
| 40 |
GLOBAL: int_or_var nat_or_var occs occs_nums unfold_occ pattern_occ |
| 41 |
delta_flag strategy_flag ref_or_pattern_occ red_expr; |
| 42 |
|
| 43 |
int_or_var: |
| 44 |
[ [ n = integer -> { ArgArg n } |
| 45 |
| id = identref -> { ArgVar id } ] ] |
| 46 |
; |
| 47 |
nat_or_var: |
| 48 |
[ [ n = natural -> { ArgArg n } |
| 49 |
| id = identref -> { ArgVar id } ] ] |
| 50 |
; |
| 51 |
|
| 52 |
occs_nums: |
| 53 |
[ [ nl = LIST1 nat_or_var -> { OnlyOccurrences nl } |
| 54 |
| "-"; nl = LIST1 nat_or_var -> { AllOccurrencesBut nl } ] ] |
| 55 |
; |
| 56 |
occs: |
| 57 |
[ [ "at"; occs = occs_nums -> { occs } | -> { AllOccurrences } ] ] |
| 58 |
; |
| 59 |
pattern_occ: |
| 60 |
[ [ c = constr; nl = occs -> { (nl,c) } ] ] |
| 61 |
; |
| 62 |
ref_or_pattern_occ: |
| 63 |
(* If a string, it is interpreted as a ref |
| 64 |
(anyway a Rocq string does not reduce) *) |
| 65 |
[ [ c = smart_global; nl = occs -> { nl,Inl c } |
| 66 |
| c = constr; nl = occs -> { nl,Inr c } ] ] |
| 67 |
; |
| 68 |
unfold_occ: |
| 69 |
[ [ c = smart_global; nl = occs -> { (nl,c) } ] ] |
| 70 |
; |
| 71 |
red_flag: |
| 72 |
[ [ IDENT "beta" -> { [FBeta] } |
| 73 |
| IDENT "iota" -> { [FMatch;FFix;FCofix] } |
| 74 |
| IDENT "match" -> { [FMatch] } |
| 75 |
| IDENT "fix" -> { [FFix] } |
| 76 |
| IDENT "cofix" -> { [FCofix] } |
| 77 |
| IDENT "zeta" -> { [FZeta] } |
| 78 |
| IDENT "delta"; d = delta_flag -> { [d] } |
| 79 |
| IDENT "head" -> { [FHead] } |
| 80 |
] ] |
| 81 |
; |
| 82 |
delta_flag: |
| 83 |
[ [ "-"; "["; idl = LIST1 smart_global; "]" -> { FDeltaBut idl } |
| 84 |
| "["; idl = LIST1 smart_global; "]" -> { FConst idl } |
| 85 |
| -> { FDeltaBut [] } |
| 86 |
] ] |
| 87 |
; |
| 88 |
strategy_flag: |
| 89 |
[ [ s = LIST1 red_flag -> { Redops.make_red_flag (List.flatten s) } |
| 90 |
| h = OPT [ IDENT "head" -> { () } ]; d = delta_flag -> { all_with ~head:(Option.has_some h) d } |
| 91 |
] ] |
| 92 |
; |
| 93 |
|
| 94 |
red_expr: |
| 95 |
[ [ IDENT "red" -> { Red } |
| 96 |
| IDENT "hnf" -> { Hnf } |
| 97 |
| IDENT "simpl"; h = OPT [ IDENT "head" -> { () } ]; |
| 98 |
d = delta_flag; po = OPT ref_or_pattern_occ -> { Simpl (all_with ~head:(Option.has_some h) d,po) } |
| 99 |
| IDENT "cbv"; s = strategy_flag -> { Cbv s } |
| 100 |
| IDENT "cbn"; s = strategy_flag -> { Cbn s } |
| 101 |
| IDENT "lazy"; s = strategy_flag -> { Lazy s } |
| 102 |
| IDENT "compute"; delta = delta_flag -> { Cbv (all_with ~head:false delta) } |
| 103 |
| IDENT "vm_compute"; po = OPT ref_or_pattern_occ -> { CbvVm po } |
| 104 |
| IDENT "native_compute"; po = OPT ref_or_pattern_occ -> { CbvNative po } |
| 105 |
| IDENT "unfold"; ul = LIST1 unfold_occ SEP "," -> { Unfold ul } |
| 106 |
| IDENT "fold"; cl = LIST1 constr -> { Fold cl } |
| 107 |
| IDENT "pattern"; pl = LIST1 pattern_occ SEP"," -> { Pattern pl } |
| 108 |
| s = IDENT -> { ExtraRedExpr s } ] ] |
| 109 |
; |
| 110 |
END |