feat(library/init/lean/elaborator): add universe and universes elaborators

This commit is contained in:
Leonardo de Moura 2019-07-31 16:46:02 -07:00
parent fe9908cad3
commit bfb5bd3752
2 changed files with 26 additions and 2 deletions

View file

@ -37,6 +37,7 @@ structure ElabScope :=
(options : Options := {})
(ns : Name := Name.anonymous) -- current namespace
(openDecls : List OpenDecl := [])
(univs : List Name := [])
namespace ElabScope
@ -388,9 +389,14 @@ namespace Elab
instance {α} : Inhabited (Elab α) :=
⟨fun _ => default _⟩
def getScope : Elab ElabScope :=
do s ← get; pure s.scopes.head
def getOpenDecls : Elab (List OpenDecl) :=
do s ← get;
pure s.scopes.head.openDecls
ElabScope.openDecls <$> getScope
def getUniverses : Elab (List Name) :=
ElabScope.univs <$> getScope
def getNamespace : Elab Name :=
do s ← get;

View file

@ -161,6 +161,24 @@ fun n => do
else
elabOpenRenaming body
def addUniverse (idStx : Syntax) : Elab Unit :=
do
let id := idStx.getId;
univs ← getUniverses;
if univs.elem id then
logError idStx ("a universe named '" ++ toString id ++ "' has already been declared in this Scope")
else
modifyScope $ fun scope => { univs := id :: scope.univs, .. scope }
@[builtinCommandElab «universe»] def elabUniverse : CommandElab :=
fun n => do
addUniverse (n.getArg 1)
@[builtinCommandElab «universes»] def elabUniverses : CommandElab :=
fun n => do
let idsStx := n.getArg 1;
idsStx.mforArgs addUniverse
/- We just ignore Lean3 notation declaration commands. -/
@[builtinCommandElab «mixfix»] def elabMixfix : CommandElab := fun _ => pure ()
@[builtinCommandElab «reserve»] def elabReserve : CommandElab := fun _ => pure ()