moved "make-docs" to its own "tools" folder

This commit is contained in:
XeroOl 2024-05-29 23:41:19 -05:00
parent e0067880d1
commit 43af58d2eb
8 changed files with 95 additions and 57 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/fennel-ls
/result
/lua*.html
/build

View File

@ -6,11 +6,13 @@ SRC=$(wildcard src/*.fnl)
SRC+=$(wildcard src/fennel-ls/*.fnl)
SRC+=$(wildcard src/fennel-ls/docs/*.fnl)
BUILD_DIR=./build
DESTDIR ?=
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
OPTS=--add-package-path "./src/?.lua" --add-fennel-path "./src/?.fnl"
OPTS=--add-package-path "src/?.lua" --add-fennel-path "src/?.fnl"
OPTS+=--skip-include fennel.compiler
.PHONY: all clean test install ci selfcheck
@ -24,12 +26,13 @@ $(EXE): $(SRC)
clean:
rm -f $(EXE)
rm -rf $(BUILD_DIR)
test:
TESTING=1 $(FENNEL) $(OPTS) --add-fennel-path "./test/faith/?.fnl" test/init.fnl
TESTING=1 $(FENNEL) $(OPTS) --add-fennel-path "test/faith/?.fnl" test/init.fnl
repl:
$(FENNEL) $(OPTS) --add-fennel-path "./test/faith/?.fnl"
$(FENNEL) $(OPTS) --add-fennel-path "test/faith/?.fnl"
testall:
$(MAKE) test LUA=lua5.1
@ -39,7 +42,7 @@ testall:
$(MAKE) test LUA=luajit
docs:
$(FENNEL) $(OPTS) make-docs.fnl
$(FENNEL) $(OPTS) --add-fennel-path "tools/?.fnl" tools/gen-docs.fnl
install: $(EXE)
mkdir -p $(DESTDIR)$(BINDIR) && cp $< $(DESTDIR)$(BINDIR)/

View File

@ -1,5 +1,5 @@
;; Generated by make-docs.fnl from fennel-ls. Contents come from https://www.lua.org/manual/5.1/manual.html
;; The Lua manual for Lua 5.1 was last updated Thu Aug 29 20:43:58 UTC 2019
;; auto-generated by `make docs` from fennel-ls. Contents come from 5.1
;; Lua Lua 5.1 Reference Manual last updated Thu Aug 29 20:43:58 UTC 2019
(local docs {:_G {:binding "_G"
:metadata {:fnl/docstring "A global variable (not a function) that
holds the global environment (that is, `_G._G = _G`).

View File

@ -1,5 +1,5 @@
;; Generated by make-docs.fnl from fennel-ls. Contents come from https://www.lua.org/manual/5.2/manual.html
;; The Lua manual for Lua 5.2 was last updated Thu Aug 29 20:10:02 UTC 2019
;; auto-generated by `make docs` from fennel-ls. Contents come from 5.2
;; Lua Lua 5.2 Reference Manual last updated Thu Aug 29 20:10:02 UTC 2019
(local docs {:_G {:binding "_G"
:metadata {:fnl/docstring "A global variable (not a function) that
holds the global environment

View File

@ -1,5 +1,5 @@
;; Generated by make-docs.fnl from fennel-ls. Contents come from https://www.lua.org/manual/5.3/manual.html
;; The Lua manual for Lua 5.3 was last updated Tue Jul 14 10:32:39 UTC 2020
;; auto-generated by `make docs` from fennel-ls. Contents come from 5.3
;; Lua Lua 5.3 Reference Manual last updated Tue Jul 14 10:32:39 UTC 2020
(local docs {:_G {:binding "_G"
:metadata {:fnl/docstring "A global variable (not a function) that
holds the global environment

View File

@ -1,5 +1,5 @@
;; Generated by make-docs.fnl from fennel-ls. Contents come from https://www.lua.org/manual/5.4/manual.html
;; The Lua manual for Lua 5.4 was last updated Tue May 2 20:09:38 UTC 2023
;; auto-generated by `make docs` from fennel-ls. Contents come from 5.4
;; Lua Lua 5.4 Reference Manual last updated Tue May 2 20:09:38 UTC 2023
(local docs {:_G {:binding "_G"
:metadata {:fnl/docstring "A global variable (not a function) that
holds the global environment

51
tools/gen-docs.fnl Normal file
View File

@ -0,0 +1,51 @@
"Script to generate /src/fennel-ls/docs/lua54.fnl and friends automatically"
(fn sh [...]
"run a shell command."
(let [command (table.concat
(icollect [_ arg (ipairs [...])]
(if
;; table skips escaping
(= (type arg) :table)
(. arg 1)
;; simple string skips escaping
(arg:find "^[a-zA-Z0-9/_-]+$")
arg
;; full escaping
(.. "'"
(string.gsub arg "'" "\\'")
"'")))
" ")]
(print (.. "tools/gen-docs: " command))
(os.execute command)))
(fn mkdir-p [dirname]
(sh "mkdir" "-p" dirname))
(fn open-file-cached [filename url]
(var file (io.open filename :r))
(when (not file)
;; I think the repos also have the html file (or the ability to generate it, depending on lua version)
;; but for simplicity I'm just grabbing the html straight from the website
(sh "curl" url [">"] filename)
(set file (io.open filename :r)))
file)
(fn main []
(mkdir-p "build")
(let [lua-manual-parser (require :tools.gen-docs.lua-manual)]
(each [_ version (ipairs [:5.1 :5.2 :5.3 :5.4])]
(let [html-filename (.. "build/lua" version ".html")
url (.. "https://www.lua.org/manual/" version "/manual.html")
infile (open-file-cached html-filename url)
contents (infile:read "*a")
_ (infile:close)
docfile (lua-manual-parser.html-to-docfile contents version)
outfilename (.. "src/fennel-ls/docs/lua" (version:gsub "%." "") ".fnl")]
(print (.. "tools/gen-docs: writing " outfilename))
(doto (io.open outfilename "w")
(: :write docfile)
(: :close))))))
(main)

View File

@ -1,15 +1,3 @@
"Script to generate /src/fennel-ls/docs/lua54.fnl and friends automatically"
(fn open-file-cached [filename url]
(var file (io.open filename :r))
(when (not file)
;; I think the repos also have the html file (or the ability to generate it, depending on lua version)
;; but for simplicity I'm just grabbing the html straight from the website
(print (.. "Downloading " url))
(os.execute (.. "curl " url " > " filename))
(set file (io.open filename :r)))
file)
(fn parse-html [html]
"splits the lua manual into the relevant sections"
(let [begin-index (assert (html:find "<h2>.%.1 &ndash; <a name=\".%.1\">Basic Functions.-\n") "no basic functions?")
@ -182,39 +170,34 @@
:fields {}
:metadata {:fnl/docstring description}})))
(fn parse [input]
(let [version (input:match "Lua .- Reference Manual")
(modules module-items last-update) (parse-html input)
docs (collect [_ module (ipairs modules)]
(parse-h2-section module))]
(each [_ section (ipairs module-items)]
(let [(mod k v) (parse-h3-section section)]
(if (not mod)
(tset docs k v)
(not= mod "file")
(let [module-doc (. docs mod)]
(assert module-doc (.. mod " not found"))
(tset (. module-doc :fields) k v)))))
{: docs : last-update : version}))
(fn main []
(each [_ version (ipairs [:5.1 :5.2 :5.3 :5.4])]
(let [local-filename (.. "lua" version ".html")
url (.. "https://www.lua.org/manual/" version "/manual.html")
infile (open-file-cached local-filename url)
(modules module-items last-update) (parse-html (infile:read :a))
docs
(collect [_ module (ipairs modules)]
(parse-h2-section module))]
(fn render [{: docs : last-update : version} url]
(let [{: view : sym : list} (require :fennel)]
(..
";; auto-generated by `make docs` from fennel-ls. Contents come from " url "\n"
";; Lua " version " last updated " last-update "\n"
(view (list (sym :local) (sym :docs) docs)) "\n"
"(set docs._G.fields docs)\n"
"(set docs.io.fields.stdin.fields docs.io.fields)\n"
"(set docs.io.fields.stdout.fields docs.io.fields)\n"
"(set docs.io.fields.stderr.fields docs.io.fields)\n"
"docs\n")))
(each [_ section (ipairs module-items)]
(let [(mod k v) (parse-h3-section section)]
(if (not mod)
(tset docs k v)
(not= mod "file")
(do
(assert (. docs mod) (.. mod " not found"))
(tset (. docs mod :fields) k v)))))
(fn html-to-docfile [input url]
(render (parse input) url))
(print (.. "Emitting docs for lua" version))
(let [outfile (io.open (.. "src/fennel-ls/docs/lua" (version:gsub "%." "") ".fnl") :w)]
(local {: view : sym : list} (require :fennel))
(outfile:write
";; Generated by make-docs.fnl from fennel-ls. Contents come from " url "\n"
";; The Lua manual for Lua " version " was last updated " last-update "\n"
(view (list (sym :local) (sym :docs) docs))
"\n"
"(set docs._G.fields docs)\n"
"(set docs.io.fields.stdin.fields docs.io.fields)\n"
"(set docs.io.fields.stdout.fields docs.io.fields)\n"
"(set docs.io.fields.stderr.fields docs.io.fields)\n"
"docs\n"))
(print (.. "Emitted docs for lua" version)))))
(main)
{: html-to-docfile}