docs: autogenerate code part of table of contents
Change-Id: I6a6a6964ec580d2403029e21ce785da000830c3d
This commit is contained in:
parent
fd85edb582
commit
b5529b2616
7 changed files with 51 additions and 39 deletions
2
docs/.gitignore
vendored
2
docs/.gitignore
vendored
|
|
@ -2,3 +2,5 @@
|
||||||
/node_modules
|
/node_modules
|
||||||
/modules/generated/pages/*
|
/modules/generated/pages/*
|
||||||
!/modules/generated/pages/.gitkeep
|
!/modules/generated/pages/.gitkeep
|
||||||
|
/modules/generated/partials/*
|
||||||
|
!/modules/generated/partials/.gitkeep
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ eggDerivation {
|
||||||
|
|
||||||
buildInputs = with chickenPackages.chickenEggs; [
|
buildInputs = with chickenPackages.chickenEggs; [
|
||||||
r7rs
|
r7rs
|
||||||
|
srfi-132
|
||||||
(pkgs.callPackage ../../core {})
|
(pkgs.callPackage ../../core {})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
((version "0.0.1")
|
((version "0.0.1")
|
||||||
(synopsis "read doc comments")
|
(synopsis "read doc comments")
|
||||||
(author "puck")
|
(author "puck")
|
||||||
(dependencies r7rs zilch)
|
(dependencies r7rs srfi-132 zilch)
|
||||||
(component-options
|
(component-options
|
||||||
(csc-options "-X" "r7rs" "-R" "r7rs" "-optimize-level" "3"))
|
(csc-options "-X" "r7rs" "-R" "r7rs" "-optimize-level" "3"))
|
||||||
(components
|
(components
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
(import (scheme base) (scheme file) (scheme write) (chicken read-syntax) (chicken process-context) (chicken irregex) (chicken format) (chicken process) (chicken file) (zilch zexpr))
|
(import (scheme base) (scheme file) (scheme write) (chicken read-syntax) (chicken process-context) (chicken irregex) (chicken format) (chicken process) (chicken file) (zilch zexpr) (srfi 132))
|
||||||
|
|
||||||
;; Return a string version of the passed-in val, but properly quoted as s-expression.
|
;; Return a string version of the passed-in val, but properly quoted as s-expression.
|
||||||
(define (quotify val)
|
(define (quotify val)
|
||||||
|
|
@ -72,6 +72,35 @@
|
||||||
(call-with-port (open-output-string)
|
(call-with-port (open-output-string)
|
||||||
(lambda (p) (render-lambda-doc p doc) (get-output-string p))))
|
(lambda (p) (render-lambda-doc p doc) (get-output-string p))))
|
||||||
|
|
||||||
|
(define table-of-contents
|
||||||
|
'(((zilch lang rust) . ())
|
||||||
|
((zilch lang ninja) . ())
|
||||||
|
((zilch lang go) . ())
|
||||||
|
((zilch nix) . ())
|
||||||
|
((zilch lib) . ())
|
||||||
|
((zilch) . ())))
|
||||||
|
|
||||||
|
; Returns whether `left` is a prefix of `right`.
|
||||||
|
(define (is-prefix left right)
|
||||||
|
(define
|
||||||
|
res
|
||||||
|
(let loop ((left left) (right right))
|
||||||
|
(cond
|
||||||
|
((and (null? left) (null? right)) #t)
|
||||||
|
((null? left) #t)
|
||||||
|
((null? right) #f)
|
||||||
|
((equal? (car left) (car right)) (loop (cdr left) (cdr right)))
|
||||||
|
(else #f))))
|
||||||
|
res)
|
||||||
|
|
||||||
|
(define (add-to-toc name path)
|
||||||
|
(let loop ((item table-of-contents))
|
||||||
|
(cond
|
||||||
|
((null? item) (error "Unknown TOC root" name))
|
||||||
|
((equal? name (caar item)) (set-cdr! (car item) (cons (sprintf "** xref:generated:~A[++~A++]\n" path name) (cdar item))))
|
||||||
|
((is-prefix (caar item) name) (set-cdr! (car item) (cons (sprintf "*** xref:generated:~A[++~A++]\n" path name) (cdar item))))
|
||||||
|
(else (loop (cdr item))))))
|
||||||
|
|
||||||
;; Iterate over the contents of a define-library, and collect comments on certain defines.
|
;; Iterate over the contents of a define-library, and collect comments on certain defines.
|
||||||
(define (parse-library-contents fname contents lib-comments)
|
(define (parse-library-contents fname contents lib-comments)
|
||||||
(define comments '())
|
(define comments '())
|
||||||
|
|
@ -141,10 +170,12 @@
|
||||||
(cdr j)))))
|
(cdr j)))))
|
||||||
contents)
|
contents)
|
||||||
|
|
||||||
(define out-path (string-append root "/docs/modules/generated/pages"))
|
|
||||||
(define first #t)
|
(define first #t)
|
||||||
(for-each (lambda (l) (set! out-path (string-append out-path (if first "/" ".") (symbol->string l))) (set! first #f)) (car contents))
|
(define file-path "")
|
||||||
(set! out-path (string-append out-path ".adoc"))
|
(for-each (lambda (l) (set! file-path (string-append file-path (if first "" ".") (symbol->string l))) (set! first #f)) (car contents))
|
||||||
|
(set! file-path (string-append file-path ".adoc"))
|
||||||
|
(define out-path (string-append root "/docs/modules/generated/pages/" file-path))
|
||||||
|
(add-to-toc (car contents) file-path)
|
||||||
|
|
||||||
(define out-file (open-output-file out-path))
|
(define out-file (open-output-file out-path))
|
||||||
; Print out the comments
|
; Print out the comments
|
||||||
|
|
@ -178,3 +209,14 @@
|
||||||
|
|
||||||
|
|
||||||
(find-files root #:test ".*\\.(sld|scm)" #:action process-file)
|
(find-files root #:test ".*\\.(sld|scm)" #:action process-file)
|
||||||
|
|
||||||
|
(call-with-output-file (string-append root "/docs/modules/generated/partials/nav.adoc")
|
||||||
|
(lambda (p)
|
||||||
|
(for-each
|
||||||
|
(lambda (chunk)
|
||||||
|
(define sorted (list-sort string<? (cdr chunk)))
|
||||||
|
(when (or (null? sorted) (not (string=? (string-copy (car sorted) 0 3) "** ")))
|
||||||
|
(fprintf p "** ++~A++\n" (car chunk)))
|
||||||
|
(for-each (lambda (line) (write-string line p)) sorted)
|
||||||
|
(write-string "\n" p))
|
||||||
|
(reverse table-of-contents))))
|
||||||
|
|
|
||||||
|
|
@ -3,37 +3,4 @@
|
||||||
* xref:zexp.adoc[]
|
* xref:zexp.adoc[]
|
||||||
|
|
||||||
* Code
|
* Code
|
||||||
** ++(zilch)++
|
include::generated:partial$nav.adoc[]
|
||||||
*** xref:generated:zilch.file.adoc[++(zilch file)++]
|
|
||||||
*** xref:generated:zilch.magic.adoc[++(zilch magic)++]
|
|
||||||
*** xref:generated:zilch.nixpkgs.adoc[++(zilch nixpkgs)++]
|
|
||||||
*** xref:generated:zilch.semver.adoc[++(zilch semver)++]
|
|
||||||
*** xref:generated:zilch.statusbar.adoc[++(zilch statusbar)++]
|
|
||||||
*** xref:generated:zilch.vfs.adoc[++(zilch vfs)++]
|
|
||||||
*** xref:generated:zilch.zexpr.adoc[++(zilch zexpr)++]
|
|
||||||
|
|
||||||
** xref:generated:zilch.lang.go.adoc[++(zilch lang go)++]
|
|
||||||
*** xref:generated:zilch.lang.go.core.adoc[++(zilch lang go core)++]
|
|
||||||
*** xref:generated:zilch.lang.go.fetch.adoc[++(zilch lang go fetch)++]
|
|
||||||
*** xref:generated:zilch.lang.go.mod.adoc[++(zilch lang go mod)++]
|
|
||||||
*** xref:generated:zilch.lang.go.package.adoc[++(zilch lang go package)++]
|
|
||||||
*** xref:generated:zilch.lang.go.stdlib.adoc[++(zilch lang go stdlib)++]
|
|
||||||
*** xref:generated:zilch.lang.go.sum.adoc[++(zilch lang go sum)++]
|
|
||||||
*** xref:generated:zilch.lang.go.version.adoc[++(zilch lang go version)++]
|
|
||||||
*** xref:generated:zilch.lang.go.vfs.adoc[++(zilch lang go vfs)++]
|
|
||||||
|
|
||||||
** xref:generated:zilch.lang.rust.adoc[++(zilch lang rust)++]
|
|
||||||
*** xref:generated:zilch.lang.rust.build-script.adoc[++(zilch lang rust build-script)++]
|
|
||||||
*** xref:generated:zilch.lang.rust.cargo.adoc[++(zilch lang rust cargo)++]
|
|
||||||
*** xref:generated:zilch.lang.rust.cfg.adoc[++(zilch lang rust cfg)++]
|
|
||||||
*** xref:generated:zilch.lang.rust.registry.adoc[++(zilch lang rust registry)++]
|
|
||||||
*** xref:generated:zilch.lang.rust.resolver.adoc[++(zilch lang rust resolver)++]
|
|
||||||
** ++(zilch lib)++
|
|
||||||
*** xref:generated:zilch.lib.getopt.adoc[++(zilch lib getopt)++]
|
|
||||||
*** xref:generated:zilch.lib.hash.adoc[++(zilch lib hash)++]
|
|
||||||
** ++(zilch nix)++
|
|
||||||
*** xref:generated:zilch.nix.binproto.adoc[++(zilch nix binproto)++]
|
|
||||||
*** xref:generated:zilch.nix.daemon.adoc[++(zilch nix daemon)++]
|
|
||||||
*** xref:generated:zilch.nix.drv.adoc[++(zilch nix drv)++]
|
|
||||||
*** xref:generated:zilch.nix.hash.adoc[++(zilch nix hash)++]
|
|
||||||
*** xref:generated:zilch.nix.path.adoc[++(zilch nix path)++]
|
|
||||||
|
|
|
||||||
0
docs/modules/generated/pages/.gitkeep
Normal file
0
docs/modules/generated/pages/.gitkeep
Normal file
0
docs/modules/generated/partials/.gitkeep
Normal file
0
docs/modules/generated/partials/.gitkeep
Normal file
Loading…
Add table
Add a link
Reference in a new issue