feat(frontend): Dissect syntax tree
This commit is contained in:
parent
1a9e450066
commit
53ea808c90
|
@ -10,7 +10,7 @@ namespace Lean.Elab
|
||||||
private def elaboratorToString : Name → String
|
private def elaboratorToString : Name → String
|
||||||
| .anonymous => ""
|
| .anonymous => ""
|
||||||
| n => s!"⟨{n}⟩ "
|
| n => s!"⟨{n}⟩ "
|
||||||
private def indent (s : String) : String := "\n".intercalate $ s.splitOn "\n" |>.map ("\t" ++ .)
|
private def indent (s : String) : String := "\n".intercalate $ s.splitOn "\n" |>.map (" " ++ .)
|
||||||
|
|
||||||
/-- The `Syntax` for a `Lean.Elab.Info`, if there is one. -/
|
/-- The `Syntax` for a `Lean.Elab.Info`, if there is one. -/
|
||||||
protected def Info.stx? : Info → Option Syntax
|
protected def Info.stx? : Info → Option Syntax
|
||||||
|
|
|
@ -1,5 +1,29 @@
|
||||||
|
import Pantograph.Frontend
|
||||||
|
|
||||||
|
open Lean
|
||||||
|
|
||||||
|
namespace Pantograph
|
||||||
|
|
||||||
|
def fail (s : String) : IO Unit := do
|
||||||
|
IO.eprintln s
|
||||||
|
|
||||||
|
def dissect (args: List String): IO Unit := do
|
||||||
|
let fileName :: _args := args | fail s!"Must supply a file name"
|
||||||
|
let file ← IO.FS.readFile fileName
|
||||||
|
let (context, state) ← do Frontend.createContextStateFromFile file fileName (env? := .none) {}
|
||||||
|
let frontendM: Elab.Frontend.FrontendM _ :=
|
||||||
|
Frontend.mapCompilationSteps λ step => do
|
||||||
|
for tree in step.trees do
|
||||||
|
IO.println s!"{← tree.toString}"
|
||||||
|
let (_, _) ← frontendM.run context |>.run state
|
||||||
|
return ()
|
||||||
|
|
||||||
|
end Pantograph
|
||||||
|
|
||||||
|
open Pantograph
|
||||||
|
|
||||||
def main (args : List String) : IO Unit := do
|
def main (args : List String) : IO Unit := do
|
||||||
let command :: args := args | IO.eprintln "Must supply a command"
|
let command :: args := args | IO.eprintln "Must supply a command"
|
||||||
IO.println s!"{command}"
|
match command with
|
||||||
|
| "dissect" => dissect args
|
||||||
|
| _ => IO.eprintln s!"Unknown command {command}"
|
||||||
|
|
Loading…
Reference in New Issue