|
| 1 | +/- |
| 2 | +Copyright (c) 2023 Kyle Miller. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Kyle Miller |
| 5 | +-/ |
| 6 | +import Lean.PrettyPrinter.Delaborator.Basic |
| 7 | + |
| 8 | +/-! |
| 9 | +# Additions to the delaborator |
| 10 | +-/ |
| 11 | + |
| 12 | +namespace Lean.PrettyPrinter.Delaborator |
| 13 | + |
| 14 | +open Lean.Meta Lean.SubExpr SubExpr |
| 15 | + |
| 16 | +namespace SubExpr |
| 17 | + |
| 18 | +variable {α : Type} [Inhabited α] |
| 19 | +variable {m : Type → Type} [Monad m] |
| 20 | + |
| 21 | +section Descend |
| 22 | + |
| 23 | +variable [MonadReaderOf SubExpr m] [MonadWithReaderOf SubExpr m] |
| 24 | +variable [MonadLiftT MetaM m] [MonadControlT MetaM m] |
| 25 | +variable [MonadLiftT IO m] |
| 26 | + |
| 27 | +/-- Assuming the current expression is a lambda or pi, |
| 28 | +descend into the body using the given name `n` for the username of the fvar. |
| 29 | +Provides `x` with the fresh fvar for the bound variable. |
| 30 | +See also `Lean.PrettyPrinter.Delaborator.SubExpr.withBindingBody`. -/ |
| 31 | +def withBindingBody' (n : Name) (x : Expr → m α) : m α := do |
| 32 | + let e ← getExpr |
| 33 | + Meta.withLocalDecl n e.binderInfo e.bindingDomain! fun fvar => |
| 34 | + descend (e.bindingBody!.instantiate1 fvar) 1 (x fvar) |
| 35 | + |
| 36 | +end Descend |
| 37 | + |
| 38 | +end SubExpr |
| 39 | + |
| 40 | +/-- Assuming the current expression in a lambda or pi, |
| 41 | +descend into the body using an unused name generated from the binder's name. |
| 42 | +Provides `d` with both `Syntax` for the bound name as an identifier |
| 43 | +as well as the fresh fvar for the bound variable. |
| 44 | +See also `Lean.PrettyPrinter.Delaborator.withBindingBodyUnusedName`. -/ |
| 45 | +def withBindingBodyUnusedName' {α} (d : Syntax → Expr → DelabM α) : DelabM α := do |
| 46 | + let n ← getUnusedName (← getExpr).bindingName! (← getExpr).bindingBody! |
| 47 | + let stxN ← annotateCurPos (mkIdent n) |
| 48 | + withBindingBody' n $ d stxN |
0 commit comments