statement
stringlengths
1
2.93k
proof
stringlengths
0
19.2k
type
stringclasses
13 values
symbolic_name
stringlengths
1
131
library
stringlengths
4
62
filename
stringlengths
20
95
imports
listlengths
0
10
deps
listlengths
0
64
docstring
stringlengths
0
4.95k
source_url
stringclasses
1 value
commit
stringclasses
1 value
elabTermWithoutNewMVars (tactic : Name) (t : Term) : TacticM Expr
Term.withoutErrToSorry do let (e, mvars) ← elabTermWithHoles t none tactic unless mvars.isEmpty do throwErrorAt t "Argument passed to {tactic} has metavariables:{indentD e}" return e
def
elabTermWithoutNewMVars
Util
Mathlib/Util/ElabWithoutMVars.lean
[]
[]
Elaborates a term with `errToSorry = false` and ensuring it has no metavariables.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
MethodsRefPointed : NonemptyType.{0}
opaque
Lean.Export.MethodsRefPointed
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
MethodsRef : Type
MethodsRefPointed.type
def
Lean.Export.MethodsRef
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
Entry | name (n : Name) | level (n : Level) | expr (n : Expr) | defn (n : Name) deriving Inhabited
inductive
Lean.Export.Entry
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
Alloc (α) [BEq α] [Hashable α] where map : Std.HashMap α Nat next : Nat deriving Inhabited
structure
Lean.Export.Alloc
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
State where names : Alloc Name
⟨(∅ : Std.HashMap Name Nat).insert Name.anonymous 0, 1⟩ levels : Alloc Level := ⟨(∅ : Std.HashMap Level Nat).insert .zero 0, 1⟩ exprs : Alloc Expr defs : Std.HashSet Name stk : Array (Bool × Entry) deriving Inhabited
structure
Lean.Export.State
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
OfState (α : Type) [BEq α] [Hashable α] where get : State → Alloc α modify : (Alloc α → Alloc α) → State → State
class
Lean.Export.OfState
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
ExportM
StateT Export.State CoreM
abbrev
Lean.ExportM
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
alloc {α} [BEq α] [Hashable α] [OfState α] (a : α) : ExportM Nat
do let n := (OfState.get (α := α) (← get)).next modify <| OfState.modify (α := α) fun s ↦ {map := s.map.insert a n, next := n + 1} pure n
def
Lean.Export.alloc
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
exportName (n : Name) : ExportM Nat
do match (← get).names.map[n]? with | some i => pure i | none => match n with | .anonymous => pure 0 | .num p a => let i ← alloc n; IO.println s!"{i} #NI {← exportName p} {a}"; pure i | .str p s => let i ← alloc n; IO.println s!"{i} #NS {← exportName p} {s}"; pure i
def
Lean.Export.exportName
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
exportLevel (L : Level) : ExportM Nat
do match (← get).levels.map[L]? with | some i => pure i | none => match L with | .zero => pure 0 | .succ l => let i ← alloc L; IO.println s!"{i} #US {← exportLevel l}"; pure i | .max l₁ l₂ => let i ← alloc L; IO.println s!"{i} #UM {← exportLevel l₁} {← exportLevel l₂}"; pure i | .imax ...
def
Lean.Export.exportLevel
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
biStr : BinderInfo → String
| BinderInfo.default => "#BD" | BinderInfo.implicit => "#BI" | BinderInfo.strictImplicit => "#BS" | BinderInfo.instImplicit => "#BC"
def
Lean.Export.biStr
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
exportExpr (E : Expr) : ExportM Nat
do match (← get).exprs.map[E]? with | some i => pure i | none => match E with | .bvar n => let i ← alloc E; IO.println s!"{i} #EV {n}"; pure i | .fvar _ => unreachable! | .mvar _ => unreachable! | .sort l => let i ← alloc E; IO.println s!"{i} #ES {← exportLevel l}"; pure i | .const n ls => ...
def
Lean.Export.exportExpr
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
exportDef (n : Name) : ExportM Unit
do if (← get).defs.contains n then return let ci ← getConstInfo n for c in ci.value!.getUsedConstants do unless (← get).defs.contains c do exportDef c match ci with | axiomInfo val => axdef "#AX" val.name val.type val.levelParams | defnInfo val => defn "#DEF" val.name val.type val.value val.l...
def
Lean.Export.exportDef
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
runExportM {α : Type} (m : ExportM α) : CoreM α
m.run' default
def
Lean.Export.runExportM
Util
Mathlib/Util/Export.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
Alignment where | left | right | center deriving Inhabited, BEq
inductive
Alignment
Util
Mathlib/Util/FormatTable.lean
[]
[]
Possible alignment modes for each table item: left-aligned, right-aligned and centered.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
String.justify (s : String) (a : Alignment) (width : Nat) : String
match a with | Alignment.left => s.rightpad width | Alignment.right => s.leftpad width | Alignment.center => let pad := (width - s.length) / 2 String.replicate pad ' ' ++ s ++ String.replicate (width - s.length - pad) ' '
def
String.justify
Util
Mathlib/Util/FormatTable.lean
[]
[ "Alignment", "String.replicate" ]
Align a `String` `s` to the left, right, or center within a field of width `width`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
formatTable (headers : Array String) (table : Array (Array String)) (alignments : Option (Array Alignment) := none) : String
Id.run do -- If no alignments are provided, default to left alignment for all columns. let alignments := alignments.getD (Array.replicate headers.size Alignment.left) -- Escape all vertical bar characters inside a table cell, -- otherwise these could get interpreted as starting a new row or column. let escape...
def
formatTable
Util
Mathlib/Util/FormatTable.lean
[]
[ "Alignment", "String.replicate" ]
Render a two-dimensional array of `String`s into a markdown-compliant table. `headers` is a list of column headers, `table` is a 2D array of cell contents, `alignments` describes how to align each table column (default: left-aligned).
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
getAllFiles (git : Bool) (ml : String) : IO (Array System.FilePath)
do let ml.lean := addExtension ⟨ml⟩ "lean" -- for example, `Mathlib.lean` let allModules : Array System.FilePath ← (do if git then let mlDir := ml.push pathSeparator -- for example, `Mathlib/` let allLean ← IO.Process.run { cmd := "git", args := #["ls-files", mlDir ++ "*.lean"] } return (((...
def
getAllFiles
Util
Mathlib/Util/GetAllModules.lean
[]
[]
`getAllFiles git ml` takes all `.lean` files in the directory `ml` (recursing into sub-directories) and returns the `Array` of `String`s ``` #[file₁, ..., fileₙ] ``` of all their file names. These are not sorted in general. The input `git` is a `Bool`ean flag: * `true` means that the command uses `git ls-files` to fin...
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
getAllModulesSorted (git : Bool) (ml : String) : IO (Array String)
do let files ← getAllFiles git ml let names := ← files.mapM fun f => do return (← moduleNameOfFileName f none).toString return names.qsort (· < ·)
def
getAllModulesSorted
Util
Mathlib/Util/GetAllModules.lean
[]
[ "getAllFiles" ]
Like `getAllFiles`, but return an array of *module* names instead, i.e. names of the form `Mathlib/Algebra/Algebra/Basic.lean`. In addition, these names are sorted in a platform-independent order.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
printNameHashMap (h : Std.HashMap Name (Array Name)) : IO Unit
for (m, names) in h.toList do IO.println "----" IO.println <| m.toString ++ ":" for n in names do IO.println n
def
printNameHashMap
Util
Mathlib/Util/LongNames.lean
[]
[]
Helper function for `#long_names` and `#long_instances`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
"#long_names " N:(num)? : command => Command.runTermElabM fun _ => do let N
N.map TSyntax.getNat |>.getD 50 let namesByModule ← allNamesByModule (fun n => n.toString.length > N) let namesByModule := namesByModule.filter fun m _ => m.getRoot.toString = "Mathlib" printNameHashMap namesByModule
elab
#long_names
Util
Mathlib/Util/LongNames.lean
[]
[ "allNamesByModule", "printNameHashMap" ]
Lists all declarations with a long name, gathered according to the module they are defined in. Use as `#long_names` or `#long_names 100` to specify the length.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
"#long_instances " N:(num)?: command => Command.runTermElabM fun _ => do let N
N.map TSyntax.getNat |>.getD 50 let namesByModule ← allNamesByModule (fun n => n.lastComponentAsString.startsWith "inst" && n.lastComponentAsString.length > N) let namesByModule := namesByModule.filter fun m _ => m.getRoot.toString = "Mathlib" printNameHashMap namesByModule
elab
#long_instances
Util
Mathlib/Util/LongNames.lean
[]
[ "allNamesByModule", "printNameHashMap" ]
Lists all instances with a long name beginning with `inst`, gathered according to the module they are defined in. This is useful for finding automatically named instances with absurd names. Use as `#long_names` or `#long_names 100` to specify the length.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
injectIntoBaseIO {α : Type} (a : α) : BaseIO α
pure a
def
injectIntoBaseIO
Util
Mathlib/Util/MemoFix.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
memoFixImpl [Nonempty β] (f : (α → β) → (α → β)) : α → β
unsafeBaseIO do let cache : IO.Ref (Lean.PtrMap α β) ← ST.mkRef Lean.mkPtrMap let rec fix (a) : β := unsafeBaseIO do if let some b := (← cache.get).find? a then return b let b ← injectIntoBaseIO (f fix a) cache.modify (·.insert a b) return b return fix /-- Takes the fixpoint of `f` with cac...
def
memoFixImpl
Util
Mathlib/Util/MemoFix.lean
[]
[ "injectIntoBaseIO" ]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
(name := expandFoldl) "expand_foldl% " "(" x:ident ppSpace y:ident " => " term:term ") " init:term:max " [" args:term,* "]" : term => args.getElems.foldlM (init := init) fun res arg ↦ do term.replaceM fun e ↦ return if e == x then some res else if e == y then some arg else none
macro
expand_foldl%
Util
Mathlib/Util/Notation3.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
(name := expandFoldr) "expand_foldr% " "(" x:ident ppSpace y:ident " => " term:term ") " init:term:max " [" args:term,* "]" : term => args.getElems.foldrM (init := init) fun arg res ↦ do term.replaceM fun e ↦ return if e == x then some arg else if e == y then some res else none
macro
expand_foldr%
Util
Mathlib/Util/Notation3.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
MatchState where /-- This stores the assignments of variables to subexpressions (and their contexts) that have been found so far during the course of the matching algorithm. We store the contexts since we need to delaborate expressions after we leave scoping constructs. -/ vars : Std.HashMap Name (SubExpr × L...
structure
Mathlib.Notation3.MatchState
Util
Mathlib/Util/Notation3.lean
[]
[]
The dynamic state of a `Matcher`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
Matcher
MatchState → DelabM MatchState deriving Inhabited
def
Mathlib.Notation3.Matcher
Util
Mathlib/Util/Notation3.lean
[]
[]
A matcher is a delaboration function that transforms `MatchState`s.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
MatchState.empty : MatchState
where vars := {} scopeState := none foldState := {}
def
Mathlib.Notation3.MatchState.empty
Util
Mathlib/Util/Notation3.lean
[]
[]
The initial state.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
MatchState.withVar {α : Type} (s : MatchState) (name : Name) (m : DelabM α) : DelabM α
do let some (se, lctx, linsts) := s.vars[name]? | failure withLCtx lctx linsts <| withTheReader SubExpr (fun _ => se) <| m
def
Mathlib.Notation3.MatchState.withVar
Util
Mathlib/Util/Notation3.lean
[]
[]
Evaluate `f` with the given variable's value as the `SubExpr` and within that subexpression's saved context. Fails if the variable has no value.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
MatchState.delabVar (s : MatchState) (name : Name) (checkNot? : Option Expr := none) : DelabM Term
s.withVar name do if let some checkNot := checkNot? then guard <| checkNot != (← getExpr) delab
def
Mathlib.Notation3.MatchState.delabVar
Util
Mathlib/Util/Notation3.lean
[]
[]
Delaborate the given variable's value. Fails if the variable has no value. If `checkNot` is provided, then checks that the expression being delaborated is not the given one (this is used to prevent infinite loops).
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
MatchState.captureSubexpr (s : MatchState) (name : Name) : DelabM MatchState
do return {s with vars := s.vars.insert name (← readThe SubExpr, ← getLCtx, ← getLocalInstances)}
def
Mathlib.Notation3.MatchState.captureSubexpr
Util
Mathlib/Util/Notation3.lean
[]
[]
Assign a variable to the current `SubExpr`, capturing the local context.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
MatchState.getFoldArray (s : MatchState) (name : Name) : Array Term
s.foldState[name]?.getD #[]
def
Mathlib.Notation3.MatchState.getFoldArray
Util
Mathlib/Util/Notation3.lean
[]
[]
Get the accumulated array of delaborated terms for a given foldr/foldl. Returns `#[]` if nothing has been pushed yet.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
MatchState.getBinders (s : MatchState) : Array (TSyntax ``extBinderParenthesized)
s.scopeState.getD #[]
def
Mathlib.Notation3.MatchState.getBinders
Util
Mathlib/Util/Notation3.lean
[]
[]
Get the accumulated array of delaborated terms for a given foldr/foldl. Returns `#[]` if nothing has been pushed yet.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
MatchState.pushFold (s : MatchState) (name : Name) (t : Term) : MatchState
let ts := (s.getFoldArray name).push t {s with foldState := s.foldState.insert name ts}
def
Mathlib.Notation3.MatchState.pushFold
Util
Mathlib/Util/Notation3.lean
[]
[]
Push a delaborated term onto a foldr/foldl array.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
matchVar (c : Name) : Matcher
fun s => do if let some (se, _, _) := s.vars[c]? then guard <| se.expr == (← getExpr) return s else s.captureSubexpr c
def
Mathlib.Notation3.matchVar
Util
Mathlib/Util/Notation3.lean
[]
[]
Matcher that assigns the current `SubExpr` into the match state; if a value already exists, then it checks for equality.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
matchExpr (p : Expr → Bool) : Matcher
fun s => do guard <| p (← getExpr) return s
def
Mathlib.Notation3.matchExpr
Util
Mathlib/Util/Notation3.lean
[]
[]
Matcher for an expression satisfying a given predicate.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
matchFVar (userName : Name) (matchTy : Matcher) : Matcher
fun s => do let .fvar fvarId ← getExpr | failure guard <| userName == (← fvarId.getUserName) withType (matchTy s)
def
Mathlib.Notation3.matchFVar
Util
Mathlib/Util/Notation3.lean
[]
[]
Matcher for `Expr.fvar`. It checks that the user name agrees and that the type of the expression is matched by `matchTy`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
matchTypeOf (matchTy : Matcher) : Matcher
fun s => do withType (matchTy s)
def
Mathlib.Notation3.matchTypeOf
Util
Mathlib/Util/Notation3.lean
[]
[]
Matcher that checks that the type of the expression is matched by `matchTy`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
natLitMatcher (n : Nat) : Matcher
fun s => do guard <| (← getExpr).rawNatLit? == n return s
def
Mathlib.Notation3.natLitMatcher
Util
Mathlib/Util/Notation3.lean
[]
[]
Matches raw `Nat` literals.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
matchApp (matchFun matchArg : Matcher) : Matcher
fun s => do guard <| (← getExpr).isApp let s ← withAppFn <| matchFun s let s ← withAppArg <| matchArg s return s
def
Mathlib.Notation3.matchApp
Util
Mathlib/Util/Notation3.lean
[]
[]
Matches applications.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
matchForall (matchDom : Matcher) (matchBody : Expr → Matcher) : Matcher
fun s => do guard <| (← getExpr).isForall let s ← withBindingDomain <| matchDom s let s ← withBindingBodyUnusedName' fun _ arg => matchBody arg s return s
def
Mathlib.Notation3.matchForall
Util
Mathlib/Util/Notation3.lean
[]
[]
Matches pi types. The name `n` should be unique, and `matchBody` should use `n` as the `userName` of its fvar.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
matchLambda (matchDom : Matcher) (matchBody : Expr → Matcher) : Matcher
fun s => do guard <| (← getExpr).isLambda let s ← withBindingDomain <| matchDom s let s ← withBindingBodyUnusedName' fun _ arg => matchBody arg s return s
def
Mathlib.Notation3.matchLambda
Util
Mathlib/Util/Notation3.lean
[]
[]
Matches lambdas. The `matchBody` takes the fvar introduced when visiting the body.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
setupLCtx (lctx : LocalContext) (boundNames : Array Name) : MetaM (LocalContext × Std.HashMap FVarId Name)
do let mut lctx := lctx let mut boundFVars := {} for name in boundNames do let fvarId ← mkFreshFVarId lctx := lctx.mkLocalDecl fvarId name (← withLCtx lctx (← getLocalInstances) mkFreshTypeMVar) boundFVars := boundFVars.insert fvarId name return (lctx, boundFVars)
def
Mathlib.Notation3.setupLCtx
Util
Mathlib/Util/Notation3.lean
[]
[]
Adds all the names in `boundNames` to the local context with types that are fresh metavariables. This is used for example when initializing `p` in `(scoped p => ...)` when elaborating `...`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
isType' : Expr → Bool
| .sort u => u.dec.isSome | _ => false
def
Mathlib.Notation3.isType'
Util
Mathlib/Util/Notation3.lean
[]
[]
Like `Expr.isType`, but uses logic that normalizes the universe level. Mirrors the core `Sort` delaborator logic.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
DelabKey where /-- The key `app.const` or `app` with a specific arity. -/ | app (const : Option Name) (arity : Nat) | other (key : Name) deriving Repr
inductive
Mathlib.Notation3.DelabKey
Util
Mathlib/Util/Notation3.lean
[]
[]
Represents a key to use when registering the `delab` attribute for a delaborator. We use this to handle overapplication.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
DelabKey.key : DelabKey → Name
| .app none _ => `app | .app (some n) _ => `app ++ n | .other key => key
def
Mathlib.Notation3.DelabKey.key
Util
Mathlib/Util/Notation3.lean
[]
[]
Turns the `DelabKey` into a key that the `delab` attribute accepts.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
exprToMatcher (boundFVars : Std.HashMap FVarId Name) (localFVars : Std.HashMap FVarId Term) (e : Expr) : OptionT TermElabM (List DelabKey × Term)
do match e with | .mvar .. => return ([], ← `(pure)) | .const n _ => return ([.app n 0], ← ``(matchExpr (Expr.isConstOf · $(quote n)))) | .sort u => /- We should try being more accurate here. Prop / Type / Type _ / Sort _ is at least an OK approximation. We mimic the core Sort delaborator `Lean....
def
Mathlib.Notation3.exprToMatcher
Util
Mathlib/Util/Notation3.lean
[]
[]
Given an expression, generate a matcher for it. The `boundFVars` hash map records which state variables certain fvars correspond to. The `localFVars` hash map records which local variable the matcher should use for an exact expression match. If it succeeds generating a matcher, returns 1. a list of keys that should be...
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
mkExprMatcher (stx : Term) (boundNames : Array Name) : OptionT TermElabM (List DelabKey × Term)
do let (lctx, boundFVars) ← setupLCtx (← getLCtx) boundNames withLCtx lctx (← getLocalInstances) do let patt ← try Term.elabPattern stx none catch e => logException e trace[notation3] "Could not elaborate pattern{indentD stx}\nError: {e.toMessageData}" -- Convert the ...
def
Mathlib.Notation3.mkExprMatcher
Util
Mathlib/Util/Notation3.lean
[]
[]
Returns a `Term` that represents a `Matcher` for the given pattern `stx`. The `boundNames` set determines which identifiers are variables in the pattern. Fails in the `OptionT` sense if it comes across something it's unable to handle. Also returns constant names that could serve as a key for a delaborator. For example...
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
matchScoped (lit scopeId : Name) (smatcher : Matcher) : Matcher
go #[] where /-- Variant of `matchScoped` after some number of `binders` have already been captured. -/ go (binders : Array (TSyntax ``extBinderParenthesized)) : Matcher := fun s => do -- `lit` is bound to the SubExpr that the `scoped` syntax produced s.withVar lit do try -- Run `smatcher` at `lit...
def
Mathlib.Notation3.matchScoped
Util
Mathlib/Util/Notation3.lean
[]
[]
Matcher for processing `scoped` syntax. Assumes the expression to be matched against is in the `lit` variable. Runs `smatcher`, extracts the resulting `scopeId` variable, processes this value (which must be a lambda) to produce a binder, and loops.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
mkScopedMatcher (lit scopeId : Name) (scopedTerm : Term) (boundNames : Array Name) : OptionT TermElabM (List DelabKey × Term)
do -- Build the matcher for `scopedTerm` with `scopeId` as an additional variable let (keys, smatcher) ← mkExprMatcher scopedTerm (boundNames.push scopeId) return (keys, ← ``(matchScoped $(quote lit) $(quote scopeId) $smatcher))
def
Mathlib.Notation3.mkScopedMatcher
Util
Mathlib/Util/Notation3.lean
[]
[]
Create a `Term` that represents a matcher for `scoped` notation. Fails in the `OptionT` sense if a matcher couldn't be constructed. Also returns a delaborator key like in `mkExprMatcher`. Reminder: `$lit:ident : (scoped $scopedId:ident => $scopedTerm:Term)`
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
matchFoldl (lit x y : Name) (smatcher : Matcher) (sinit : Matcher) : Matcher
fun s => do s.withVar lit do let expr ← getExpr -- Clear x and y state before running smatcher so it can store new values let s := {s with vars := s.vars |>.erase x |>.erase y} let some s ← try some <$> smatcher s catch _ => pure none | -- We put this here rather than using a big try block to pr...
def
Mathlib.Notation3.matchFoldl
Util
Mathlib/Util/Notation3.lean
[]
[]
Matcher for expressions produced by `foldl`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
mkFoldlMatcher (lit x y : Name) (scopedTerm init : Term) (boundNames : Array Name) : OptionT TermElabM (List DelabKey × Term)
do -- Build the `scopedTerm` matcher with `x` and `y` as additional variables let boundNames' := boundNames |>.push x |>.push y let (keys, smatcher) ← mkExprMatcher scopedTerm boundNames' let (keys', sinit) ← mkExprMatcher init boundNames return (keys ++ keys', ← ``(matchFoldl $(quote lit) $(quote x) $(quote ...
def
Mathlib.Notation3.mkFoldlMatcher
Util
Mathlib/Util/Notation3.lean
[]
[]
Create a `Term` that represents a matcher for `foldl` notation. Reminder: `( lit ","* => foldl (x y => scopedTerm) init)`
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
mkFoldrMatcher (lit x y : Name) (scopedTerm init : Term) (boundNames : Array Name) : OptionT TermElabM (List DelabKey × Term)
do -- Build the `scopedTerm` matcher with `x` and `y` as additional variables let boundNames' := boundNames |>.push x |>.push y let (keys, smatcher) ← mkExprMatcher scopedTerm boundNames' let (keys', sinit) ← mkExprMatcher init boundNames -- N.B. by swapping `x` and `y` we can just use the foldl matcher ret...
def
Mathlib.Notation3.mkFoldrMatcher
Util
Mathlib/Util/Notation3.lean
[]
[]
Create a `Term` that represents a matcher for `foldr` notation. Reminder: `( lit ","* => foldr (x y => scopedTerm) init)`
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
BoundValueType /-- A normal variable, delaborate its expression. -/ | normal /-- A fold variable, use the fold state (but reverse the array). -/ | foldl /-- A fold variable, use the fold state (do not reverse the array). -/ | foldr
inductive
Mathlib.Notation3.BoundValueType
Util
Mathlib/Util/Notation3.lean
[]
[]
Used when processing different kinds of variables when building the final delaborator.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
getPrettyPrintOpt (opt? : Option (TSyntax ``prettyPrintOpt)) : Bool
if let some opt := opt? then match opt with | `(prettyPrintOpt| (prettyPrint := false)) => false | _ => true else true
def
Mathlib.Notation3.getPrettyPrintOpt
Util
Mathlib/Util/Notation3.lean
[]
[]
Interpret a `prettyPrintOpt`. The default value is `true`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
withHeadRefIfTagAppFns (d : Delab) : Delab
do let tagAppFns ← getPPOption getPPTagAppFns if tagAppFns && (← getExpr).getAppFn.consumeMData.isConst then -- Delaborate the head to register term info and get a syntax we can use for the ref. -- The syntax `f` itself is thrown away. let f ← withNaryFn <| withOptionAtCurrPos `pp.tagAppFns true delab ...
def
Mathlib.Notation3.withHeadRefIfTagAppFns
Util
Mathlib/Util/Notation3.lean
[]
[]
If `pp.tagAppFns` is true and the head of the current expression is a constant, then delaborates the head and uses it for the ref. This causes tokens inside the syntax to refer to this constant. A consequence is that docgen will linkify the tokens.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
(name := notation3) doc:(docComment)? attrs?:(Parser.Term.attributes)? attrKind:Term.attrKind "notation3" prec?:(precedence)? name?:(namedName)? prio?:(namedPrio)? pp?:(ppSpace prettyPrintOpt)? items:(ppSpace notation3Item)+ " => " val:term : command => do -- We use raw `Name`s for variables. This maps variab...
{} -- Replacements to use for the `macro` let mut boundValues : Std.HashMap Name Syntax := {} -- The names of the bound names in order, used when constructing patterns for delaboration. let mut boundNames : Array Name := #[] -- The normal/foldl/foldr type of each variable (for delaborator) let mut boundType...
elab
notation3
Util
Mathlib/Util/Notation3.lean
[]
[ "Mathlib.Notation3.mkExprMatcher" ]
`notation3` declares notation using Lean-3-style syntax. Examples: ``` notation3 "∀ᶠ " (...) " in " f ", " r:(scoped p => Filter.eventually p f) => r notation3 "MyList[" (x", "* => foldr (a b => MyList.cons a b) MyList.nil) "]" => x ``` By default notation is unable to mention any variables defined using `variable`, b...
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
captureException (env : Environment) (s : ParserFn) (input : String) : Except String Syntax
let ictx := mkInputContext input "<input>" let s := s.run ictx { env, options := {} } (getTokenTable env) (mkParserState input) if !s.allErrors.isEmpty then .error (s.toErrorMsg ictx) else if ictx.atEnd s.pos then .ok s.stxStack.back else .error ((s.mkError "end of input").toErrorMsg ictx)
def
Mathlib.GuardExceptions.captureException
Util
Mathlib/Util/ParseCommand.lean
[]
[]
`captureException env s input` uses the given `Environment` `env` to parse the `String` `input` using the `ParserFn` `s`. This is a variation of `Lean.Parser.runParserCategory`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
parseAsTacticSeq (env : Environment) (input : String) (fileName := "<input>") : Except String (TSyntax ``Lean.Parser.Tactic.tacticSeq)
let p := andthenFn whitespace Tactic.tacticSeq.fn let ictx := mkInputContext input fileName let s := p.run ictx { env, options := {} } (getTokenTable env) (mkParserState input) if s.hasError then .error (s.toErrorMsg ictx) else if s.pos.atEnd input then .ok ⟨s.stxStack.back⟩ else .error ((s.mkErro...
def
Mathlib.GuardExceptions.parseAsTacticSeq
Util
Mathlib/Util/ParseCommand.lean
[]
[]
Parse a string as a tactic sequence. This is a slight modification of `Parser.runParserCategory`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
getPPBinderPredicates (o : Options) : Bool
o.get pp.mathlib.binderPredicates.name (!getPPAll o)
def
Mathlib.getPPBinderPredicates
Util
Mathlib/Util/PPOptions.lean
[]
[]
Gets whether `pp.mathlib.binderPredicates` is enabled.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
State where /-- The set of already visited declarations. -/ visited : NameSet
{} /-- The set of `sorry` expressions that have been found. Note that unlabeled sorries will only be reported in the *first* declaration that uses them, even if a later definition independently has a direct use of `sorryAx`. -/ sorries : Std.HashSet Expr := {} /-- The uses of `sorry` that were found. -/ sor...
structure
Mathlib.PrintSorries.State
Util
Mathlib/Util/PrintSorries.lean
[]
[]
Type of intermediate computation of sorry-tracking.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
collect (c : Name) : StateT State MetaM Unit
do let collectExpr (e : Expr) : StateT State MetaM Unit := do /- We assume most declarations do not contain sorry. The `getUsedConstants` function is very efficient compared to `forEachExpr'`, since `forEachExpr'` needs to instantiate fvars. Visiting constants first also guarantees that we attribu...
def
Mathlib.PrintSorries.collect
Util
Mathlib/Util/PrintSorries.lean
[]
[]
Collects all uses of `sorry` by the declaration `c`. It finds all transitive uses as well. This is a version of `Lean.CollectAxioms.collect` that keeps track of enough information to print each use of `sorry`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
collectSorries (constNames : Array Name) : MetaM (Array MessageData)
do let (_, s) ← (constNames.forM collect).run {} pure s.sorryMsgs
def
Mathlib.PrintSorries.collectSorries
Util
Mathlib/Util/PrintSorries.lean
[]
[]
Prints all uses of `sorry` inside a list of declarations. Displayed sorries are hoverable and support "go to definition".
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
evalCollectSorries (names : Array Name) : CommandElabM Unit
do let msgs ← liftTermElabM <| collectSorries names if msgs.isEmpty then logInfo m!"Declarations are sorry-free!" else logInfo <| MessageData.joinSep msgs.toList "\n"
def
Mathlib.PrintSorries.evalCollectSorries
Util
Mathlib/Util/PrintSorries.lean
[]
[]
Collects sorries in the given constants and logs a message.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
getLevelQ (e : Expr) : MetaM (Σ u : Lean.Level, Q(Sort u))
do return ⟨← getLevel e, e⟩
def
Qq.getLevelQ
Util
Mathlib/Util/Qq.lean
[]
[]
If `e` has type `Sort u` for some level `u`, return `u` and `e : Q(Sort u)`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
getLevelQ' (e : Expr) : MetaM (Σ u : Lean.Level, Q(Type u))
do let u ← getLevel e let some v := (← instantiateLevelMVars u).dec | throwError "not a Type{indentExpr e}" return ⟨v, e⟩
def
Qq.getLevelQ'
Util
Mathlib/Util/Qq.lean
[]
[]
If `e` has type `Type u` for some level `u`, return `u` and `e : Q(Type u)`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
inferTypeQ' (e : Expr) : MetaM ((u : Level) × (α : Q(Type $u)) × Q($α))
do let α ← inferType e let ⟨v, α⟩ ← getLevelQ' α pure ⟨v, α, e⟩
def
Qq.inferTypeQ'
Util
Mathlib/Util/Qq.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
QuotedDefEq.rfl {u : Level} {α : Q(Sort u)} {a : Q($α)} : @QuotedDefEq u α a a
⟨⟩
theorem
Qq.QuotedDefEq.rfl
Util
Mathlib/Util/Qq.lean
[]
[]
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
findLocalDeclWithTypeQ? {u : Level} (sort : Q(Sort u)) : MetaM (Option Q($sort))
do let some fvarId ← findLocalDeclWithType? q($sort) | return none return some <| .fvar fvarId
def
Qq.findLocalDeclWithTypeQ?
Util
Mathlib/Util/Qq.lean
[]
[]
Return a local declaration whose type is definitionally equal to `sort`. This is a Qq version of `Lean.Meta.findLocalDeclWithType?`
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
mkDecideProofQ (p : Q(Prop)) : MetaM Q($p)
mkDecideProof p
def
Qq.mkDecideProofQ
Util
Mathlib/Util/Qq.lean
[]
[]
Returns a proof of `p : Prop` using `decide p`. This is a Qq version of `Lean.Meta.mkDecideProof`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
mkSetLiteralQ {u v : Level} {α : Q(Type u)} (β : Q(Type v)) (elems : List Q($α)) (_ : Q(EmptyCollection $β) := by exact q(inferInstance)) (_ : Q(Singleton $α $β) := by exact q(inferInstance)) (_ : Q(Insert $α $β) := by exact q(inferInstance)) : Q($β)
match elems with | [] => q(∅) | [x] => q({$x}) | x :: xs => q(Insert.insert $x $(mkSetLiteralQ β xs))
def
Qq.mkSetLiteralQ
Util
Mathlib/Util/Qq.lean
[]
[]
Join a list of elements of type `α` into a container `β`. Usually `β` is `q(Multiset α)` or `q(Finset α)` or `q(Set α)`. As an example ```lean mkSetLiteralQ q(Finset ℝ) (List.range 4 |>.map fun n : ℕ ↦ q($n•π)) ``` produces the expression `{0 • π, 1 • π, 2 • π, 3 • π} : Finset ℝ`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
mkNatLitQ (n : Nat) : Q(Nat)
mkNatLit n
def
Qq.mkNatLitQ
Util
Mathlib/Util/Qq.lean
[]
[]
Returns the natural number literal `n` as used in the frontend. It is a `OfNat.ofNat` application. Recall that all theorems and definitions containing numeric literals are encoded using `OfNat.ofNat` applications in the frontend. This is a Qq version of `Lean.mkNatLit`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
mkIntLitQ (n : Int) : Q(Int)
mkIntLit n
def
Qq.mkIntLitQ
Util
Mathlib/Util/Qq.lean
[]
[]
Returns the integer literal `n`. This is a Qq version of `Lean.mkIntLit`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
Methods.dischargeQ? (M : Methods) (a : Q(Prop)) : SimpM <| Option Q($a)
M.discharge? a
def
Lean.Meta.Simp.Methods.dischargeQ?
Util
Mathlib/Util/Simp.lean
[]
[]
`Qq` version of `Lean.Meta.Simp.Methods.discharge?`, which avoids having to use `~q` matching on the proof expression returned by `discharge?` `dischargeQ? (a : Q(Prop))` attempts to prove `a` using the discharger, returning `some (pf : Q(a))` if a proof is found and `none` otherwise.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
sleepAtLeastHeartbeats (n : Nat) : IO Unit
do -- TODO: adjust docstring IO.addHeartbeats n
def
sleepAtLeastHeartbeats
Util
Mathlib/Util/SleepHeartbeats.lean
[]
[]
A low level command to sleep for at least a given number of heartbeats by running in a loop until the desired number of heartbeats is hit. Warning: this function relies on interpreter / compiler behaviour that is not guaranteed to function in the way that is relied upon here. As such this function is not to be consider...
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
"sleep_heartbeats " n:num : tactic => do match Syntax.isNatLit? n with
| none => throwIllFormedSyntax /- We multiply by `1000` to convert the user-facing heartbeat count to the internal heartbeat counter used by `IO.getNumHeartbeats`. -/ | some m => sleepAtLeastHeartbeats (m * 1000)
elab
sleep_heartbeats
Util
Mathlib/Util/SleepHeartbeats.lean
[]
[ "sleepAtLeastHeartbeats" ]
do nothing for at least n heartbeats
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
Mapping where /-- Map from "special" (e.g. superscript) characters to "normal" characters. -/ toNormal : Std.HashMap Char Char
{} /-- Map from "normal" text to "special" (e.g. superscript) characters. -/ toSpecial : Std.HashMap Char Char := {} deriving Inhabited
structure
Mathlib.Tactic.Superscript.Mapping
Util
Mathlib/Util/Superscript.lean
[]
[]
A bidirectional character mapping.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
mkMapping (s₁ s₂ : String) : Mapping
Id.run do let mut toNormal := {} let mut toSpecial := {} assert! s₁.length == s₂.length for sp in s₁.toRawSubstring, nm in s₂ do assert! !toNormal.contains sp assert! !toSpecial.contains nm toNormal := toNormal.insert sp nm toSpecial := toSpecial.insert nm sp pure { toNormal, toSpecial }
def
Mathlib.Tactic.Superscript.mkMapping
Util
Mathlib/Util/Superscript.lean
[]
[]
Constructs a mapping (intended for compile time use). Panics on violated invariants.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
Mapping.superscript
mkMapping "⁰¹²³⁴⁵⁶⁷⁸⁹ᵃᵇᶜᵈᵉᶠᵍʰⁱʲᵏˡᵐⁿᵒᵖ𐞥ʳˢᵗᵘᵛʷˣʸᶻᴬᴮᴰᴱᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾꟴᴿᵀᵁⱽᵂᵝᵞᵟᵋᶿᶥᶹᵠᵡ⁺⁻⁼⁽⁾" "0123456789abcdefghijklmnopqrstuvwxyzABDEGHIJKLMNOPQRTUVWβγδεθιυφχ+-=()"
def
Mathlib.Tactic.Superscript.Mapping.superscript
Util
Mathlib/Util/Superscript.lean
[]
[]
A mapping from superscripts to and from regular text.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
Mapping.subscript
mkMapping "₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘꞯʀꜱᴛᴜᴠᴡʏᴢᵦᵧᵨᵩᵪ₊₋₌₍₎" "0123456789aehijklmnoprstuvxABCDEFGHIJKLMNOPQRSTUVWYZβγρφχ+-=()"
def
Mathlib.Tactic.Superscript.Mapping.subscript
Util
Mathlib/Util/Superscript.lean
[]
[]
A mapping from subscripts to and from regular text.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
satisfyTokensFn (p : Char → Bool) (errorMsg : String) (many := true) (k : Array (String.Pos.Raw × String.Pos.Raw × String.Pos.Raw) → ParserState → ParserState) : ParserFn
fun c s => let start := s.pos let s := takeWhile1Fn p errorMsg c s if s.hasError then s else let stop := s.pos let s := whitespace c s let toks := #[(start, stop, s.pos)] if many then let rec /-- Loop body of `satisfyTokensFn` -/ loop (toks) (s : ParserState) : ParserState := let start := s....
def
Mathlib.Tactic.Superscript.satisfyTokensFn
Util
Mathlib/Util/Superscript.lean
[]
[]
Collects runs of text satisfying `p` followed by whitespace. Fails if the first character does not satisfy `p`. If `many` is true, it will parse 1 or more many whitespace-separated runs, otherwise it will parse only 1. If successful, it passes the result to `k` as an array `(a, b, c)` where `a..b` is a token and `b..c`...
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
partitionPoint (lo := 0) (hi := as.size) : Nat
if lo < hi then let m := (lo + hi)/2 let a := as[m]! if leftOfPartition a then partitionPoint (m+1) hi else partitionPoint lo m else lo
def
Mathlib.Tactic.Superscript.partitionPoint
Util
Mathlib/Util/Superscript.lean
[]
[]
Given a predicate `leftOfPartition` which is true for indexes `< i` and false for `≥ i`, returns `i`, by binary search.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
scriptFnNoAntiquot (m : Mapping) (errorMsg : String) (p : ParserFn) (many := true) : ParserFn
fun c s => let start := s.pos satisfyTokensFn m.toNormal.contains errorMsg many c s (k := fun toks s => Id.run do let mut newStr := "" -- This consists of a sorted array of `(from, to)` pairs, where indexes `from+i` in `newStr` -- such that `from+i < from'` for the next element of the array, are mapped ...
def
Mathlib.Tactic.Superscript.scriptFnNoAntiquot
Util
Mathlib/Util/Superscript.lean
[]
[]
The core function for super/subscript parsing. It consists of three stages: 1. Parse a run of superscripted characters, skipping whitespace and stopping when we hit a non-superscript character. 2. Un-superscript the text and pass the body to the inner parser (usually `term`). 3. Take the resulting `Syntax` object a...
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
scriptParser (m : Mapping) (antiquotName errorMsg : String) (p : Parser) (many := true) (kind : SyntaxNodeKind := by exact decl_name%) : Parser
let tokens := "$" :: (m.toNormal.toArray.map (·.1.toString) |>.qsort (·<·)).toList let antiquotP := mkAntiquot antiquotName `term (isPseudoKind := true) let p := Superscript.scriptFnNoAntiquot m errorMsg p.fn many node kind { info.firstTokens := .tokens tokens info.collectTokens := (tokens ++ ·) fn :=...
def
Mathlib.Tactic.Superscript.scriptParser
Util
Mathlib/Util/Superscript.lean
[]
[]
The super/subscript parser. * `m`: the character mapping * `antiquotName`: the name to use for antiquotation bindings `$a:antiquotName`. Note that the actual syntax kind bound will be the body kind (parsed by `p`), not `kind`. * `errorMsg`: shown when the parser does not match * `p`: the inner parser (usually `term`...
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
scriptParser.parenthesizer (k : SyntaxNodeKind) (p : Parenthesizer) : Parenthesizer
Parenthesizer.node.parenthesizer k p
def
Mathlib.Tactic.Superscript.scriptParser.parenthesizer
Util
Mathlib/Util/Superscript.lean
[]
[]
Parenthesizer for the script parser.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
_root_.Std.Format.mapStringsM {m} [Monad m] (f : Format) (f' : String → m String) : m Format
match f with | .group f b => (.group · b) <$> Std.Format.mapStringsM f f' | .tag t g => .tag t <$> Std.Format.mapStringsM g f' | .append f g => .append <$> Std.Format.mapStringsM f f' <*> Std.Format.mapStringsM g f' | .nest n f => .nest n <$> Std.Format.mapStringsM f f' | .text s => .text <$> f' s | .align ...
def
Std.Format.mapStringsM
Util
Mathlib/Util/Superscript.lean
[]
[]
Map over the strings in a `Format`.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
scriptParser.formatter (name : String) (m : Mapping) (k : SyntaxNodeKind) (p : Formatter) : Formatter
do let stack ← modifyGet fun s => (s.stack, {s with stack := #[]}) Formatter.node.formatter k p let st ← get let transformed : Except String _ := st.stack.mapM (·.mapStringsM fun s => do let some s := s.toList.mapM (m.toSpecial.insert ' ' ' ').get? | .error s .ok (String.ofList s)) match transformed w...
def
Mathlib.Tactic.Superscript.scriptParser.formatter
Util
Mathlib/Util/Superscript.lean
[]
[]
Formatter for the script parser.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
superscript (p : Parser) : Parser
Superscript.scriptParser .superscript "superscript" "expected superscript character" p
def
Mathlib.Tactic.superscript
Util
Mathlib/Util/Superscript.lean
[]
[]
The parser `superscript(term)` parses a superscript. Basic usage is: ``` local syntax:arg term:max superscript(term) : term local macro_rules | `($a:term $b:superscript) => `($a ^ $b) ``` Given a notation like this, the expression `2⁶⁴` parses and expands to `2 ^ 64`. Note that because of Unicode limitations, not many...
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
superscript.parenthesizer
Superscript.scriptParser.parenthesizer ``superscript
def
Mathlib.Tactic.superscript.parenthesizer
Util
Mathlib/Util/Superscript.lean
[]
[]
Formatter for the superscript parser.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
superscript.formatter
Superscript.scriptParser.formatter "superscript" .superscript ``superscript
def
Mathlib.Tactic.superscript.formatter
Util
Mathlib/Util/Superscript.lean
[]
[]
Formatter for the superscript parser.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
superscriptTerm
leading_parser (withAnonymousAntiquot := false) superscript termParser
def
Mathlib.Tactic.superscriptTerm
Util
Mathlib/Util/Superscript.lean
[]
[]
Shorthand for `superscript(term)`. This is needed because the initializer below does not always run, and if it has not run then downstream parsers using the combinators will crash. See https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Non-builtin.20parser.20aliases/near/365125476 for some context.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
subscript (p : Parser) : Parser
Superscript.scriptParser .subscript "subscript" "expected subscript character" p
def
Mathlib.Tactic.subscript
Util
Mathlib/Util/Superscript.lean
[]
[]
The parser `subscript(term)` parses a subscript. Basic usage is: ``` local syntax:arg term:max subscript(term) : term local macro_rules | `($a:term $i:subscript) => `($a $i) ``` Given a notation like this, the expression `(a)ᵢ` parses and expands to `a i`. (Either parentheses or a whitespace as in `a ᵢ` is required, be...
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
subscript.parenthesizer
Superscript.scriptParser.parenthesizer ``subscript
def
Mathlib.Tactic.subscript.parenthesizer
Util
Mathlib/Util/Superscript.lean
[]
[]
Formatter for the subscript parser.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
subscript.formatter
Superscript.scriptParser.formatter "subscript" .subscript ``subscript
def
Mathlib.Tactic.subscript.formatter
Util
Mathlib/Util/Superscript.lean
[]
[]
Formatter for the subscript parser.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
subscriptTerm
leading_parser (withAnonymousAntiquot := false) subscript termParser
def
Mathlib.Tactic.subscriptTerm
Util
Mathlib/Util/Superscript.lean
[]
[]
Shorthand for `subscript(term)`. This is needed because the initializer below does not always run, and if it has not run then downstream parsers using the combinators will crash. See https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Non-builtin.20parser.20aliases/near/365125476 for some context.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
Superscript.isValid (m : Mapping) : Syntax → Bool
| .node _ kind args => kind == hygieneInfoKind || (!(scripted kind) && args.all (isValid m)) | .atom _ s => valid s | .ident _ _ s _ => valid s.toString | _ => false where valid (s : String) : Bool := s.all ((m.toSpecial.insert ' ' ' ').contains ·) scripted : SyntaxNodeKind → Bool := #[``subscript, ``...
def
Mathlib.Tactic.Superscript.isValid
Util
Mathlib/Util/Superscript.lean
[]
[]
Returns true if every character in `stx : Syntax` can be superscripted (or subscripted).
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
delabSuperscript : Delab
do let stx ← delab if Superscript.isValid .superscript stx.raw then pure stx else failure
def
Mathlib.Tactic.delabSuperscript
Util
Mathlib/Util/Superscript.lean
[]
[]
Successfully delaborates only if the resulting expression can be superscripted. See `Mapping.superscript` in this file for legal superscript characters.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319
delabSubscript : Delab
do let stx ← delab if Superscript.isValid .subscript stx.raw then pure stx else failure
def
Mathlib.Tactic.delabSubscript
Util
Mathlib/Util/Superscript.lean
[]
[]
Successfully delaborates only if the resulting expression can be subscripted. See `Mapping.subscript` in this file for legal subscript characters.
https://github.com/leanprover-community/mathlib4
b9f14353520df73472ae3825fb53f86559a01319