Scheme のソースのコメントからドキュメントを生成する SchemeDoc を Gauche に移植

Scheme のソースのコメントからドキュメントを生成する SchemeDocGauche で動くようにしました。(一部いい加減な移植あるのはご容赦ください。)
SchemeDoc は Doxygen と同じ種類のツールです。

SchemeDoc の特徴

  • 2種類のドキュメント指示用のコメント形式がある
  • ドキュメント生成のオプションをソースに埋め込める
  • 複数の Scheme ファイルから1つのドキュメントを作れる
  • ドキュメントから Scheme のソースファイルにリンクできる
  • R5RS のドキュメントにリンクできる
  • いろいろな方法で起動できる。(SchemeインタプリタEmacsから)
  • XML を使ってマニュアルを一から作ることもできるよ
  • 索引を作れる
  • マニュアルの内部形式ファイルを吐くのでそれを使うのもいいかも
  • 独自のコメントタグを作れる

インストール

以下 Gauche 特有の手順については #(*Gauche*)と書きます。

  1. wget http://www.cs.aau.dk/~normark/laml/zip-distribution/schemedoc-32-30.zip
  2. unzip schemedoc-32-30.zip
  3. patch -p0 < schemedoc-32-30-gosh-20080501.diff #(*Gauche*)
  4. schemedoc/laml-config/configration を書く
  5. cd schemedoc/laml-config
  6. gosh 起動
  7. laml の config 生成(一度のみ)
    1. (add-load-path ".") #(*Gauche*)
    2. (load "./laml-config.scm")

使ってみる

  1. (define laml-dir "/home/taro/Desktop/mogemoge/schemedoc/")
  2. (load (string-append laml-dir "laml-init.scm"))
  3. (schemedoc "/home/taro/vm/monar/library2.scm")
    1. これで /tmp/library2.html ができる

より詳しい使い方

SchemeDoc からドキュメントを辿ってください。

Gauche 用の patch

  • Gauche に依存する手続きの実装
  • パース時に regexp? を満たす S式を認識するように
schemedoc-32-30-gosh-20080501.diff
diff -urN schemedoc.orig/laml-config/laml-config-internal.scm schemedoc/laml-config/laml-config-internal.scm
--- schemedoc.orig/laml-config/laml-config-internal.scm	2007-06-11 22:15:38.000000000 +0900
+++ schemedoc/laml-config/laml-config-internal.scm	2008-05-01 14:58:42.000000000 +0900
@@ -20,6 +20,10 @@
 ;;;; This program assumes the existence of the non-RS4S functions file-exists?, 

 ;;;; directory-exists? and delete-file.

 

+(define directory-exists? file-exists?)

+(define delete-file sys-unlink)

+

+

 ; --------------------------------------------------------------------------------------------------------

 

 ; Here we define optional-parameter (from laml.scm) because write-text-file uses it:

@@ -32,12 +36,13 @@
 ; --------------------------------------------------------------------------------------------------------

 

 (define supported-platforms '(windows unix))

-(define supported-scheme-systems '(scm mzscheme guile drscheme mzscheme-200 mzscheme-300 sisc bigloo gambit-4 drscheme-300))

+(define supported-scheme-systems '(scm mzscheme guile drscheme mzscheme-200 mzscheme-300 sisc bigloo gambit-4 drscheme-300 gosh))

                                                                  ; mzscheme really means version 103 or smaller.

                                                                  ; drscheme similarly means version 103 or smaller. 

                                                                  ; mzscheme-200 means version 200 - 209

                                                                  ; mzscheme-300 means version 299, and 300+

                                                                  ; drscheme-300 means DrScheme 300+

+                                                                 ; gosh         means Gauche

 

 (define supported-operating-systems '(win98 win95 nt40 solaris-6 linux solaris-7 win2000 osx))

 (define supported-kinds-of-emacs '(gnu-emacs win-emacs)) ; not important any more

diff -urN schemedoc.orig/lib/compatibility/star_star_gosh.scm schemedoc/lib/compatibility/star_star_gosh.scm
--- schemedoc.orig/lib/compatibility/star_star_gosh.scm	1970-01-01 09:00:00.000000000 +0900
+++ schemedoc/lib/compatibility/star_star_gosh.scm	2008-05-01 14:50:40.000000000 +0900
@@ -0,0 +1,48 @@
+(use file.util)
+
+;; Return the current time in seconds
+(define current-time sys-time)
+(define current-seconds sys-time)
+(define (current-process-milliseconds) 0)
+
+;; Sort list using the comparison predicate
+(define (sort-list list com) (sort list com))
+
+; ---------------------------------------------------------------------------------------------------
+
+;; Make a new directory, new-dir, in the directory path (first parameter).
+;; The parameter in-directory-path ends in a slash.
+(define (make-directory-in-directory in-directory-path new-dir)
+  (make-directory* (string-append in-directory-path new-dir)))
+
+(define directory-exists? file-exists?)
+(define delete-file sys-unlink)
+
+; ---------------------------------------------------------------------------------------------------
+
+(define (eval-cur-env e) (eval e (interaction-environment)))
+
+; -----------------------------------------------------------------------------
+
+;;; LAML specific, context definition functions. 
+;;; The functions in this section return and define the activation context of the LAML processor.
+
+
+;; Return the contextual command line information passed to LAML upon activation.
+;; Returns a list of lenght four or #f if no command line activation exists.
+;; The first element must be the symbol laml (a tag).
+;; Element number two must be the laml source file name (without extension and initial path).
+;; Element number three must be a slash terminated, full directory path (with forward slashes), in which the source file resides.
+;; Element number four must be a list of program parameters.
+;; This function must be redefined in Scheme-system/OS/platform dependent compatibility file. 
+(define (laml-canonical-command-line) `(laml "hige" "/tmp/" #f))
+
+(define (fake-startup-parameters source-file startup-dir . optional-parameter-list) '())
+
+(define-syntax load
+  (syntax-rules()
+    ((_ file)
+     (call-with-input-file file load-from-port :encoding 'latin1))))
+
+
+
diff -urN schemedoc.orig/styles/xml-in-laml/elucidator-2/elucidator.scm schemedoc/styles/xml-in-laml/elucidator-2/elucidator.scm
--- schemedoc.orig/styles/xml-in-laml/elucidator-2/elucidator.scm	2007-06-11 22:15:41.000000000 +0900
+++ schemedoc/styles/xml-in-laml/elucidator-2/elucidator.scm	2008-05-01 14:59:45.000000000 +0900
@@ -2387,6 +2387,9 @@
         ((char? f) (match-char f ip op)

                    (skip-white-space ip op))

 

+        ((and (eq? scheme-system 'gosh) (regexp? f)) (match-regexp f ip op)

+                   (skip-white-space ip op))

+

         ((boolean? f) (match-boolean f ip op)

                       (skip-white-space ip op))

 

@@ -3725,6 +3728,10 @@
   (read ip)

   (write ch op))

 

+(define (match-regexp ch ip op)

+  (read ip)

+  (write ch op))

+

 (define (match-number n ip op)

   (read ip)

   (write n op))

@@ -5927,4 +5934,4 @@
         ""

         sdd)))

          

-(end-laml-loading)    
\ No newline at end of file
+(end-laml-loading)    

おまけ

configuration の例

;  THIS FILE CONTAINS A LISP ASSOCIATION LIST WITH A LAML CONFIGURATION.
;  AN ASSOCIATION LIST IS A LIST OF KEY-VALUE PAIRS: (key . value).
;  EDIT THIS FILE BY CHANGING THE VALUES OF THE KEYS (AT THE
;  POSITIONS AFTER THE DOTS). THERE ARE ALREADY EXAMPLES OF
;  VALUES (SUCH AS "c:/programs/laml/") IN THIS FILE.
;  AFTER YOU HAVE EDITED THIS FILE PLEASE LOAD THE FILE 
;  laml-config.scm IN YOUR SCHEME SYSTEM. THIS IS THE SCHEME PROGRAM
;  WHICH PERFORMS THE CONFIGURATIN PROCESS. THE LOADING PROCESS WILL
;  READ THE CURRENT FILE, configuration, AND IT WILL CONFIGURE LAML 
;  ON YOUR COMPUTER.
;
;  NOTICE THAT THE EXISTING VALUES IN THIS FILE REFLECT A WINDOWS 2000 
;  OR WINDOWS XP SETUP WITH PLT MZSCHEME (version 200 .. 209).


(
  ; A full and absolute path to the directory in which your 
  ; LAML or SchmeDoc distribution is located.
  ; Always use forward slashes in the path.
  ; The last character should be a '/'.

  (laml-dir . "/home/taro/Desktop/mogemoge/schemedoc/")        ; <== Edit here


  ; Which Scheme system do you use:   mzscheme, mzscheme-200, mzscheme-300, scm, guile, sisc, drscheme, or drscheme-300.
  ; mzscheme refers to versions smaller than 200 of MzScheme (103, 101, ...).
  ; mzscheme-200 refers to version 200 - 209. As of April 2005, version 209 is the latest version.
  ; mzscheme-300 refers to version 300+. 
  ; drscheme refers to versions smaller than 200 of DrScheme.
  ; drscheme-300 refers to version 300 or larger of DrScheme.
  ; The value part of the cons pair should be a symbol or a string.

  (scheme-system . "gosh")                  ; <== Edit here


  ; On which platform do you install LAML: windows, unix, or mac.
  ; If you use linux use unix here.
  ; If you use max OSX, use unix here too.
  ; The given value should be a symbol or a string

  (laml-platform . "unix")                   ; <== Edit here


  ; Which operating system do you use: win98, win95, nt40, win2000,
  ; solaris-6, solaris-7, or linux.
  ; If you use Windows XP or Vista you should write win2000 below.
  ; If you use solaris in a newer version than 7, you should write solaris-7.
  ; The value of operating-system should be a symbol or a string.

  (operating-system . "linux")                ; <== Edit here


  ; The absolute path to your Scheme interpreter.
  ; The value must be a string (an absolute file path) or the value #f 
  ; (#f means boolean false).
  ; Use forward slashes in the path.
  ; Do not include any file extension (such as '.exe').
  ; If your Scheme system is drscheme or drscheme-300 use the value #f.

  (scheme-exec . "/usr/local/bin/gosh")           ; <== Edit here


  ; The full path to your emacs init file (.emacs file).
  ; If you give the path to you emacs init file here, you allow the
  ; LAML configuration program to change your .emacs file.
  ; If you do not have an emacs init file, the LAML configuration program
  ; will make one for you. In case you do NOT want the LAML configuration 
  ; process to modify your emacs init file, the value of this property should
  ; be #f (which is Scheme's representation of 'false').

  (emacs-init-file . #f)             ; <== Edit here


  ; The full path to you laml init file (such as .laml). 
  ; Mostly for advanced laml users. 
  ; The value of laml-init-file must be a string (file path), or the boolean #f.
  ; The laml init file allows you to customize and extend LAML.
  ; The laml init file is loaded by the function begin-laml, which always should be
  ; called when program loading has been completed.
  ; The laml init file is only loaded if it actually exists.
  ; If you delete this clause, or if you specify the value #f,
  ; no laml init file is supported by your installation.

  (laml-init-file . #f)              ; <== Edit here


  ; Control of Emacs keybindings.
  ; Possible values are "original", "hygienic", and "none".
  ; Some original keybindings may be in conflict with other Emacs key bindings,
  ; but they are short and convenient.
  ; Hygienic keybindings all start with C-c, and as such they do not conflict
  ; with other keybindings. If "none" is specified, no keybindings are will be made.
  ; Menu bindings will be made even if "none" is specified as the value of 
  ; emacs-keybindings.

  (emacs-keybindings . "hygienic")           ; <== Edit here


  ; Leno is a LAML based system for production of slides and teaching
  ; material.  If you want Emacs support of LENO, the value of
  ; leno-emacs-support should be #t.  If not, it should be #f. If you
  ; select Emacs support for LENO, a number of key bindings and
  ; menu bindings will be in effect.
  ; Use the value #f if you install SchemeDoc

  (leno-emacs-support . #f)                  ; <== Edit here


  ; LAML SchemeDoc is a tool for comments from Scheme source files.
  ; If you want Emacs support LAML Schemedoc (including SchemeDoc
  ; support when you work on Scheme source files in scheme-mode) the value of
  ; schemedoc-emacs-support should be #t.  If not, it should be #f.

  (schemedoc-emacs-support . #f)            ; <== Edit here


  ; The Scheme elucidator is a LAML based system for production of
  ; elucidative programs (programs with documentation). If you want
  ; Emacs support of the Scheme Elucidator, the value of
  ; elucidator-emacs-support should be #t.  If not, it should be #f.
  ; If you select Emacs support for the elucidator,
  ; a number of key bindings and menu bindings will be in effect.
  ; You may use the value #t if you install SchemeDoc, because
  ; the SchemeDoc distribution includes the Scheme Elucidator.

  (elucidator-emacs-support . #f)            ; <== Edit here


  ; The LAML photo show tool supports the generation of HTML
  ; files that controls the presentation of digital photos. 
  ; The value #t will give some support of the LAML photo show from Emacs.
  ; Use the value #f if you install SchemeDoc

  (photoshow-emacs-support . #f)            ; <== Edit here


  ; The LAML chords tool supports the generation of HTML
  ; files for songs with chords.
  ; The value #t will give provide support of the LAML chords system from Emacs.
  ; Use the value #f if you install SchemeDoc

  (chords-emacs-support . #f)            ; <== Edit here


)

追記

(define (laml-canonical-command-line) `(laml ,@*argv* #f))

の方が良いかも。