feat(library/init/lean/elaborator/term): add elabList, and fix elabTermAux
This commit is contained in:
parent
306ff7d7e5
commit
bd7ee8b01b
5 changed files with 29 additions and 7 deletions
|
|
@ -204,6 +204,7 @@ fun n => do
|
|||
@[builtinCommandElab «preterm»] def elabPreTerm : CommandElab :=
|
||||
fun n => do
|
||||
let s := n.getArg 1;
|
||||
runIO (IO.println s);
|
||||
pre ← toPreTerm (s.lift Expr);
|
||||
runIO (IO.println pre.dbgToString);
|
||||
pure ()
|
||||
|
|
@ -214,7 +215,9 @@ fun n => do
|
|||
r ← elabTerm (s.lift Expr);
|
||||
match r with
|
||||
| Syntax.other e => runIO (IO.println e.dbgToString)
|
||||
| _ => throw "failed to elaborate syntax"
|
||||
| other => do
|
||||
runIO (IO.println other);
|
||||
throw "failed to elaborate syntax"
|
||||
|
||||
/- We just ignore Lean3 notation declaration commands. -/
|
||||
@[builtinCommandElab «mixfix»] def elabMixfix : CommandElab := fun _ => pure ()
|
||||
|
|
|
|||
|
|
@ -18,7 +18,11 @@ partial def elabTermAux : Syntax Expr → Option Expr → Bool → Elab (Syntax
|
|||
let tables := termElabAttribute.ext.getState s.env;
|
||||
let k := n.getKind;
|
||||
match tables.find k with
|
||||
| some elab => elab n expectedType
|
||||
| some elab => do
|
||||
newStx ← elab n expectedType;
|
||||
match newStx with
|
||||
| Syntax.other _ => pure newStx
|
||||
| _ => elabTermAux newStx expectedType expanding
|
||||
| none => do
|
||||
-- recursively expand syntax
|
||||
let k := n.getKind;
|
||||
|
|
@ -38,10 +42,16 @@ partial def elabTermAux : Syntax Expr → Option Expr → Bool → Elab (Syntax
|
|||
def elabTerm (stx : Syntax Expr) (expectedType : Option Expr := none) : Elab (Syntax Expr) :=
|
||||
elabTermAux stx expectedType false
|
||||
|
||||
open Lean.Parser
|
||||
|
||||
@[builtinTermElab «list»] def elabList : TermElab :=
|
||||
fun stx _ => do
|
||||
runIO (IO.println stx.val);
|
||||
pure stx.val
|
||||
let openBkt := stx.getArg 0;
|
||||
let args := stx.getArg 1;
|
||||
let closeBkt := stx.getArg 2;
|
||||
let consId := openBkt.mkIdent `List.cons;
|
||||
let nilId := closeBkt.mkIdent `List.nil;
|
||||
pure $ args.foldSepArgs (fun arg r => mkAppStx consId [arg, r]) nilId
|
||||
|
||||
end Elab
|
||||
end Lean
|
||||
|
|
|
|||
|
|
@ -176,5 +176,8 @@ def checkIsSort := checkLeading (fun leading => leading.isOfKind `Lean.Parser.Te
|
|||
|
||||
end Term
|
||||
|
||||
def mkAppStx {α} (fn : Syntax α) (args : List (Syntax α)) : Syntax α :=
|
||||
args.foldl (fun fn arg => Syntax.node `Lean.Parser.Term.app [fn, arg].toArray) fn
|
||||
|
||||
end Parser
|
||||
end Lean
|
||||
|
|
|
|||
|
|
@ -457,5 +457,10 @@ match stx.isNatLit with
|
|||
| some val => val
|
||||
| none => 0
|
||||
|
||||
/-- Create an identifier using `SourceInfo` from `src` -/
|
||||
def mkIdent {α} (src : Syntax α) (val : Name) : Syntax α :=
|
||||
let info := src.getHeadInfo;
|
||||
Syntax.ident info (toString val).toSubstring val []
|
||||
|
||||
end Syntax
|
||||
end Lean
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@ import init.lean.elaborator
|
|||
open Lean
|
||||
|
||||
def main (xs : List String) : IO Unit :=
|
||||
do path ← IO.getEnv "LEAN_PATH";
|
||||
IO.println path;
|
||||
do initSearchPath "../../library:.";
|
||||
-- path ← IO.getEnv "LEAN_PATH";
|
||||
-- IO.println path;
|
||||
contents ← IO.readTextFile xs.head;
|
||||
(env, messages) ← testFrontend contents xs.head;
|
||||
(env, messages) ← Elab.testFrontend contents xs.head;
|
||||
messages.toList.mfor $ fun msg => IO.println msg;
|
||||
pure ()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue