lean4-htt/src/Lean/Elab/AutoBound.lean
Leonardo de Moura bbcd2247f2 feat: extend valid set of valid auto bound names
@Kha The motivation was Andrew's example :)
Users often use `u₁`, `u1`, `u₂`, ... to name universe variables.
2020-12-19 12:36:19 -08:00

35 lines
1.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Data.Options
/- Basic support for auto bound implicit local names -/
namespace Lean.Elab
builtin_initialize
registerOption `autoBoundImplicitLocal {
defValue := true
group := ""
descr := "Unbound local variables in declaration headers become implicit arguments if they are a lower case or greek letter followed by numeric digits. For example, `def f (x : Vector α n) : Vector α n :=` automatically introduces the implicit variables {α n}"
}
def getAutoBoundImplicitLocalOption (opts : Options) : Bool :=
opts.get `autoBoundImplicitLocal true
private def allNumeral (s : Substring) : Bool :=
s.all fun c => c.isDigit || isNumericSubscript c
def isValidAutoBoundImplicitName (n : Name) : Bool :=
match n.eraseMacroScopes with
| Name.str Name.anonymous s _ => s.length > 0 && (isGreek s[0] || s[0].isLower) && allNumeral (s.toSubstring.drop 1)
| _ => false
def isValidAutoBoundLevelName (n : Name) : Bool :=
match n.eraseMacroScopes with
| Name.str Name.anonymous s _ => s.length > 0 && s[0].isLower && allNumeral (s.toSubstring.drop 1)
| _ => false
end Lean.Elab