summaryrefslogtreecommitdiff
path: root/scheme
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
parent9d64bcb33f7ac1b3a06220842d04ce3c0534948e (diff)
downloadgeiser-guile-283e6f040449bb4f740991956007332c48308b38.tar.gz
geiser-guile-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')
-rw-r--r--scheme/guile/geiser/doc.scm85
-rw-r--r--scheme/plt/geiser/autodoc.ss97
2 files changed, 47 insertions, 135 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)
diff --git a/scheme/plt/geiser/autodoc.ss b/scheme/plt/geiser/autodoc.ss
index 6607a94..2fe3a83 100644
--- a/scheme/plt/geiser/autodoc.ss
+++ b/scheme/plt/geiser/autodoc.ss
@@ -31,39 +31,32 @@
(eval `(help ,symbol #:from ,mod)))))
(eval `(help ,symbol))))
-(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-values
- define-method define-class define-generic define-struct
- define-syntax define-syntaxes -define-syntax))
- (and (= 2 (length form))
- (memq (car form) defforms)
- (car form)))
-
-(define (describe-application form)
- (let* ((fun (car form))
- (loc (symbol-location* fun))
- (name (car loc))
- (path (cdr loc))
- (sgn (and path (find-signature path name fun))))
- (and sgn
- (list (cons 'signature (format-signature fun sgn))
- (cons 'position (find-position sgn form))
- (cons 'module (module-path-name->name path))))))
+(define (autodoc ids)
+ (if (not (list? ids))
+ '()
+ (map (lambda (id) (or (autodoc* id) (list id))) ids)))
+
+(define (autodoc* id)
+ (and
+ (symbol? id)
+ (let* ((loc (symbol-location* id))
+ (name (car loc))
+ (path (cdr loc))
+ (sgn (and path (find-signature path name id))))
+ (and sgn
+ `(,id
+ (name . ,name)
+ ,@(format-signature sgn)
+ (module . ,(module-path-name->name path)))))))
+
+(define (format-signature sign)
+ (if (signature? sign)
+ `((required ,@(signature-required sign))
+ (optional ,@(signature-optional sign)
+ ,@(let ((rest (signature-rest sign)))
+ (if rest (list "...") '())))
+ (key ,@(signature-keys sign)))
+ '()))
(define signatures (make-hash))
@@ -167,44 +160,6 @@
(opt-no (- max-val min-val)))
(make-signature (args 0 min-val) (args min-val opt-no) '() #f)))))
-(define (format-signature fun sign)
- (cond ((symbol? sign) (cons fun sign))
- ((signature? sign)
- (let ((req (signature-required sign))
- (opt (signature-optional sign))
- (keys (signature-keys sign))
- (rest (signature-rest sign)))
- `(,fun
- ,@req
- ,@(if (null? opt) opt (cons 'geiser-opt_marker opt))
- ,@(if (null? keys) keys (cons 'geiser-key_maker keys))
- ,@(if rest (list 'geiser-rest_marker rest) '()))))
- (else #f)))
-
-(define (find-position sign form)
- (if (signature? sign)
- (let* ((lf (length form))
- (lf-1 (- lf 1)))
- (if (= 1 lf) 0
- (let ((req (length (signature-required sign)))
- (opt (length (signature-optional sign)))
- (keys (map (lambda (k) (symbol->keyword (if (list? k) (car k) k)))
- (signature-keys sign)))
- (rest (signature-rest sign)))
- (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)))))))
- 0))
-
(define (update-module-cache path . form)
(when (and (string? path)
(or (null? form)