From 4f3bac551e7ff71237f7b1c94cb8266c27ad0464 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Tue, 12 May 2020 12:01:44 +1000 Subject: [PATCH] updated finddesc to use the new doc library, allowing type annotations and building a directory of documentation --- .gitignore | 3 +-- build.sh | 5 +++- finddesc.lua | 74 +++++++++++++++++++++++++++++++++++++--------------- template.tex | 46 ++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 24 deletions(-) create mode 100644 template.tex diff --git a/.gitignore b/.gitignore index f02c58a..03fadf9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -apidoc.md -apidoc.html *.cpio *.af /target +/doc diff --git a/build.sh b/build.sh index bd6815d..fa49106 100755 --- a/build.sh +++ b/build.sh @@ -7,5 +7,8 @@ echo _OSVERSION=\"PsychOS 2.0a2-$(git rev-parse --short HEAD)\" > target/version cat target/version.lua target/init.lua > target/tinit.lua mv target/tinit.lua target/init.lua cp -r service/ lib/ cfg/ target/ -$LUA finddesc.lua $(find module/ -type f) $(find lib/ -type f) > apidoc.md +#$LUA finddesc.lua $(find module/ -type f) $(find lib/ -type f) > apidoc.md rm target/version.lua +rm -r doc/ +$LUA finddesc2.lua doc/ $(find lib/ module/ -type f|sort) +pandoc doc/apidoc.md --template=template.tex -o doc/apidoc.pdf diff --git a/finddesc.lua b/finddesc.lua index d2c4df4..dde9e07 100644 --- a/finddesc.lua +++ b/finddesc.lua @@ -1,27 +1,59 @@ +#!/usr/bin/env lua +local doc = require "lib/doc" local tA = {...} -local docfiles = {} -for _,file in pairs(tA) do - docfiles[file] = {} - local f = io.open(file) - local lines = {} - for l in f:read("*a"):gmatch("[^\n]+") do - if l:find("function") and not l:find("local") then - lines[#lines+1] = l + +local outpath = table.remove(tA,1) + +print(outpath) + +local function formatDocs(fd) + local rs = "" + for name,finfo in pairs(fd) do + if rs:len() > 0 then + rs = rs .. "\n\n" end + local as = "" + for k,v in pairs(finfo.args) do + if k > 1 then + as = as .. ", " + end + as = as .. v[1] + if v[2] then + as = as .. "^"..v[2].."^" + end + end + local rt = "" + for k,v in pairs(finfo.outtypes or {}) do + if rt:len() > 0 then + rt = rt .. ", " + else + rt = ": " + end + rt = rt .. v + end + rs = string.format("%s## %s(%s)%s\n%s",rs,name,as,rt,finfo.description) end - for k,v in pairs(lines) do - local name, args, desc = v:match("function%s+(.+)%s*%((.*)%)%s*%-%-%s*(.+)") - if name and args and desc then - docfiles[file][#docfiles[file]+1] = string.format("## %s(%s)\n%s\n",name,args,desc) - end + return rs +end + +os.execute("mkdir -p "..outpath) +local ad = io.open(outpath.."/apidoc.md","w") + +for k,v in pairs(tA) do + local fd = doc.parsefile(v) + local ds = formatDocs(fd) + print(string.format("%s: %i",v,ds:len())) + if ds and ds:len() > 0 then + os.execute("mkdir -p $(dirname \""..outpath.."/"..v.."\")") + local f = io.open(outpath.."/"..v:gsub("%.lua$",".md"),"wb") + f:write(string.format("# %s\n\n",v)) + f:write(ds) + f:write("\n\n") + f:close() + ad:write(string.format("# %s\n\n",v)) + ad:write(ds) + ad:write("\n\n") end end -for k,v in pairs(docfiles) do - if #v > 0 then - print("\n# "..k) - for l,m in pairs(v) do - print(m) - end - end -end +ad:close() diff --git a/template.tex b/template.tex new file mode 100644 index 0000000..19bff59 --- /dev/null +++ b/template.tex @@ -0,0 +1,46 @@ +\documentclass[11pt,twoside,a4paper]{article} +\usepackage{hyperref} +\usepackage{multicol} +\usepackage{standalone} +\usepackage{graphicx} +\usepackage{pdfpages} +\usepackage{listings} +\usepackage{color} +\usepackage{sectsty} +\usepackage[cm]{fullpage} +\lstset{ + commentstyle=\color{cyan}, % comment style + keywordstyle=\color{cyan}, % keyword style + stringstyle=\color{red}, % string literal style + numbers=left, % where to put the line-numbers; possible values are (none, left, right) + numbersep=5pt, % how far the line-numbers are from the code + numberstyle=\tiny\color{gray}, % the style that is used for the line-numbers +} +\hypersetup{ + colorlinks=true +} + +\subsectionfont{\ttfamily} + +% pandoc stuff +\providecommand{\tightlist}{% + \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} + +\let\stdsection\section +\renewcommand\section{\newpage\stdsection} + +\lstset{basicstyle=\footnotesize\ttfamily,breaklines=true} +\newcommand{\ignore}[1]{} +\title{$title$$if(thanks)$\thanks{$thanks$}$endif$} +\author{$for(author)$$author$$sep$ \and $endfor$} +\date{} +\begin{document} + \pagenumbering{gobble} + \maketitle + \newpage + \pagenumbering{alph} + \tableofcontents + \newpage + \pagenumbering{arabic} + $body$ +\end{document}