Skip to content

Commit

Permalink
feat: default pp if pp expr/syntax/level without context
Browse files Browse the repository at this point in the history
  • Loading branch information
llllvvuu committed Jun 12, 2024
1 parent ea46bf2 commit 5109fef
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/Lean/Message.lean
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,31 @@ def mkPPContext (nCtx : NamingContext) (ctx : MessageDataContext) : PPContext :=
def ofSyntax (stx : Syntax) : MessageData :=
-- discard leading/trailing whitespace
let stx := stx.copyHeadTailInfoFrom .missing
.lazy fun ctx => ofFormat <$> ppTerm ctx ⟨stx⟩ -- HACK: might not be a term
.ofLazy
(fun ctx? => do
let msg ← ofFormat <$> match ctx? with
| .none => pure stx.formatStx
| .some ctx => ppTerm ctx ⟨stx⟩ -- HACK: might not be a term
return Dynamic.mk msg)
(fun _ => false)

def ofExpr (e : Expr) : MessageData :=
.lazy (fun ctx => ofFormatWithInfos <$> ppExprWithInfos ctx e)
(fun mctx => instantiateMVarsCore mctx e |>.1.hasSyntheticSorry)
.ofLazy
(fun ctx? => do
let msg ← ofFormatWithInfos <$> match ctx? with
| .none => pure (format (toString e))
| .some ctx => ppExprWithInfos ctx e
return Dynamic.mk msg)
(fun mctx => instantiateMVarsCore mctx e |>.1.hasSyntheticSorry)

def ofLevel (l : Level) : MessageData :=
.lazy fun ctx => ofFormat <$> ppLevel ctx l
.ofLazy
(fun ctx? => do
let msg ← ofFormat <$> match ctx? with
| .none => pure (format l)
| .some ctx => ppLevel ctx l
return Dynamic.mk msg)
(fun _ => false)

def ofName (n : Name) : MessageData := ofFormat (format n)

Expand Down

0 comments on commit 5109fef

Please sign in to comment.