@@ -198,26 +198,25 @@ scoped[Topology] notation (name := Continuous_of) "Continuous[" t₁ ", " t₂ "
198198namespace TopologicalSpace
199199open Topology Lean Meta PrettyPrinter.Delaborator SubExpr
200200
201+ /-- Fails iff argument #`space` has a `TopologicalSpace` instance registered and that instance is defeq to argument #`inst`. -/
202+ def assertNonCanonical (space inst : ℕ) : DelabM Unit := do
203+ let α ← withNaryArg space getExpr
204+ let .some synthInst ← Meta.trySynthInstance (← Meta.mkAppM ``TopologicalSpace #[α]) | return ()
205+ let inst ← withNaryArg inst getExpr
206+ if ← Meta.isDefEq inst synthInst then failure
207+
201208/-- Delaborate unary notation referring to non-standard topologies. -/
202209def delabUnary (mkStx : Term → DelabM Term) : Delab :=
203210 withOverApp 2 <| whenPPOption Lean.getPPNotation do
204- let α ← withNaryArg 0 getExpr
205- let .some synthInst ← Meta.trySynthInstance (← Meta.mkAppM ``TopologicalSpace #[α]) | failure
206- let inst ← withNaryArg 1 getExpr
207- if ← Meta.isDefEq inst synthInst then failure
211+ assertNonCanonical 0 1 -- fall through to normal delab if canonical
208212 let instD ← withNaryArg 1 delab
209213 mkStx instD
210214
211215/-- Delaborate binary notation referring to non-standard topologies. -/
212216def delabBinary (mkStx : Term → Term → DelabM Term) : Delab :=
213217 withOverApp 4 <| whenPPOption Lean.getPPNotation do
214- let α ← withNaryArg 0 getExpr
215- let β ← withNaryArg 1 getExpr
216- let .some synthInstα ← Meta.trySynthInstance (← Meta.mkAppM ``TopologicalSpace #[α]) | failure
217- let .some synthInstβ ← Meta.trySynthInstance (← Meta.mkAppM ``TopologicalSpace #[β]) | failure
218- let instα ← withNaryArg 2 getExpr
219- let instβ ← withNaryArg 3 getExpr
220- if (← Meta.isDefEq instα synthInstα) ∧ (← Meta.isDefEq instβ synthInstβ) then failure
218+ -- fall through to normal delab if both canonical
219+ assertNonCanonical 0 2 <|> assertNonCanonical 1 3
221220 let instDα ← withNaryArg 2 delab
222221 let instDβ ← withNaryArg 3 delab
223222 mkStx instDα instDβ
0 commit comments