lean4-htt/tests/lean/run/macro.lean
Leonardo de Moura 5ac7b1232a chore: add workarounds
@Kha It seems the recent parser modifications created some unexpected
problems. I didn't investigate them. I am "lost" in the elaborator and
dependent pattern matching land.

1) We can't write anymore
```
f [1, 2, 3] |>.run' 0 = Except.ok ()
```
We have to use parentheses and the error message is weird :(
```
(f [1, 2, 3] |>.run' 0) = Except.ok ()
```

2) I had to add comments to `macro.lean`, I didn't find a workaround
for one of the rules. BTW, I had to add a bunch of `:term` for fixing
the other rules, and the error messages were counterintuitive.
2021-03-23 18:35:27 -07:00

44 lines
1.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

abbrev Set (α : Type) := α → Prop
axiom setOf {α : Type} : (α → Prop) → Set α
axiom mem {α : Type} : α → Set α → Prop
axiom univ {α : Type} : Set α
axiom Union {α : Type} : Set (Set α) → Set α
syntax:100 term " ∈ " term:99 : term
macro_rules
| `($x:term ∈ $s:term) => `(mem $x:term $s:term)
declare_syntax_cat index
syntax term : index
syntax term "≤" ident "<" term : index
syntax ident ":" term : index
syntax "{" index " | " term "}" : term
macro_rules
-- | `({ $l:term ≤ $x:ident < $u:term | $p:term }) => `(setOf (fun $x:ident => $l:term ≤ $x:ident ∧ $x:ident < $u:term ∧ $p:term))
| `({ $x:ident : $t:term | $p:term }) => `(setOf (fun ($x:ident : $t:term) => $p:term))
| `({ $x:term ∈ $s:term | $p:term }) => `(setOf (fun $x:term => $x:term ∈ $s:term ∧ $p:term))
| `({ $x:term ≤ $e:term | $p:term }) => `(setOf (fun $x:term => $x:term ≤ $e:term ∧ $p:term))
| `({ $b:term | $r:term}) => `(setOf (fun $b:term => $r:term))
-- #check { 1 ≤ x < 10 | x ≠ 5 }
#check { f : Nat → Nat | f 1 > 0 }
syntax " " term ", " term : term
macro_rules
| `( $b:term, $r:term) => `(Union {$b:term | $r:term})
#check x, x = x
#check (x : Set Unit), x = x
#check x ∈ univ, x = x
syntax "#check2" term : command
macro_rules
| `(#check2 $e) => `(#check $e #check $e)
#check2 1