| 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 |
(* (c) Copyright 2006-2015 Microsoft Corporation and Inria. *) |
| 12 |
|
| 13 |
{ |
| 14 |
|
| 15 |
open Ltac_plugin |
| 16 |
open Procq.Constr |
| 17 |
open Ssrmatching |
| 18 |
open Ssrmatching.Internal |
| 19 |
|
| 20 |
} |
| 21 |
|
| 22 |
DECLARE PLUGIN "rocq-runtime.plugins.ssrmatching" |
| 23 |
|
| 24 |
(* The user is supposed to Require Import ssreflect or Require ssreflect *) |
| 25 |
(* and Import ssreflect.SsrSyntax to obtain these keywords and as a *) |
| 26 |
(* consequence the extended ssreflect grammar. *) |
| 27 |
IGNORE KEYWORDS |
| 28 |
|
| 29 |
{ |
| 30 |
|
| 31 |
let pr_rpattern _ _ _ = pr_rpattern |
| 32 |
|
| 33 |
} |
| 34 |
|
| 35 |
ARGUMENT EXTEND rpattern |
| 36 |
TYPED AS rpatternty |
| 37 |
PRINTED BY { pr_rpattern } |
| 38 |
INTERPRETED BY { interp_rpattern } |
| 39 |
GLOBALIZED BY { glob_rpattern } |
| 40 |
SUBSTITUTED BY { subst_rpattern } |
| 41 |
| [ lconstr(c) ] -> { mk_rpattern (T (mk_lterm c None)) } |
| 42 |
| [ "in" lconstr(c) ] -> { mk_rpattern (In_T (mk_lterm c None)) } |
| 43 |
| [ lconstr(x) "in" lconstr(c) ] -> |
| 44 |
{ mk_rpattern (X_In_T (mk_lterm x None, mk_lterm c None)) } |
| 45 |
| [ "in" lconstr(x) "in" lconstr(c) ] -> |
| 46 |
{ mk_rpattern (In_X_In_T (mk_lterm x None, mk_lterm c None)) } |
| 47 |
| [ lconstr(e) "in" lconstr(x) "in" lconstr(c) ] -> |
| 48 |
{ mk_rpattern (E_In_X_In_T (mk_lterm e None, (mk_lterm x None, mk_lterm c None))) } |
| 49 |
| [ lconstr(e) "as" lconstr(x) "in" lconstr(c) ] -> |
| 50 |
{ mk_rpattern (E_As_X_In_T (mk_lterm e None, (mk_lterm x None, mk_lterm c None))) } |
| 51 |
END |
| 52 |
|
| 53 |
{ |
| 54 |
|
| 55 |
let pr_ssrterm _ _ _ = pr_ssrterm |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
ARGUMENT EXTEND cpattern |
| 60 |
PRINTED BY { pr_ssrterm } |
| 61 |
INTERPRETED BY { interp_ssrterm } |
| 62 |
GLOBALIZED BY { glob_cpattern } SUBSTITUTED BY { subst_ssrterm } |
| 63 |
RAW_PRINTED BY { pr_ssrterm } |
| 64 |
GLOB_PRINTED BY { pr_ssrterm } |
| 65 |
| [ "Qed" constr(c) ] -> { mk_lterm c None } |
| 66 |
END |
| 67 |
|
| 68 |
{ |
| 69 |
|
| 70 |
let input_ssrtermkind kwstate strm = match Gramlib.LStream.peek_nth kwstate 0 strm with |
| 71 |
| Some (Tok.KEYWORD "(") -> Ok InParens |
| 72 |
| Some (Tok.KEYWORD "@") -> Ok WithAt |
| 73 |
| Some _ -> Ok NoFlag |
| 74 |
| None -> Error () (* NB this never happens, instead we get a EOI token *) |
| 75 |
let ssrtermkind = Procq.Entry.(of_parser "ssrtermkind" { parser_fun = input_ssrtermkind }) |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
GRAMMAR EXTEND Gram |
| 80 |
GLOBAL: cpattern; |
| 81 |
cpattern: TOP [[ k = ssrtermkind; c = constr -> { |
| 82 |
let pattern = mk_term k c None in |
| 83 |
if loc_of_cpattern pattern <> Some loc && k = InParens |
| 84 |
then mk_term Cpattern c None |
| 85 |
else pattern } ]]; |
| 86 |
END |
| 87 |
|
| 88 |
ARGUMENT EXTEND lcpattern |
| 89 |
TYPED AS cpattern |
| 90 |
PRINTED BY { pr_ssrterm } |
| 91 |
INTERPRETED BY { interp_ssrterm } |
| 92 |
GLOBALIZED BY { glob_cpattern } SUBSTITUTED BY { subst_ssrterm } |
| 93 |
RAW_PRINTED BY { pr_ssrterm } |
| 94 |
GLOB_PRINTED BY { pr_ssrterm } |
| 95 |
| [ "Qed" lconstr(c) ] -> { mk_lterm c None } |
| 96 |
END |
| 97 |
|
| 98 |
GRAMMAR EXTEND Gram |
| 99 |
GLOBAL: lcpattern; |
| 100 |
lcpattern: TOP [[ k = ssrtermkind; c = lconstr -> { |
| 101 |
let pattern = mk_term k c None in |
| 102 |
if loc_of_cpattern pattern <> Some loc && k = InParens |
| 103 |
then mk_term Cpattern c None |
| 104 |
else pattern } ]]; |
| 105 |
END |
| 106 |
|
| 107 |
ARGUMENT EXTEND ssrpatternarg TYPED AS rpattern PRINTED BY { pr_rpattern } |
| 108 |
| [ rpattern(pat) ] -> { pat } |
| 109 |
END |
| 110 |
|
| 111 |
TACTIC EXTEND ssrinstoftpat |
| 112 |
| [ "ssrinstancesoftpat" cpattern(arg) ] -> { ssrinstancesof arg } |
| 113 |
END |