feat: include_str macro for static file inclusion

main
Henrik Böving 2021-12-12 13:20:03 +01:00
parent 0719fd6e30
commit 0f0a355a93
1 changed files with 21 additions and 0 deletions

21
DocGen4/IncludeStr.lean Normal file
View File

@ -0,0 +1,21 @@
import Lean
namespace DocGen4
open Lean System IO Lean.Elab.Term
syntax (name := includeStr) "include_str" str : term
@[termElab includeStr] def includeStrImpl : TermElab := λ stx expectedType? => do
let str := stx[1].isStrLit?.get!
let path := FilePath.mk str
if ←path.pathExists then
if ←path.isDir then
throwError s!"{str} is a directory"
else
let content ← FS.readFile path
return mkStrLit content
else
throwError s!"\"{str}\" does not exist as a file"
end DocGen4