From 10aeb63142e8b5faf5528abc070113c00f874aaf Mon Sep 17 00:00:00 2001 From: XeroOl Date: Tue, 7 May 2024 14:02:50 -0500 Subject: [PATCH] more doc extraction code --- make-docs.fnl | 59 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/make-docs.fnl b/make-docs.fnl index 1248526..e99d8f9 100644 --- a/make-docs.fnl +++ b/make-docs.fnl @@ -32,30 +32,57 @@ (let [(header description) (html-describing-the-thing:match "^(.-)\n+(.-)\n*$") optional-args [] signature (header:match "(.-)") + ;; strip commas + signature (signature:gsub "," " ") ;; Replace `[]`'d args with ?-prefixes ;; Three times is enough, as `table.concat` and `load` and `loadfile` ;; 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. - signature (signature:gsub "%[,? ?([^%[%] ]+)([^%[%]]-)%](%]-%))" + signature (signature:gsub "%[ -([^%[%] ]+)([^%[%]]-)%](%]-%))" #(do (table.insert optional-args $1) (.. :? $1 $2 $3))) - signature (signature:gsub "%[,? ?([^%[%] ]+)([^%[%]]-)%](%]-%))" + signature (signature:gsub "%[ -([^%[%] ]+)([^%[%]]-)%](%]-%))" #(do (table.insert optional-args $1) (.. :? $1 $2 $3))) - signature (signature:gsub "%[,? ?([^%[%] ]+)([^%[%]]-)%]?(%]-)%)" + signature (signature:gsub "%[ -([^%[%] ]+)([^%[%]]-)%]?(%]-%))" #(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. - signature (signature:gsub "···" "...")] - nil - ;; Debug prints for now. I'm not sure how to process the description. - (if (not (signature:match "%(")) - ;; (print "c" signature) - nil - (and (signature:match "[%[]") - (not (signature:match "debug")) - (not (signature:match "table.insert"))) - (do - (print "========================" signature)) - (print "?" signature)))) + signature (signature:gsub "···" "...") + ;; fix parens + signature (signature:gsub "^(.-) -%(" "(%1 ") + ;; fix spaces + signature (signature:gsub " +" " ") + signature (signature:gsub " +%)" ")") + + ;; delete

tags + description (description:gsub "" "") + ;; trim whitespace + description (description:match "^%s*(.-)%s*$") + ;; tags for optional args + description (accumulate [description description _ arg (ipairs optional-args)] + (description:gsub (.. "" arg "") + (.. "`?" arg "`"))) + ;; tags for the rest + description (description:gsub "\"(.-)\"" "`\"%1\"`") + description (description:gsub "\'(.-)\'" "`\"%1\"`") + description (description:gsub "(.-)" "`%1`") + description (description:gsub " " " ") + description (description:gsub "–" "–") + description (description:gsub "—" "—")] + + (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)) + ; (if (= (io.read) "done") + ; (set done true)))