Skip to content

Commit 06863f2

Browse files
authored
Merge pull request #675 from lean-ja/Seasawher/issue661
expand_tactic と expand_command を統一する
2 parents 918dfa5 + fd28e22 commit 06863f2

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

Examples/Command/Declarative/Infix.lean

+14-3
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,25 @@ open Lean
5151

5252
def lxor (l r : Bool) : Bool := !l && r
5353

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
5667
match ← Elab.liftMacroM <| Lean.Macro.expandMacro? t with
5768
| none => logInfo m!"Not a macro"
5869
| some t => logInfo m!"{t}"
5970

6071
/-- info: notation:50 lhs✝:51 " LXOR " rhs✝:51 => lxor lhs✝ rhs✝ -/
6172
#guard_msgs in
62-
#expand_command infix:50 " LXOR " => lxor
73+
#expand infix:50 " LXOR " => lxor
6374

6475
end Infix --#

Examples/Command/Declarative/Postfix.lean

+14-3
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,25 @@ scoped postfix:200 "!" => factorial
2222

2323
open Lean
2424

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
2738
match ← Elab.liftMacroM <| Lean.Macro.expandMacro? t with
2839
| none => logInfo m!"Not a macro"
2940
| some t => logInfo m!"{t}"
3041

3142
/-- info: notation:200 arg✝:200 "!" => factorial arg✝ -/
3243
#guard_msgs in
33-
#expand_command postfix:200 "!" => factorial
44+
#expand postfix:200 "!" => factorial
3445

3546
end Postfix --#

Examples/Command/Declarative/Prefix.lean

+14-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,25 @@ scoped prefix:90 "⋄" => Nat.succ
1818

1919
open Lean
2020

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
2334
match ← Elab.liftMacroM <| Lean.Macro.expandMacro? t with
2435
| none => logInfo m!"Not a macro"
2536
| some t => logInfo m!"{t}"
2637

2738
/-- info: notation:90 "⋄" arg✝:90 => Nat.succ arg✝ -/
2839
#guard_msgs in
29-
#expand_command prefix:90 "⋄" => Nat.succ
40+
#expand prefix:90 "⋄" => Nat.succ
3041

3142
end Prefix --#

Examples/Tactic/Exists.lean

+14-3
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,25 @@ example : ∃ x : Nat, 3 * x + 1 = 7 := by
3636

3737
open Lean
3838

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
4152
match ← Elab.liftMacroM <| Lean.Macro.expandMacro? t with
4253
| none => logInfo m!"Not a macro"
4354
| some t => logInfo m!"{t}"
4455

4556
/-- info: (refine ⟨1, 2, 3, ?_⟩; try trivial) -/
4657
#guard_msgs in
47-
#expand_tactic exists 1, 2, 3
58+
#expand exists 1, 2, 3
4859

4960
end Exists --#

0 commit comments

Comments
 (0)