bookshelf-doc/DocGen4/LeanInk/Process.lean

58 lines
1.8 KiB
Plaintext
Raw Normal View History

/-
Copyright (c) 2022 Henrik Böving. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henrik Böving
-/
2022-07-26 10:52:41 +00:00
import Lean
import LeanInk.Analysis
import LeanInk.Annotation
import DocGen4.LeanInk.Output
import DocGen4.Output.Base
2022-07-26 10:52:41 +00:00
namespace DocGen4.Process.LeanInk
open Lean
2022-07-26 10:52:41 +00:00
open DocGen4.Output
2022-07-26 10:52:41 +00:00
def docGenOutput (as : List LeanInk.Annotation.Annotation) : HtmlT LeanInk.AnalysisM UInt32 := do
let some modName ← getCurrentName | unreachable!
let srcHtml ← LeanInk.Annotation.Alectryon.renderAnnotations as
2022-07-26 10:52:41 +00:00
let srcDir := moduleNameToDirectory srcBasePath modName
let srcPath := moduleNameToFile srcBasePath modName
IO.FS.createDirAll srcDir
IO.FS.writeFile srcPath srcHtml.toString
pure 0
2022-07-26 10:52:41 +00:00
def execAuxM : HtmlT LeanInk.AnalysisM UInt32 := do
let ctx ← readThe SiteContext
let baseCtx ← readThe SiteBaseContext
let outputFn := (docGenOutput · |>.run ctx baseCtx)
2022-07-26 10:52:41 +00:00
return ← LeanInk.Analysis.runAnalysis {
name := "doc-gen4"
genOutput := outputFn
}
def execAux (config : LeanInk.Configuration) : HtmlT IO UInt32 := do
execAuxM.run (←readThe SiteContext) (←readThe SiteBaseContext) |>.run config
@[implementedBy enableInitializersExecution]
private def enableInitializersExecutionWrapper : IO Unit := pure ()
def runInk (sourceFilePath : System.FilePath) : HtmlT IO Unit := do
let contents ← IO.FS.readFile sourceFilePath
let config := {
inputFilePath := sourceFilePath
inputFileContents := contents
lakeFile := none
verbose := false
prettifyOutput := true
experimentalTypeInfo := true
experimentalDocString := true
experimentalSemanticType := true
}
2022-07-26 10:52:41 +00:00
enableInitializersExecutionWrapper
if (← execAux config) != 0 then
throw <| IO.userError s!"Analysis for \"{sourceFilePath}\" failed!"
2022-07-26 10:52:41 +00:00
end DocGen4.Process.LeanInk