Skip to content

Instantly share code, notes, and snippets.

@cppio
Created August 18, 2025 07:18
Show Gist options
  • Save cppio/44fc86752e41eccc0436184594d4d2ee to your computer and use it in GitHub Desktop.
Save cppio/44fc86752e41eccc0436184594d4d2ee to your computer and use it in GitHub Desktop.
import Lean.Elab.Term
deriving instance Lean.ToExpr for String.Pos
deriving instance Lean.ToExpr for Substring
deriving instance Lean.ToExpr for Lean.SourceInfo
deriving instance Lean.ToExpr for Lean.Syntax
syntax "log! " (interpolatedStr(term) <|> term:arg) : term
@[term_elab termLog!__]
def elabLog! : Lean.Elab.Term.TermElab
| `(log!%$tk $m:interpolatedStr), expectedType? => do
let tk ← Lean.Elab.Term.exprToSyntax (Lean.toExpr tk)
Lean.Elab.Term.elabTerm (← ``(Lean.logInfoAt $tk m!$m)) expectedType?
| `(log!%$tk $m:term), expectedType? => do
let tk ← Lean.Elab.Term.exprToSyntax (Lean.toExpr tk)
Lean.Elab.Term.elabTerm (← ``(Lean.logInfoAt $tk $m)) expectedType?
| _, _ => Lean.Elab.throwUnsupportedSyntax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment