notation.v 5.2 KB
Newer Older
1 2
From iris.program_logic Require Import language.
From iris.heap_lang Require Export lang tactics.
3

4
Coercion LitInt : Z >-> base_lit.
5
Coercion LitBool : bool >-> base_lit.
6 7
Coercion LitLoc : loc >-> base_lit.

8 9 10
Coercion App : expr >-> Funclass.
Coercion of_val : val >-> expr.

11 12
Coercion Var : string >-> expr.

13
Coercion BNamed : string >-> binder.
14
Notation "<>" := BAnon : binder_scope.
15

16 17
(* No scope for the values, does not conflict and scope is often not inferred
properly. *)
18 19
Notation "# l" := (LitV l%Z%V) (at level 8, format "# l").
Notation "# l" := (Lit l%Z%V) (at level 8, format "# l") : expr_scope.
20

21 22 23
(** Syntax inspired by Coq/Ocaml. Constructions with higher precedence come
    first. *)
Notation "( e1 , e2 , .. , en )" := (Pair .. (Pair e1 e2) .. en) : expr_scope.
Robbert Krebbers's avatar
Robbert Krebbers committed
24
Notation "( e1 , e2 , .. , en )" := (PairV .. (PairV e1 e2) .. en) : val_scope.
25
Notation "'match:' e0 'with' 'InjL' x1 => e1 | 'InjR' x2 => e2 'end'" :=
Ralf Jung's avatar
Ralf Jung committed
26
  (Match e0 x1%bind e1 x2%bind e2)
27
  (e0, x1, e1, x2, e2 at level 200) : expr_scope.
28
Notation "'match:' e0 'with' 'InjR' x1 => e1 | 'InjL' x2 => e2 'end'" :=
Ralf Jung's avatar
Ralf Jung committed
29
  (Match e0 x2%bind e2 x1%bind e1)
Ralf Jung's avatar
Ralf Jung committed
30
  (e0, x1, e1, x2, e2 at level 200, only parsing) : expr_scope.
31
Notation "()" := LitUnit : val_scope.
32 33 34 35 36 37 38 39 40 41 42 43
Notation "! e" := (Load e%E) (at level 9, right associativity) : expr_scope.
Notation "'ref' e" := (Alloc e%E)
  (at level 30, right associativity) : expr_scope.
Notation "- e" := (UnOp MinusUnOp e%E)
  (at level 35, right associativity) : expr_scope.
Notation "e1 + e2" := (BinOp PlusOp e1%E e2%E)
  (at level 50, left associativity) : expr_scope.
Notation "e1 - e2" := (BinOp MinusOp e1%E e2%E)
  (at level 50, left associativity) : expr_scope.
Notation "e1 ≤ e2" := (BinOp LeOp e1%E e2%E) (at level 70) : expr_scope.
Notation "e1 < e2" := (BinOp LtOp e1%E e2%E) (at level 70) : expr_scope.
Notation "e1 = e2" := (BinOp EqOp e1%E e2%E) (at level 70) : expr_scope.
44
Notation "e1 ≠ e2" := (UnOp NegOp (BinOp EqOp e1%E e2%E)) (at level 70) : expr_scope.
45
Notation "~ e" := (UnOp NegOp e%E) (at level 75, right associativity) : expr_scope.
46
(* The unicode ← is already part of the notation "_ ← _; _" for bind. *)
47
Notation "e1 <- e2" := (Store e1%E e2%E) (at level 80) : expr_scope.
Ralf Jung's avatar
Ralf Jung committed
48
Notation "'rec:' f x := e" := (Rec f%bind x%bind e%E)
49
  (at level 102, f at level 1, x at level 1, e at level 200) : expr_scope.
50
Notation "'rec:' f x := e" := (locked (RecV f%bind x%bind e%E))
51
  (at level 102, f at level 1, x at level 1, e at level 200) : val_scope.
52 53
Notation "'if:' e1 'then' e2 'else' e3" := (If e1%E e2%E e3%E)
  (at level 200, e1, e2, e3 at level 200) : expr_scope.
54 55 56 57 58

(** Derived notions, in order of declaration. The notations for let and seq
are stated explicitly instead of relying on the Notations Let and Seq as
defined above. This is needed because App is now a coercion, and these
notations are otherwise not pretty printed back accordingly. *)
Ralf Jung's avatar
Ralf Jung committed
59
Notation "'rec:' f x y := e" := (Rec f%bind x%bind (Lam y%bind e%E))
60
  (at level 102, f, x, y at level 1, e at level 200) : expr_scope.
61
Notation "'rec:' f x y := e" := (locked (RecV f%bind x%bind (Lam y%bind e%E)))
62
  (at level 102, f, x, y at level 1, e at level 200) : val_scope.
Ralf Jung's avatar
Ralf Jung committed
63
Notation "'rec:' f x y .. z := e" := (Rec f%bind x%bind (Lam y%bind .. (Lam z%bind e%E) ..))
64
  (at level 102, f, x, y, z at level 1, e at level 200) : expr_scope.
65
Notation "'rec:' f x y .. z := e" := (locked (RecV f%bind x%bind (Lam y%bind .. (Lam z%bind e%E) ..)))
66 67
  (at level 102, f, x, y, z at level 1, e at level 200) : val_scope.

Ralf Jung's avatar
Ralf Jung committed
68
Notation "λ: x , e" := (Lam x%bind e%E)
69
  (at level 102, x at level 1, e at level 200) : expr_scope.
Ralf Jung's avatar
Ralf Jung committed
70
Notation "λ: x y .. z , e" := (Lam x%bind (Lam y%bind .. (Lam z%bind e%E) ..))
71
  (at level 102, x, y, z at level 1, e at level 200) : expr_scope.
72
Notation "λ: x , e" := (locked (LamV x%bind e%E))
73
  (at level 102, x at level 1, e at level 200) : val_scope.
74
Notation "λ: x y .. z , e" := (locked (LamV x%bind (Lam y%bind .. (Lam z%bind e%E) .. )))
75
  (at level 102, x, y, z at level 1, e at level 200) : val_scope.
76

Ralf Jung's avatar
Ralf Jung committed
77
Notation "'let:' x := e1 'in' e2" := (Lam x%bind e2%E e1%E)
78 79 80
  (at level 102, x at level 1, e1, e2 at level 200) : expr_scope.
Notation "e1 ;; e2" := (Lam BAnon e2%E e1%E)
  (at level 100, e2 at level 200, format "e1  ;;  e2") : expr_scope.
81
(* These are not actually values, but we want them to be pretty-printed. *)
Ralf Jung's avatar
Ralf Jung committed
82
Notation "'let:' x := e1 'in' e2" := (LamV x%bind e2%E e1%E)
83
  (at level 102, x at level 1, e1, e2 at level 200) : val_scope.
84
Notation "e1 ;; e2" := (LamV BAnon e2%E e1%E)
85
  (at level 100, e2 at level 200, format "e1  ;;  e2") : val_scope.
86

87
(* Shortcircuit Boolean connectives *)
88
Notation "e1 && e2" :=
Robbert Krebbers's avatar
Oops.  
Robbert Krebbers committed
89
  (If e1%E e2%E (Lit (LitBool false))) (only parsing) : expr_scope.
90
Notation "e1 || e2" :=
Robbert Krebbers's avatar
Oops.  
Robbert Krebbers committed
91
  (If e1%E (Lit (LitBool true)) e2%E) (only parsing) : expr_scope.
92

93
(** Notations for option *)
94 95
Notation NONE := (InjL #()) (only parsing).
Notation SOME x := (InjR x) (only parsing).
96

97 98
Notation NONEV := (InjLV #()) (only parsing).
Notation SOMEV x := (InjRV x) (only parsing).
99 100 101

Notation "'match:' e0 'with' 'NONE' => e1 | 'SOME' x => e2 'end'" :=
  (Match e0 BAnon e1 x%bind e2)
102
  (e0, e1, x, e2 at level 200, only parsing) : expr_scope.
103
Notation "'match:' e0 'with' 'SOME' x => e2 | 'NONE' => e1 'end'" :=
104 105
  (Match e0 BAnon e1 x%bind e2)
  (e0, e1, x, e2 at level 200, only parsing) : expr_scope.