File tree 4 files changed +56
-12
lines changed
4 files changed +56
-12
lines changed Original file line number Diff line number Diff line change @@ -51,14 +51,25 @@ open Lean
51
51
52
52
def lxor (l r : Bool) : Bool := !l && r
53
53
54
- /-- コマンドをマクロ展開するコマンド -/
55
- elab "#expand_command " t:command : command => do
54
+ /-- `#expand` の入力に渡すための構文カテゴリ -/
55
+ declare_syntax_cat macro_stx
56
+
57
+ -- コマンドとタクティクと項を扱える
58
+ syntax command : macro_stx
59
+ syntax tactic : macro_stx
60
+ syntax term : macro_stx
61
+
62
+ /-- マクロを展開するコマンド -/
63
+ elab "#expand " t:macro_stx : command => do
64
+ let t : Syntax := match t.raw with
65
+ | .node _ _ #[t] => t
66
+ | _ => t.raw
56
67
match ← Elab.liftMacroM <| Lean.Macro.expandMacro? t with
57
68
| none => logInfo m!"Not a macro"
58
69
| some t => logInfo m!"{t}"
59
70
60
71
/-- info: notation:50 lhs✝:51 " LXOR " rhs✝:51 => lxor lhs✝ rhs✝ -/
61
72
#guard_msgs in
62
- #expand_command infix :50 " LXOR " => lxor
73
+ #expand infix :50 " LXOR " => lxor
63
74
64
75
end Infix --#
Original file line number Diff line number Diff line change @@ -22,14 +22,25 @@ scoped postfix:200 "!" => factorial
22
22
23
23
open Lean
24
24
25
- /-- コマンドをマクロ展開するコマンド -/
26
- elab "#expand_command " t:command : command => do
25
+ /-- `#expand` の入力に渡すための構文カテゴリ -/
26
+ declare_syntax_cat macro_stx
27
+
28
+ -- コマンドとタクティクと項を扱える
29
+ syntax command : macro_stx
30
+ syntax tactic : macro_stx
31
+ syntax term : macro_stx
32
+
33
+ /-- マクロを展開するコマンド -/
34
+ elab "#expand " t:macro_stx : command => do
35
+ let t : Syntax := match t.raw with
36
+ | .node _ _ #[t] => t
37
+ | _ => t.raw
27
38
match ← Elab.liftMacroM <| Lean.Macro.expandMacro? t with
28
39
| none => logInfo m!"Not a macro"
29
40
| some t => logInfo m!"{t}"
30
41
31
42
/-- info: notation:200 arg✝:200 "!" => factorial arg✝ -/
32
43
#guard_msgs in
33
- #expand_command postfix :200 "!" => factorial
44
+ #expand postfix :200 "!" => factorial
34
45
35
46
end Postfix --#
Original file line number Diff line number Diff line change @@ -18,14 +18,25 @@ scoped prefix:90 "⋄" => Nat.succ
18
18
19
19
open Lean
20
20
21
- /-- コマンドをマクロ展開するコマンド -/
22
- elab "#expand_command " t:command : command => do
21
+ /-- `#expand` の入力に渡すための構文カテゴリ -/
22
+ declare_syntax_cat macro_stx
23
+
24
+ -- コマンドとタクティクと項を扱える
25
+ syntax command : macro_stx
26
+ syntax tactic : macro_stx
27
+ syntax term : macro_stx
28
+
29
+ /-- マクロを展開するコマンド -/
30
+ elab "#expand " t:macro_stx : command => do
31
+ let t : Syntax := match t.raw with
32
+ | .node _ _ #[t] => t
33
+ | _ => t.raw
23
34
match ← Elab.liftMacroM <| Lean.Macro.expandMacro? t with
24
35
| none => logInfo m!"Not a macro"
25
36
| some t => logInfo m!"{t}"
26
37
27
38
/-- info: notation:90 "⋄" arg✝:90 => Nat.succ arg✝ -/
28
39
#guard_msgs in
29
- #expand_command prefix :90 "⋄" => Nat.succ
40
+ #expand prefix :90 "⋄" => Nat.succ
30
41
31
42
end Prefix --#
Original file line number Diff line number Diff line change @@ -36,14 +36,25 @@ example : ∃ x : Nat, 3 * x + 1 = 7 := by
36
36
37
37
open Lean
38
38
39
- -- タクティクのマクロ展開を調べるためのコマンド
40
- elab "#expand_tactic " t:tactic : command => do
39
+ /-- `#expand` の入力に渡すための構文カテゴリ -/
40
+ declare_syntax_cat macro_stx
41
+
42
+ -- コマンドとタクティクと項を扱える
43
+ syntax command : macro_stx
44
+ syntax tactic : macro_stx
45
+ syntax term : macro_stx
46
+
47
+ /-- マクロを展開するコマンド -/
48
+ elab "#expand " t:macro_stx : command => do
49
+ let t : Syntax := match t.raw with
50
+ | .node _ _ #[t] => t
51
+ | _ => t.raw
41
52
match ← Elab.liftMacroM <| Lean.Macro.expandMacro? t with
42
53
| none => logInfo m!"Not a macro"
43
54
| some t => logInfo m!"{t}"
44
55
45
56
/-- info: (refine ⟨1, 2, 3, ?_⟩; try trivial) -/
46
57
#guard_msgs in
47
- #expand_tactic exists 1 , 2 , 3
58
+ #expand exists 1 , 2 , 3
48
59
49
60
end Exists --#
You can’t perform that action at this time.
0 commit comments