The areas / V01. The language of Mathlib
Mathlib.Lean.Name
11 declarations. Mathlib docs · Source
Additional functions on Lean.Name.
We provide allNames and allNamesByModule, as well as assorted utilities on Name
such as mapPrefix, fromComponents, splitAt and isPrefixOf?.
def allNames E1 #
(Lean.Name → Bool) → Lean.CoreM (Array Lean.Name)
Retrieve all names in the environment satisfying a predicate.
def allNamesByModule E1 #
(Lean.Name → Bool) → Lean.CoreM (Std.HashMap Lean.Name (Array Lean.Name))
Retrieve all names in the environment satisfying a predicate,
gathered together into a HashMap according to the module they are defined in.
def Lean.Name.willRoundTrip E1 #
Lean.Name → Bool
Determines if the pretty-printed version of the given name would parse as an
ident with an underlying name (via getId) equal to the original name.
The pretty-printer usually escapes unparsable components of a name with «»,
but makes exceptions for various names with special meaning, meaning that the result does not
round trip. We therefore re-check those conditions here.
This function is intended to be "safe" in that if it returns true,
the name will definitely round trip. (The converse is not guaranteed.) Any deviation from this
behavior is a bug which should be fixed.
def Lean.Name.isBlackListed E1 #
{m : Type → Type} → [Monad m] → [Lean.MonadEnv m] → Lean.Name → m Bool
def Lean.Name.decapitalize E1 #
Lean.Name → Lean.Name
Decapitalize the last component of a name.
def Lean.Name.mapPrefix E1 #
(Lean.Name → Option Lean.Name) → Lean.Name → Lean.Name
Find the largest prefix n of a Name such that f n != none, then replace this prefix
with the value of f n.
def Lean.Name.fromComponents E1 #
List Lean.Name → Lean.Name
Build a name from components.
For example, from_components [`foo, `bar] becomes `foo.bar.
It is the inverse of Name.components on list of names that have single components.
def Lean.Name.updateLast E1 #
(String → String) → Lean.Name → Lean.Name
Update the last component of a name.
def Lean.Name.lastComponentAsString E1 #
Lean.Name → String
Get the last field of a name as a string. Doesn't raise an error when the last component is a numeric field.
def Lean.Name.splitAt E1 #
Lean.Name → ℕ → Lean.Name × Lean.Name
nm.splitAt n splits a name nm in two parts, such that the second part has depth n,
i.e. (nm.splitAt n).2.getNumParts = n (assuming nm.getNumParts ≥ n).
Example: splitAt `foo.bar.baz.back.bat 1 = (`foo.bar.baz.back, `bat).
def Lean.Name.isPrefixOf? E1 #
Lean.Name → Lean.Name → Option Lean.Name
isPrefixOf? pre nm returns some post if nm = pre ++ post.
Note that this includes the case where nm has multiple more namespaces.
If pre is not a prefix of nm, it returns none.