-
Notifications
You must be signed in to change notification settings - Fork 310
/
ScopedNS.lean
55 lines (49 loc) · 2.6 KB
/
ScopedNS.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/-
Copyright (c) 2021 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Mario Carneiro
-/
import Mathlib.Util.WithWeakNamespace
/-! # `scoped[NS]` syntax
This is a replacement for the `localized` command in mathlib. It is similar to `scoped`,
but it scopes the syntax in the specified namespace instead of the current namespace.
-/
namespace Mathlib.Tactic
open Lean
/--
`scoped[NS]` is similar to the `scoped` modifier on attributes and notations,
but it scopes the syntax in the specified namespace instead of the current namespace.
```
scoped[Matrix] infixl:75 " ⬝ " => Matrix.mul
-- declares `⬝` as a notation for matrix multiplication
-- which is only accessible if you `open Matrix` or `open scoped Matrix`.
namespace Nat
scoped[Nat.Count] attribute [instance] CountSet.fintype
-- make the definition Nat.CountSet.fintype an instance,
-- but only if `Nat.Count` is open
```
-/
syntax (name := scopedNS) (docComment)? (Parser.Term.attributes)?
"scoped" "[" ident "] " command : command
macro_rules
| `($[$doc]? $(attr)? scoped[$ns] notation $(prec)? $(n)? $(prio)? $sym* => $t) =>
`(with_weak_namespace $(mkIdentFrom ns <| rootNamespace ++ ns.getId)
$[$doc]? $(attr)? scoped notation $(prec)? $(n)? $(prio)? $sym* => $t)
| `($[$doc]? $(attr)? scoped[$ns] $mk:prefix $prec $(n)? $(prio)? $sym => $t) =>
`(with_weak_namespace $(mkIdentFrom ns <| rootNamespace ++ ns.getId)
$[$doc]? $(attr)? scoped $mk:prefix $prec $(n)? $(prio)? $sym => $t)
| `($[$doc]? $(attr)? scoped[$ns] $mk:infix $prec $(n)? $(prio)? $sym => $t) =>
`(with_weak_namespace $(mkIdentFrom ns <| rootNamespace ++ ns.getId)
$[$doc]? $(attr)? scoped $mk:infix $prec $(n)? $(prio)? $sym => $t)
| `($[$doc]? $(attr)? scoped[$ns] $mk:infixl $prec $(n)? $(prio)? $sym => $t) =>
`(with_weak_namespace $(mkIdentFrom ns <| rootNamespace ++ ns.getId)
$[$doc]? $(attr)? scoped $mk:infixl $prec $(n)? $(prio)? $sym => $t)
| `($[$doc]? $(attr)? scoped[$ns] $mk:infixr $prec $(n)? $(prio)? $sym => $t) =>
`(with_weak_namespace $(mkIdentFrom ns <| rootNamespace ++ ns.getId)
$[$doc]? $(attr)? scoped $mk:infixr $prec $(n)? $(prio)? $sym => $t)
| `($[$doc]? $(attr)? scoped[$ns] $mk:postfix $prec $(n)? $(prio)? $sym => $t) =>
`(with_weak_namespace $(mkIdentFrom ns <| rootNamespace ++ ns.getId)
$[$doc]? $(attr)? scoped $mk:postfix $prec $(n)? $(prio)? $sym => $t)
| `(scoped[$ns] attribute [$[$attr:attr],*] $ids*) =>
`(with_weak_namespace $(mkIdentFrom ns <| rootNamespace ++ ns.getId)
attribute [$[scoped $attr:attr],*] $ids*)