-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improved
export
command and namespace aliases
This PR gives the `export` command the ability to create aliases to namespaces, in addition to its current ability to create aliases to individual declarations. It adds a number of `open`-like variations to the syntax. * `export NS1 ... NSn` makes the current namespace be an alias for the provided namespaces. * `export NS (def1 ... defn)` has the same meaning as before, but if any `NS.defi` is a namespace then the alias also serves as a namespace alias. For example, if one were to do ```lean namespace MyNS export _root_ (Nat) end MyNS ``` then not only is `MyNS.Nat` available as an alias for `Nat`, but additionally `MyNS.Nat.succ` is now an alias for `Nat.succ`. * `export NS hiding def1 ... defn` is like `export NS`, but the given names in `NS` do not get aliases. * `export NS renaming def1 -> def1', ..., defn -> defn'` creates aliases for the given names `def1` through `defn`, but the aliases respectively use the names `def1'` through `defn'`.
- Loading branch information
Showing
8 changed files
with
489 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/- | ||
Copyright (c) 2024 Lean FRO, LLC. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Kyle Miller | ||
-/ | ||
prelude | ||
import Init.Meta | ||
|
||
namespace Lean | ||
|
||
/-- | ||
Data for representing `export` commands. | ||
-/ | ||
inductive ExportDecl where | ||
/-- The name `aDeclName` is an alias for the declaration `declName`. -/ | ||
| explicit (aDeclName : Name) (declName : Name) | ||
/-- The namespace `ans` is an alias for the namespace `ns`, | ||
except, if `e` is in `except`, `ans ++ e` is not an alias for `ns ++ e`. | ||
Alias resolution is recursive. `ns` must be a registered namespace. -/ | ||
| namespace (ans ns : Name) (except : List Name) | ||
deriving BEq | ||
|
||
namespace ExportDecl | ||
|
||
instance : ToString ExportDecl := ⟨fun decl => | ||
match decl with | ||
| .explicit adecl decl => toString adecl ++ " → " ++ toString decl | ||
| .namespace ans ns ex => toString ans ++ ".* → " ++ toString ns ++ ".*" ++ (if ex == [] then "" else " hiding " ++ toString ex)⟩ | ||
|
||
end ExportDecl | ||
|
||
end Lean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.