summaryrefslogtreecommitdiff
path: root/scheme/guile
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2009-08-17 04:18:02 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2009-08-17 04:18:02 +0200
commit283e6f040449bb4f740991956007332c48308b38 (patch)
treea33bb00a155f11149b361f97aeebe2c0a1cc05ae /scheme/guile
parent9d64bcb33f7ac1b3a06220842d04ce3c0534948e (diff)
downloadgeiser-chez-283e6f040449bb4f740991956007332c48308b38.tar.gz
geiser-chez-283e6f040449bb4f740991956007332c48308b38.tar.bz2
Simpler, more correct and efficient autodoc implementation.
Not that it was difficult: it's replacing an ugly kludge.
Diffstat (limited to 'scheme/guile')
-rw-r--r--scheme/guile/geiser/doc.scm85
1 files changed, 21 insertions, 64 deletions
diff --git a/scheme/guile/geiser/doc.scm b/scheme/guile/geiser/doc.scm
index 3f060e3..d951f1c 100644
--- a/scheme/guile/geiser/doc.scm
+++ b/scheme/guile/geiser/doc.scm
@@ -37,76 +37,33 @@
#:use-module (oop goops)
#:use-module (srfi srfi-1))
-(define (autodoc form)
- (cond ((null? form) #f)
- ((symbol? form) (describe-application (list form)))
- ((not (pair? form)) #f)
- ((not (list? form)) (autodoc (pair->list form)))
- ((define-head? form) => autodoc)
- (else (autodoc/list form))))
-
-(define (autodoc/list form)
- (let ((lst (last form)))
- (cond ((and (symbol? lst) (describe-application (list lst))))
- ((and (pair? lst) (not (memq (car lst) '(quote))) (autodoc lst)))
- (else (describe-application form)))))
-
-(define (define-head? form)
- (define defforms '(define define* define-macro define-macro*
- define-method define-class define-generic))
- (and (= 2 (length form))
- (memq (car form) defforms)
- (car form)))
-
-(define (describe-application form)
- (let* ((fun (car form))
- (args (obj-args (symbol->object fun))))
+(define (autodoc ids)
+ (if (not (list? ids))
+ '()
+ (map (lambda (id) (or (autodoc* id) (list id))) ids)))
+
+(define (autodoc* id)
+ (let ((args (obj-args (symbol->object id))))
(and args
- (list (cons 'signature (signature fun args))
- (cons 'position (find-position args form))
- (cons 'module (symbol-module fun))))))
+ `(,@(signature id args)
+ (module . ,(symbol-module id))))))
(define (object-signature name obj)
(let ((args (obj-args obj)))
(and args (signature name args))))
-(define (signature fun args)
- (let ((req (arglst args 'required))
- (opt (arglst args 'optional))
- (key (arglst args 'keyword))
- (rest (assq-ref args 'rest)))
- (let ((sgn `(,fun ,@req
- ,@(if (not (null? opt)) (cons 'geiser-opt_marker opt) '())
- ,@(if (not (null? key)) (cons 'geiser-key_maker key) '()))))
- (if rest `(,@sgn geiser-rest_marker ,rest) sgn))))
-
-(define (find-position args form)
- (let* ((lf (length form))
- (lf-1 (- lf 1)))
- (if (= 1 lf) 0
- (let ((req (length (arglst args 'required)))
- (opt (length (arglst args 'optional)))
- (keys (map (lambda (k) (symbol->keyword (if (list? k) (car k) k)))
- (arglst args 'keyword)))
- (rest (assq-ref args 'rest)))
- (cond ((<= lf (+ 1 req)) lf-1)
- ((<= lf (+ 1 req opt)) (if (> opt 0) lf lf-1))
- ((or (memq (last form) keys)
- (memq (car (take-right form 2)) keys)) =>
- (lambda (sl)
- (+ 2 req
- (if (> opt 0) (+ 1 opt) 0)
- (- (length keys) (length sl)))))
- (else (+ 1 req
- (if (> opt 0) (+ 1 opt) 0)
- (if (null? keys) 0 (+ 1 (length keys)))
- (if rest 2 0))))))))
-
-(define (arglst args kind)
- (let ((args (assq-ref args kind)))
- (cond ((or (not args) (null? args)) '())
- ((list? args) args)
- (else (list args)))))
+(define (signature id args)
+ (define (arglst kind)
+ (let ((args (assq-ref args kind)))
+ (cond ((or (not args) (null? args)) '())
+ ((list? args) args)
+ (else (list args)))))
+ `(,id
+ (required ,@(arglst 'required))
+ (optional ,@(arglst 'optional)
+ ,@(let ((rest (assq-ref args 'rest)))
+ (if rest (list "...") '())))
+ (key ,@(arglst 'keyword))))
(define (obj-args obj)
(cond ((not obj) #f)