more doc extraction code

This commit is contained in:
XeroOl 2024-05-07 14:02:50 -05:00
parent 767cb88f63
commit 10aeb63142

View File

@ -32,30 +32,57 @@
(let [(header description) (html-describing-the-thing:match "^(.-)\n+(.-)\n*$") (let [(header description) (html-describing-the-thing:match "^(.-)\n+(.-)\n*$")
optional-args [] optional-args []
signature (header:match "<code>(.-)</code>") signature (header:match "<code>(.-)</code>")
;; strip commas
signature (signature:gsub "," " ")
;; Replace `[]`'d args with ?-prefixes ;; Replace `[]`'d args with ?-prefixes
;; Three times is enough, as `table.concat` and `load` and `loadfile` ;; Three times is enough, as `table.concat` and `load` and `loadfile`
;; and `utf8.codepoint` and `utf8.len` have 3 sets of []'s. ;; and `utf8.codepoint` and `utf8.len` have 3 sets of []'s.
;; Lua 5.2 manual has a typo, so the last pass makes the `]` optional. ;; Lua 5.2 manual has a typo, so the last pass makes the `]` optional.
signature (signature:gsub "%[,? ?([^%[%] ]+)([^%[%]]-)%](%]-%))" signature (signature:gsub "%[ -([^%[%] ]+)([^%[%]]-)%](%]-%))"
#(do (table.insert optional-args $1) (.. :? $1 $2 $3))) #(do (table.insert optional-args $1) (.. :? $1 $2 $3)))
signature (signature:gsub "%[,? ?([^%[%] ]+)([^%[%]]-)%](%]-%))" signature (signature:gsub "%[ -([^%[%] ]+)([^%[%]]-)%](%]-%))"
#(do (table.insert optional-args $1) (.. :? $1 $2 $3))) #(do (table.insert optional-args $1) (.. :? $1 $2 $3)))
signature (signature:gsub "%[,? ?([^%[%] ]+)([^%[%]]-)%]?(%]-)%)" signature (signature:gsub "%[ -([^%[%] ]+)([^%[%]]-)%]?(%]-%))"
#(do (table.insert optional-args $1) (.. :? $1 $2 $3))) #(do (table.insert optional-args $1) (.. :? $1 $2 $3)))
;; hide the thread argument in the debug functions
signature (if (signature:find "debug") (signature:gsub "%[thread -%]" "") signature)
;; hide the ?pos argument in table.insert
signature (if (signature:find "table%.insert") (signature:gsub "%[pos -%]" "") signature)
;; For some reason, they use an html middot, but we want to use periods. ;; For some reason, they use an html middot, but we want to use periods.
signature (signature:gsub "&middot;&middot;&middot;" "...")] signature (signature:gsub "&middot;&middot;&middot;" "...")
nil ;; fix parens
;; Debug prints for now. I'm not sure how to process the description. signature (signature:gsub "^(.-) -%(" "(%1 ")
(if (not (signature:match "%(")) ;; fix spaces
;; (print "c" signature) signature (signature:gsub " +" " ")
nil signature (signature:gsub " +%)" ")")
(and (signature:match "[%[]")
(not (signature:match "debug")) ;; delete <p> tags
(not (signature:match "table.insert"))) description (description:gsub "</?p>" "")
(do ;; trim whitespace
(print "========================" signature)) description (description:match "^%s*(.-)%s*$")
(print "?" signature)))) ;; <code> tags for optional args
description (accumulate [description description _ arg (ipairs optional-args)]
(description:gsub (.. "<code>" arg "</code>")
(.. "`?" arg "`")))
;; <code> tags for the rest
description (description:gsub "\"<code>(.-)</code>\"" "`\"%1\"`")
description (description:gsub "\'<code>(.-)</code>\'" "`\"%1\"`")
description (description:gsub "<code>(.-)</code>" "`%1`")
description (description:gsub "&nbsp;" " ")
description (description:gsub "&ndash;" "")
description (description:gsub "&mdash;" "—")]
(assert (not (signature:find "[%[%]]")) (.. "bad signature " signature))
;; Debug prints for now.
(print "=============")
(print "```fnl")
(print signature)
(print "```")
(print description)))
(each [_ section (ipairs sections)] (var done false)
(each [_ section (ipairs sections) &until done]
(process-html-thing section)) (process-html-thing section))
; (if (= (io.read) "done")
; (set done true)))