diff --git a/src/Lean/Elab/Quotation.lean b/src/Lean/Elab/Quotation.lean index 12a0b14482..0c17d5221b 100644 --- a/src/Lean/Elab/Quotation.lean +++ b/src/Lean/Elab/Quotation.lean @@ -18,11 +18,6 @@ open Lean.Parser.Term open Lean.Syntax open Meta -register_builtin_option hygiene : Bool := { - defValue := true - descr := "Annotate identifiers in quotations such that they are resolved relative to the scope at their declaration, not that at their eventual use/expansion, to avoid accidental capturing. Note that quotations/notations already defined are unaffected." -} - /-- `C[$(e)]` ~> `let a := e; C[$a]`. Used in the implementation of antiquot splices. -/ private partial def floatOutAntiquotTerms : Syntax → StateT (Syntax → TermElabM Syntax) TermElabM Syntax | stx@(Syntax.node k args) => do diff --git a/src/Lean/Elab/Quotation/Precheck.lean b/src/Lean/Elab/Quotation/Precheck.lean index 5f13b96d7d..a43b774b62 100644 --- a/src/Lean/Elab/Quotation/Precheck.lean +++ b/src/Lean/Elab/Quotation/Precheck.lean @@ -55,8 +55,9 @@ where return true return false -def runPrecheck (stx : Syntax) : TermElabM Unit := - precheck stx |>.run { quotLCtx := {} } +def runPrecheck (stx : Syntax) : TermElabM Unit := do + if hygiene.get (← getOptions) then + precheck stx |>.run { quotLCtx := {} } @[builtinQuotPrecheck ident] def precheckIdent : Precheck | Syntax.ident info rawVal val preresolved => do diff --git a/src/Lean/Elab/Quotation/Util.lean b/src/Lean/Elab/Quotation/Util.lean index 341bbbd865..684a6004e1 100644 --- a/src/Lean/Elab/Quotation/Util.lean +++ b/src/Lean/Elab/Quotation/Util.lean @@ -8,6 +8,11 @@ import Lean.Elab.Term namespace Lean.Elab.Term.Quotation open Lean.Syntax +register_builtin_option hygiene : Bool := { + defValue := true + descr := "Annotate identifiers in quotations such that they are resolved relative to the scope at their declaration, not that at their eventual use/expansion, to avoid accidental capturing. Note that quotations/notations already defined are unaffected." +} + partial def getAntiquotationIds (stx : Syntax) : TermElabM (Array Syntax) := do let mut ids := #[] for stx in stx.topDown do