Skip to content

Commit 20db2cb

Browse files
committed
Add logging to extractInfoTree
1 parent eed4488 commit 20db2cb

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

LeanUtils/Utils.lean

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,26 @@ def SorryData.toParsedSorry {Out} [ToString Out] (fileMap : FileMap) : SorryData
5656
instance : ToString ParsedSorry where
5757
toString a := ToString.toString <| ToJson.toJson a
5858

59+
#check Frontend.State
5960

6061
/-- `extractInfoTree myLeanFile` takes as input the path to a Lean file and outputs
6162
the infotrees of the file, together with the `FileMap`. -/
62-
def extractInfoTrees (fileName : System.FilePath) : IO ( FileMap × List InfoTree) := do
63+
def extractInfoTrees (fileName : System.FilePath) : IO (FileMap × List InfoTree) := do
6364
let input ← IO.FS.readFile fileName
6465
let inputCtx := Parser.mkInputContext input fileName.toString
6566
let (header, parserState, messages) ← Parser.parseHeader inputCtx
67+
if Lean.MessageLog.hasErrors messages then
68+
IO.println s!"Ran into errors while parsing the header of {fileName}"
6669
-- TODO: do we need to specify the main module here?
6770
let (env, messages) ← processHeader header {} messages inputCtx
71+
if Lean.MessageLog.hasErrors messages then
72+
IO.println s!"Ran into errors whist processing the header of {fileName}"
6873
let commandState := Command.mkState env messages
69-
let s ← IO.processCommands inputCtx parserState commandState
74+
let frontendState ← IO.processCommands inputCtx parserState commandState
75+
if Lean.MessageLog.hasErrors frontendState.commandState.messages then
76+
IO.println s!"Ran into errors whist processing the commands in {fileName}"
7077
let fileMap := FileMap.ofString input
71-
return (fileMap, s.commandState.infoState.trees.toList)
72-
78+
return (fileMap, frontendState.commandState.infoState.trees.toList)
7379

7480
/-
7581
Note: we may want to implememt the following functions in Python in order to

bins/ExtractSorry.lean

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ def main (args : List String) : IO Unit := do
2525
IO.eprintln (toJson out)
2626
else
2727
IO.println "A path is needed."
28+
29+
30+
def test : IO Unit := do
31+
discard <| IO.FS.readFile ⟨"this is a fake file"
32+
pure ()
33+
34+
35+
#eval test

0 commit comments

Comments
 (0)