summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2021-04-27 23:53:38 +0200
committerRicardo Wurmus <rekado@elephly.net>2021-04-27 23:53:38 +0200
commit7f8613cb088f0df0b1979620f36686aea1300465 (patch)
tree4149c5f63ee2b6b8706f8003fe2b03598af6c93f /doc
parent6e8124aa21edfe3e46f5ca735484118c2a7e343b (diff)
doc: Add documentation of low level bindings.
* doc/snarf.scm: New file. * Makefile.am (EXTRA_DIST): Add it. (doc/low.texi): New target. (drmaa_TEXINFOS): New definition. (CLEANFILES): Add generated doc/low.texi. * doc/drmaa.texi: Include doc/low.texi.
Diffstat (limited to 'doc')
-rw-r--r--doc/drmaa.texi7
-rw-r--r--doc/snarf.scm104
2 files changed, 111 insertions, 0 deletions
diff --git a/doc/drmaa.texi b/doc/drmaa.texi
index 494adc1..1146725 100644
--- a/doc/drmaa.texi
+++ b/doc/drmaa.texi
@@ -49,6 +49,7 @@ This document describes Guile DRMAA version @value{VERSION}.
@menu
* Introduction:: Why Guile DRMAA?
* Installation:: How do I install it?
+* Low-level bindings:: Bindings that closely wrap the library procedures.
@end menu
@c *********************************************************************
@@ -84,4 +85,10 @@ If you want to build the sources from the source repository you need to
bootstrap the build system first. Run the @code{bootstrap.sh} script
first and then perform the above steps.
+@c *********************************************************************
+@node Low-level bindings
+@chapter Low-level bindings
+
+@include low.texi
+
@bye
diff --git a/doc/snarf.scm b/doc/snarf.scm
new file mode 100644
index 0000000..5dd2f7d
--- /dev/null
+++ b/doc/snarf.scm
@@ -0,0 +1,104 @@
+;;; Copyright © 2021 Ricardo Wurmus <rekado@elephly.net>
+;;;
+;;; This program is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;;; Commentary:
+;;;
+;;; This script extracts docstrings from a module and spits out a
+;;; TexInfo file.
+;;;
+;;;; Code:
+
+(use-modules (ice-9 match)
+ (ice-9 session))
+
+(define (arguments->string proc)
+ (match (procedure-arguments proc)
+ ((('required . req-names)
+ ('optional . opt-names)
+ ('keyword . kw-names)
+ ('allow-other-keys? . any)
+ ('rest . rest))
+ (string-join
+ (list
+ (format #false "~{@var{~a}~^ ~}" req-names)
+ (format #false "~:[[~{@var{~a}~^ ~}]~;~]" (null? opt-names) opt-names)
+ (format #false "~:[[~{@var{~a}~^ ~}]~;~]" (null? kw-names) (map car kw-names))
+ (format #false "~@[@var{~a} ...~]" rest))))))
+
+(define (fancy-docstring proc known-procedures)
+ (define arguments
+ (match (procedure-arguments proc)
+ ((('required . req-names)
+ ('optional . opt-names)
+ ('keyword . kw-names)
+ ('allow-other-keys? . any)
+ ('rest . rest))
+ (let ((kws (map (compose keyword->symbol car)
+ kw-names)))
+ (map symbol->string
+ (append req-names opt-names kws
+ (if rest (list rest) '())))))))
+ (define (argument? word)
+ (member (string-downcase word) arguments))
+ (define* (maybe-wrap word #:optional (trail ""))
+ (let ((word* (string-drop-right word (string-length trail))))
+ (if (or (member word* '("#TRUE" "#FALSE" "*"))
+ (member word* known-procedures)
+ (argument? word*))
+ (string-append "@var{" (string-downcase word*) "}" trail)
+ (string-append word* trail))))
+ (let ((words (string-tokenize (procedure-documentation proc))))
+ (string-join (map (lambda (word)
+ (cond
+ ((string-suffix? "." word)
+ (maybe-wrap word "."))
+ ((string-suffix? "," word)
+ (maybe-wrap word ","))
+ ((string-suffix? ";" word)
+ (maybe-wrap word ";"))
+ (else
+ (maybe-wrap word))))
+ words))))
+
+(define (docs module)
+ (define known-procedures
+ (module-map (lambda (sym var)
+ (string-upcase (symbol->string sym)))
+ (resolve-interface module)))
+ (let ((unsorted
+ (module-map
+ (lambda (sym var)
+ (let ((proc (variable-ref var)))
+ (cons sym (format #false
+ "\
+@cindex ~a
+@deffn {Scheme Procedure} ~a ~a
+~a
+@end deffn
+" sym sym
+ (arguments->string proc)
+ (fancy-docstring proc known-procedures)))))
+ (resolve-interface module))))
+ (sort unsorted (lambda (a b)
+ (string< (symbol->string (car a))
+ (symbol->string (car b)))))))
+
+(with-output-to-file "doc/low.texi"
+ (lambda ()
+ (for-each (match-lambda
+ ((sym . doc)
+ (display doc)
+ (newline)))
+ (docs '(drmaa v1 low)))))