| 1 |
(* Check that "where" clause behaves as if given independently of the *) |
| 2 |
(* definition (variant of BZ#1132 submitted by Assia Mahboubi) *) |
| 3 |
|
| 4 |
Fixpoint plus1 (n m:nat) {struct n} : nat := |
| 5 |
match n with |
| 6 |
| O => m |
| 7 |
| S p => S (p+m) |
| 8 |
end |
| 9 |
where "n + m" := (plus1 n m) : nat_scope. |
| 10 |
|
| 11 |
(* Check behaviour wrt yet empty levels (see Stephane's bug #1850) *) |
| 12 |
|
| 13 |
Parameter P : Type -> Type -> Type -> Type. |
| 14 |
Notation "e |= t --> v" := (P e t v) (at level 100, t at level 54). |
| 15 |
Check (nat |= nat --> nat). |
| 16 |
|
| 17 |
(* Check that first non empty definition at an empty level can be of any |
| 18 |
associativity *) |
| 19 |
|
| 20 |
Module Type v1. |
| 21 |
Notation "x +1" := (S x) (at level 8, left associativity). |
| 22 |
End v1. |
| 23 |
Module Type v2. |
| 24 |
Notation "x +1" := (S x) (at level 8, right associativity). |
| 25 |
End v2. |
| 26 |
|
| 27 |
(* Check that empty levels (here 8 and 2 in pattern) are added in the |
| 28 |
right order *) |
| 29 |
|
| 30 |
Notation "' 'C_' G ( A )" := (A,G) (at level 8, G at level 2). |
| 31 |
|
| 32 |
(* Check import of notations from within a section *) |
| 33 |
|
| 34 |
Notation "+1 x" := (S x) (at level 25, x at level 9). |
| 35 |
Section A. Require Import make_notation. End A. |
| 36 |
|
| 37 |
(* Check use of "$" (see bug #1961) *) |
| 38 |
|
| 39 |
Notation "$ x" := (id x) (at level 30). |
| 40 |
Check ($ 5). |
| 41 |
|
| 42 |
(* Check regression of bug #2087 *) |
| 43 |
|
| 44 |
Notation "'exists' x , P" := (x, P) |
| 45 |
(at level 200, x ident, right associativity, only parsing). |
| 46 |
|
| 47 |
Definition foo P := let '(exists x, Q) := P in x = Q :> nat. |
| 48 |
|
| 49 |
(* Check empty levels when extending binder_constr *) |
| 50 |
|
| 51 |
Notation "'exists' x >= y , P" := (exists x, x >= y /\ P)%nat |
| 52 |
(at level 200, x ident, right associativity, y at level 69). |
| 53 |
|
| 54 |
(* This used to loop at some time before r12491 *) |
| 55 |
|
| 56 |
Notation R x := (@pair _ _ x). |
| 57 |
Check (fun x:nat*nat => match x with R x y => (x,y) end). |
| 58 |
|
| 59 |
(* Check multi-tokens recursive notations *) |
| 60 |
|
| 61 |
Local Notation "[ a # ; .. # ; b ]" := (a + .. (b + 0) ..). |
| 62 |
Check [ 0 ]. |
| 63 |
Check [ 0 # ; 1 ]. |
| 64 |
|
| 65 |
(* Check well-scoping of alpha-renaming of private binders *) |
| 66 |
(* see bug #2248 (thanks to Marc Lasson) *) |
| 67 |
|
| 68 |
Notation "{ q , r | P }" := (fun (p:nat*nat) => let (q, r) := p in P). |
| 69 |
Check (fun p => {q,r| q + r = p}). |
| 70 |
|
| 71 |
(* Check that declarations of empty levels are correctly backtracked *) |
| 72 |
|
| 73 |
Section B. |
| 74 |
Notation "*" := 5 (at level 0) : nat_scope. |
| 75 |
Notation "[ h ] p" := (h + p) (at level 8, p at level 9, h at level 7) : nat_scope. |
| 76 |
End B. |
| 77 |
|
| 78 |
(* Should succeed *) |
| 79 |
Definition n := 5 * 5. |
| 80 |
|
| 81 |
(* Check that lonely notations (here FOO) do not modify the visibility |
| 82 |
of scoped interpretations (bug #2634 fixed in r14819) *) |
| 83 |
|
| 84 |
Notation "x ++++ y" := (mult x y) (at level 40). |
| 85 |
Notation "x ++++ y" := (plus x y) : A_scope. |
| 86 |
Open Scope A_scope. |
| 87 |
Notation "'FOO' x" := (S x) (at level 40). |
| 88 |
Goal (2 ++++ 3) = 5. |
| 89 |
reflexivity. |
| 90 |
Abort. |
| 91 |
|
| 92 |
(* Check correct failure handling when a non-constructor notation is |
| 93 |
used in cases pattern (bug #2724 in 8.3 and 8.4beta) *) |
| 94 |
|
| 95 |
Notation "'FORALL' x .. y , P" := (forall x, .. (forall y, P) ..) |
| 96 |
(at level 200, x binder, y binder, right associativity) : type_scope. |
| 97 |
|
| 98 |
Fail Check fun x => match x with S (FORALL x, _) => 0 end. |
| 99 |
|
| 100 |
(* Bug #2708: don't check for scope of variables used as binder *) |
| 101 |
|
| 102 |
Parameter traverse : (nat -> unit) -> (nat -> unit). |
| 103 |
Notation traverse_var f l := (traverse (fun l => f l) l). |
| 104 |
|
| 105 |
(* Check that when an ident become a keyword, it does not break |
| 106 |
previous rules relying on the string to be classified as an ident *) |
| 107 |
|
| 108 |
Notation "'intros' x" := (S x) (at level 0). |
| 109 |
Goal True -> True. intros H. exact H. Qed. |
| 110 |
|
| 111 |
(* Check absence of collision on ".." in nested notations with ".." *) |
| 112 |
Notation "[ a , .. , b ]" := (a, (.. (b,tt) ..)). |
| 113 |
|
| 114 |
(* Check that vector notations do not break Ltac [] (bugs #4785, #4733) *) |
| 115 |
Notation "[ ]" := (nil _) (format "[ ]") : vector_scope. |
| 116 |
Goal True. idtac; []. (* important for test: no space here *) constructor. Qed. |
| 117 |
|
| 118 |
(* Check parsing of { and } is not affected by notations #3479 *) |
| 119 |
Notation " |- {{ a }} b" := (a=b) (no associativity, at level 10). |
| 120 |
Goal True. |
| 121 |
{{ exact I. }} |
| 122 |
Qed. |
| 123 |
|
| 124 |
Check |- {{ 0 }} 0. |
| 125 |
|
| 126 |
(* Check parsing of { and } is not affected by notations #3479 *) |
| 127 |
Notation " |- {{ a }} b" := (a=b) (no associativity, at level 10). |
| 128 |
Goal True. |
| 129 |
{{ exact I. }} |
| 130 |
Qed. |
| 131 |
|
| 132 |
(* Check that we can have notations without any symbol iff they are "only printing". *) |
| 133 |
Fail Notation "" := (@nil). |
| 134 |
Notation "" := (@nil) (only printing). |
| 135 |
|
| 136 |
(* Check that a notation cannot be neither parsing nor printing. *) |
| 137 |
Fail Notation "'foobarkeyword'" := (@nil) (only parsing, only printing). |
| 138 |
|
| 139 |
(* Check "where" clause for inductive types with parameters *) |
| 140 |
|
| 141 |
Reserved Notation "x === y" (at level 50). |
| 142 |
Inductive EQ {A} (x:A) : A -> Prop := REFL : x === x |
| 143 |
where "x === y" := (EQ x y). |
| 144 |
|
| 145 |
(* Check that strictly ident or _ are coerced to a name *) |
| 146 |
|
| 147 |
Fail Check {x@{u},y|x=x}. |
| 148 |
Fail Check {?[n],y|0=0}. |
| 149 |
|
| 150 |
(* Check that 10 is well declared left associative *) |
| 151 |
|
| 152 |
Section C. |
| 153 |
Notation "f $$$ x" := (id f x) (at level 10, left associativity). |
| 154 |
End C. |
| 155 |
|
| 156 |
(* Scope names should not start with an underscore *) |
| 157 |
Fail Declare Scope _scope_start_underscore. |
| 158 |
|
| 159 |
(* Scope delimiters should not start with an underscore *) |
| 160 |
Fail Delimit Scope type_scope with _type. |
| 161 |
|
| 162 |
Module ImplicitArgumentsPrimToken. |
| 163 |
|
| 164 |
(* Check that implicit arguments of number notations are taken into account *) |
| 165 |
|
| 166 |
Class T (A:Type). |
| 167 |
Parameter (a:T nat). |
| 168 |
Axiom f : forall A, T A -> A. |
| 169 |
Arguments f {A} {_}. |
| 170 |
Notation "0" := f. |
| 171 |
Check 0 = 1. |
| 172 |
|
| 173 |
End ImplicitArgumentsPrimToken. |