Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand_tactic と expand_command を統一する #675

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Examples/Command/Declarative/Infix.lean
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,25 @@ open Lean

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

/-- コマンドをマクロ展開するコマンド -/
elab "#expand_command " t:command : command => do
/-- `#expand` の入力に渡すための構文カテゴリ -/
declare_syntax_cat macro_stx

-- コマンドとタクティクと項を扱える
syntax command : macro_stx
syntax tactic : macro_stx
syntax term : macro_stx

/-- マクロを展開するコマンド -/
elab "#expand " t:macro_stx : command => do
let t : Syntax := match t.raw with
| .node _ _ #[t] => t
| _ => t.raw
match ← Elab.liftMacroM <| Lean.Macro.expandMacro? t with
| none => logInfo m!"Not a macro"
| some t => logInfo m!"{t}"

/-- info: notation:50 lhs✝:51 " LXOR " rhs✝:51 => lxor lhs✝ rhs✝ -/
#guard_msgs in
#expand_command infix:50 " LXOR " => lxor
#expand infix:50 " LXOR " => lxor

end Infix --#
17 changes: 14 additions & 3 deletions Examples/Command/Declarative/Postfix.lean
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,25 @@ scoped postfix:200 "!" => factorial

open Lean

/-- コマンドをマクロ展開するコマンド -/
elab "#expand_command " t:command : command => do
/-- `#expand` の入力に渡すための構文カテゴリ -/
declare_syntax_cat macro_stx

-- コマンドとタクティクと項を扱える
syntax command : macro_stx
syntax tactic : macro_stx
syntax term : macro_stx

/-- マクロを展開するコマンド -/
elab "#expand " t:macro_stx : command => do
let t : Syntax := match t.raw with
| .node _ _ #[t] => t
| _ => t.raw
match ← Elab.liftMacroM <| Lean.Macro.expandMacro? t with
| none => logInfo m!"Not a macro"
| some t => logInfo m!"{t}"

/-- info: notation:200 arg✝:200 "!" => factorial arg✝ -/
#guard_msgs in
#expand_command postfix:200 "!" => factorial
#expand postfix:200 "!" => factorial

end Postfix --#
17 changes: 14 additions & 3 deletions Examples/Command/Declarative/Prefix.lean
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,25 @@ scoped prefix:90 "⋄" => Nat.succ

open Lean

/-- コマンドをマクロ展開するコマンド -/
elab "#expand_command " t:command : command => do
/-- `#expand` の入力に渡すための構文カテゴリ -/
declare_syntax_cat macro_stx

-- コマンドとタクティクと項を扱える
syntax command : macro_stx
syntax tactic : macro_stx
syntax term : macro_stx

/-- マクロを展開するコマンド -/
elab "#expand " t:macro_stx : command => do
let t : Syntax := match t.raw with
| .node _ _ #[t] => t
| _ => t.raw
match ← Elab.liftMacroM <| Lean.Macro.expandMacro? t with
| none => logInfo m!"Not a macro"
| some t => logInfo m!"{t}"

/-- info: notation:90 "⋄" arg✝:90 => Nat.succ arg✝ -/
#guard_msgs in
#expand_command prefix:90 "⋄" => Nat.succ
#expand prefix:90 "⋄" => Nat.succ

end Prefix --#
17 changes: 14 additions & 3 deletions Examples/Tactic/Exists.lean
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,25 @@ example : ∃ x : Nat, 3 * x + 1 = 7 := by

open Lean

-- タクティクのマクロ展開を調べるためのコマンド
elab "#expand_tactic " t:tactic : command => do
/-- `#expand` の入力に渡すための構文カテゴリ -/
declare_syntax_cat macro_stx

-- コマンドとタクティクと項を扱える
syntax command : macro_stx
syntax tactic : macro_stx
syntax term : macro_stx

/-- マクロを展開するコマンド -/
elab "#expand " t:macro_stx : command => do
let t : Syntax := match t.raw with
| .node _ _ #[t] => t
| _ => t.raw
match ← Elab.liftMacroM <| Lean.Macro.expandMacro? t with
| none => logInfo m!"Not a macro"
| some t => logInfo m!"{t}"

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

end Exists --#
Loading