2022-06-19 22:31:09 +00:00
|
|
|
/-
|
|
|
|
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-06-19 22:31:09 +00:00
|
|
|
|
2022-07-26 10:52:41 +00:00
|
|
|
namespace DocGen4.Process.LeanInk
|
2022-06-19 22:31:09 +00:00
|
|
|
|
|
|
|
open Lean
|
2022-07-26 10:52:41 +00:00
|
|
|
open DocGen4.Output
|
2022-07-27 18:11:41 +00:00
|
|
|
|
2022-07-26 10:52:41 +00:00
|
|
|
def docGenOutput (as : List LeanInk.Annotation.Annotation) : HtmlT LeanInk.AnalysisM UInt32 := do
|
2022-07-27 18:11:41 +00:00
|
|
|
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-06-19 22:31:09 +00:00
|
|
|
|
2022-07-26 10:52:41 +00:00
|
|
|
def execAuxM : HtmlT LeanInk.AnalysisM UInt32 := do
|
|
|
|
let ctx ← readThe SiteContext
|
|
|
|
let baseCtx ← readThe SiteBaseContext
|
2022-07-27 18:11:41 +00:00
|
|
|
let outputFn := (docGenOutput · |>.run ctx baseCtx)
|
2022-10-20 17:51:26 +00:00
|
|
|
return ← LeanInk.Analysis.runAnalysis {
|
2022-07-26 10:52:41 +00:00
|
|
|
name := "doc-gen4"
|
|
|
|
genOutput := outputFn
|
2022-10-20 17:51:26 +00:00
|
|
|
}
|
2022-07-26 10:52:41 +00:00
|
|
|
|
|
|
|
def execAux (config : LeanInk.Configuration) : HtmlT IO UInt32 := do
|
|
|
|
execAuxM.run (←readThe SiteContext) (←readThe SiteBaseContext) |>.run config
|
|
|
|
|
2022-10-20 17:51:26 +00:00
|
|
|
@[implemented_by enableInitializersExecution]
|
2022-07-26 10:52:41 +00:00
|
|
|
private def enableInitializersExecutionWrapper : IO Unit := pure ()
|
|
|
|
|
|
|
|
def runInk (sourceFilePath : System.FilePath) : HtmlT IO Unit := do
|
|
|
|
let contents ← IO.FS.readFile sourceFilePath
|
2022-10-20 17:51:26 +00:00
|
|
|
let config := {
|
2022-07-26 10:52:41 +00:00
|
|
|
inputFilePath := sourceFilePath
|
|
|
|
inputFileContents := contents
|
|
|
|
lakeFile := none
|
|
|
|
verbose := false
|
|
|
|
prettifyOutput := true
|
|
|
|
experimentalTypeInfo := true
|
|
|
|
experimentalDocString := true
|
|
|
|
experimentalSemanticType := true
|
2022-06-19 22:31:09 +00:00
|
|
|
}
|
2022-07-26 10:52:41 +00:00
|
|
|
enableInitializersExecutionWrapper
|
|
|
|
if (← execAux config) != 0 then
|
|
|
|
throw <| IO.userError s!"Analysis for \"{sourceFilePath}\" failed!"
|
2022-06-19 22:31:09 +00:00
|
|
|
|
2022-07-26 10:52:41 +00:00
|
|
|
end DocGen4.Process.LeanInk
|