-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To work with newer Lean versions, SubVerso needs to have some compatibility shims.
- Loading branch information
1 parent
b1bc281
commit 026f1ce
Showing
4 changed files
with
76 additions
and
15 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
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,54 @@ | ||
import Lean | ||
|
||
open Lean Elab Term | ||
|
||
namespace SubVerso.Compat | ||
|
||
elab "%first_defined" "[" xs:ident,* "]" : term => do | ||
let env ← getEnv | ||
for x in xs.getElems do | ||
if env.contains x.getId then | ||
let expr ← elabTerm x none | ||
return expr | ||
throwError "None of the names exist" | ||
|
||
|
||
def realizeNameNoOverloads | ||
[Monad m] [MonadEnv m] [MonadLiftT CoreM m] [MonadError m] | ||
[MonadInfoTree m] [MonadResolveName m] | ||
(ident : Syntax) : m Name := | ||
%first_defined [ | ||
Lean.Elab.realizeGlobalConstNoOverloadWithInfo, | ||
Lean.Elab.resolveGlobalConstNoOverloadWithInfo | ||
] ident | ||
|
||
|
||
elab "%first_succeeding" "[" es:term,* "]" : term <= ty => do | ||
for e in es.getElems do | ||
try | ||
let expr ← | ||
withReader ({· with errToSorry := false}) <| | ||
elabTerm e (some ty) | ||
return expr | ||
catch _ => | ||
continue | ||
throwError "No alternative succeeded" | ||
|
||
|
||
def mkRefIdentFVar [Monad m] [MonadEnv m] (id : FVarId) : m Lean.Lsp.RefIdent := do | ||
pure %first_succeeding [ | ||
.fvar (← getEnv).mainModule id, | ||
.fvar id | ||
] | ||
|
||
def refIdentCase (ri : Lsp.RefIdent) | ||
(onFVar : FVarId → α) | ||
(onConst : Name → α) : α := | ||
%first_succeeding [ | ||
match ri with | ||
| .fvar _ id => onFVar id | ||
| .const _ x => onConst x, | ||
match ri with | ||
| .fvar id => onFVar id | ||
| .const x => onConst x | ||
] |
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