From 7f8613cb088f0df0b1979620f36686aea1300465 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Tue, 27 Apr 2021 23:53:38 +0200 Subject: 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. --- doc/drmaa.texi | 7 ++++ doc/snarf.scm | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 doc/snarf.scm (limited to 'doc') 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 +;;; +;;; 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 . + +;;;; 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))))) -- cgit v1.2.3