diff --git a/scribble-lib/scribble/private/doc-begin.rkt b/scribble-lib/scribble/private/doc-begin.rkt index c41e555a0c..e7e51f2e77 100644 --- a/scribble-lib/scribble/private/doc-begin.rkt +++ b/scribble-lib/scribble/private/doc-begin.rkt @@ -66,22 +66,15 @@ #'(check-pre-part s (quote-syntax loc))))])) (define (check-pre-part v loc-stx) - (if (pre-part? v) - v - (error - (format - "~a: not valid in document body (need a pre-part for decode) in: ~e" - (cond - [(and (syntax-source loc-stx) - (syntax-line loc-stx)) - (format "~a:~a:~a" - (syntax-source loc-stx) - (syntax-line loc-stx) - (syntax-column loc-stx))] - [(and (syntax-source loc-stx) - (syntax-position loc-stx)) - (format "~a:::~a" - (syntax-source loc-stx) - (syntax-position loc-stx))] - [else 'document]) - v)))) + (unless (pre-part? v) + (error + (format + "~a: not valid in document body (need a pre-part for decode) in: ~e" + (cond + [(and (syntax-source loc-stx) (syntax-line loc-stx)) + (format "~a:~a:~a" (syntax-source loc-stx) (syntax-line loc-stx) (syntax-column loc-stx))] + [(and (syntax-source loc-stx) (syntax-position loc-stx)) + (format "~a:::~a" (syntax-source loc-stx) (syntax-position loc-stx))] + [else 'document]) + v))) + v) diff --git a/scribble-lib/scribble/private/manual-bind.rkt b/scribble-lib/scribble/private/manual-bind.rkt index fb8b9962df..58cba2d134 100644 --- a/scribble-lib/scribble/private/manual-bind.rkt +++ b/scribble-lib/scribble/private/manual-bind.rkt @@ -59,10 +59,7 @@ (define hovers (make-weak-hasheq)) (define (intern-hover-style text) (let ([text (datum-intern-literal text)]) - (or (hash-ref hovers text #f) - (let ([s (make-style #f (list (make-hover-property text)))]) - (hash-set! hovers text s) - s)))) + (hash-ref! hovers text (λ () (make-style #f (list (make-hover-property text))))))) (define (annote-exporting-library e) (make-delayed-element @@ -71,15 +68,14 @@ (if (and from (pair? from)) (make-element (intern-hover-style - (string-append - "Provided from: " - (string-join (map ~s from) ", ") - (let ([from-pkgs (resolve-get/tentative p ri '(exporting-packages #f))]) - (if (and from-pkgs (pair? from-pkgs)) - (string-append - " | Package: " - (string-join (map ~a from-pkgs) ", ")) - "")))) + (string-join (map ~s from) + ", " + #:before-first "Provided from: " + #:after-last + (let ([from-pkgs (resolve-get/tentative p ri '(exporting-packages #f))]) + (if (and from-pkgs (pair? from-pkgs)) + (string-append " | Package: " (string-join (map ~a from-pkgs) ", ")) + "")))) e) e)) (lambda () e) @@ -114,30 +110,30 @@ (lambda (x add) x))) (let ([lib (or (for/or ([lib (in-list (or source-libs null))]) - (let ([checker - (hash-ref - checkers lib - (lambda () - (define ns-id - (let ([ns (make-base-empty-namespace)]) - (parameterize ([current-namespace ns]) - ;; A `(namespace-require `(for-label ,lib))` can - ;; fail if `lib` provides different bindings of the - ;; same name at different phases. We can require phases - ;; 1 and 0 separately, in which case the phase-0 - ;; binding shadows the phase-1 one in that case. - ;; This strategy only works for documenting bindings - ;; at phases 0 and 1, though. - (namespace-require `(just-meta 1 (for-label ,lib))) - (namespace-require `(just-meta 0 (for-label ,lib))) - (namespace-syntax-introduce (datum->syntax #f 'x))))) - (define (checker id intro) - (free-label-identifier=? - (intro (datum->syntax ns-id (syntax-e id)) 'add) - (intro id 'add))) - (hash-set! checkers lib checker) - checker))]) - (and (checker id intro) lib))) + (define checker + (hash-ref checkers + lib + (lambda () + (define ns-id + (let ([ns (make-base-empty-namespace)]) + (parameterize ([current-namespace ns]) + ;; A `(namespace-require `(for-label ,lib))` can + ;; fail if `lib` provides different bindings of the + ;; same name at different phases. We can require phases + ;; 1 and 0 separately, in which case the phase-0 + ;; binding shadows the phase-1 one in that case. + ;; This strategy only works for documenting bindings + ;; at phases 0 and 1, though. + (namespace-require `(just-meta 1 (for-label ,lib))) + (namespace-require `(just-meta 0 (for-label ,lib))) + (namespace-syntax-introduce (datum->syntax #f 'x))))) + (define (checker id intro) + (free-label-identifier=? (intro (datum->syntax ns-id (syntax-e id)) + 'add) + (intro id 'add))) + (hash-set! checkers lib checker) + checker))) + (and (checker id intro) lib)) (and (pair? libs) (car libs)))]) (and lib (module-path-index->taglet (module-path-index-join lib #f))))) @@ -198,79 +194,64 @@ #:show-libs? [show-libs? #t]) ;; This function could have more optional argument to select ;; whether to index the id, include a toc link, etc. - (let ([dep? #t]) - (define maker - (if form? - (id-to-form-target-maker id dep?) - (id-to-target-maker id dep?))) - (define-values (elem elem-ref) - (if show-libs? - (definition-site (syntax-e id) id form?) - (values (to-element id #:defn? #t) - (to-element id)))) - (if maker - (maker elem - (lambda (tag) - (let ([elem - (if index? - (make-index-element - #f (list elem) tag - (list (datum-intern-literal (symbol->string (syntax-e id)))) - (list elem) - (and show-libs? - (with-exporting-libraries - (lambda (libs) - (make-exported-index-desc (syntax-e id) - libs))))) - elem)]) - (make-target-element #f (list elem) tag)))) - elem))) + (define dep? #t) + (define maker + (if form? + (id-to-form-target-maker id dep?) + (id-to-target-maker id dep?))) + (define-values (elem elem-ref) + (if show-libs? + (definition-site (syntax-e id) id form?) + (values (to-element id #:defn? #t) (to-element id)))) + (if maker + (maker elem + (lambda (tag) + (let ([elem (if index? + (make-index-element + #f + (list elem) + tag + (list (datum-intern-literal (symbol->string (syntax-e id)))) + (list elem) + (and show-libs? + (with-exporting-libraries + (lambda (libs) (make-exported-index-desc (syntax-e id) libs))))) + elem)]) + (make-target-element #f (list elem) tag)))) + elem)) (define (make-binding-redirect-elements mod-path redirects) (define taglet (module-path-index->taglet (module-path-index-join mod-path #f))) (make-element #f - (map - (lambda (redirect) - (define id (car redirect)) - (define form? (cadr redirect)) - (define path (caddr redirect)) - (define anchor (cadddr redirect)) - (define (make-one kind) - (make-redirect-target-element - #f - null - (intern-taglet (list kind (list taglet id))) - path - anchor)) - (make-element - #f - (list (make-one (if form? 'form 'def)) - (make-dep (list taglet id) null) - (let ([str (datum-intern-literal (symbol->string id))]) - (make-index-element #f - null - (intern-taglet - (list (if form? 'form 'def) - (list taglet id))) - (list str) - (list - (make-element - symbol-color - (list - (make-element - (if form? - syntax-link-color - value-link-color) - (list str))))) - (make-exported-index-desc* - id - (list mod-path) - (hash 'kind (if form? - "syntax" - "procedure")))))))) - redirects))) + (for/list ([redirect (in-list redirects)]) + (define id (car redirect)) + (define form? (cadr redirect)) + (define path (caddr redirect)) + (define anchor (cadddr redirect)) + (define (make-one kind) + (make-redirect-target-element #f + null + (intern-taglet (list kind (list taglet id))) + path + anchor)) + (make-element + #f + (list (make-one (if form? 'form 'def)) + (make-dep (list taglet id) null) + (let ([str (datum-intern-literal (symbol->string id))]) + (make-index-element + #f + null + (intern-taglet (list (if form? 'form 'def) (list taglet id))) + (list str) + (list (make-element symbol-color + (list (make-element (if form? syntax-link-color value-link-color) + (list str))))) + (make-exported-index-desc* id + (list mod-path) + (hash 'kind (if form? "syntax" "procedure")))))))))) (define (make-dep t content) diff --git a/scribble-lib/scribble/private/manual-class.rkt b/scribble-lib/scribble/private/manual-class.rkt index 7cff96cfe0..af8c1a5e15 100644 --- a/scribble-lib/scribble/private/manual-class.rkt +++ b/scribble-lib/scribble/private/manual-class.rkt @@ -48,14 +48,9 @@ (define (id-info id) (define b (identifier-label-binding id)) - (if b - (list (caddr b) - (list-ref b 3) - (list-ref b 4) - (list-ref b 5) - (list-ref b 6)) - (error 'scribble "no class/interface/mixin information for identifier: ~e" - id))) + (unless b + (error 'scribble "no class/interface/mixin information for identifier: ~e" id)) + (list (caddr b) (list-ref b 3) (list-ref b 4) (list-ref b 5) (list-ref b 6))) (define (make-inherited-table r d ri decl) (define start @@ -155,11 +150,11 @@ null)) (define (build-body decl body) - `(,@(map (lambda (i) - (cond [(constructor? i) ((constructor-def i))] - [(meth? i) ((meth-def i))] - [else i])) - body) + `(,@(for/list ([i (in-list body)]) + (cond + [(constructor? i) ((constructor-def i))] + [(meth? i) ((meth-def i))] + [else i])) ,(make-delayed-block (lambda (r d ri) (make-inherited-table r d ri decl))))) (define (*include-class/title decl link?) @@ -408,17 +403,13 @@ (datum->syntax n (syntax-e n) (list 'src 1 3 4 1))) (list 'src 1 0 1 5))] [(((kw ...) ...) ...) - (map (lambda (ids) - (map (lambda (arg) - (if (and (pair? (syntax-e arg)) - (eq? (syntax-e #'mode) 'new)) - (list (string->keyword - (symbol->string - (syntax-e - (car (syntax-e arg)))))) - null)) - (syntax->list ids))) - (syntax->list #'((arg ...) ...)))]) + (for/list ([ids (in-list (syntax->list #'((arg ...) ...)))]) + (map (lambda (arg) + (if (and (pair? (syntax-e arg)) (eq? (syntax-e #'mode) 'new)) + (list (string->keyword + (symbol->string (syntax-e (car (syntax-e arg)))))) + null)) + (syntax->list ids)))]) #'(make-constructor (lambda () (defproc* #:mode mode #:within name [[(make [kw ... . arg] ...) result] ...] diff --git a/scribble-lib/scribble/private/manual-code.rkt b/scribble-lib/scribble/private/manual-code.rkt index 740d828bd0..3b3b228143 100644 --- a/scribble-lib/scribble/private/manual-code.rkt +++ b/scribble-lib/scribble/private/manual-code.rkt @@ -340,16 +340,19 @@ (list 'function start end 1)] ; this looses information [_ tok]))) - (define (make-test-result lst) - (define-values (res _) - (for/fold ([result null] [count 12]) + (define (make-test-result lst) + (define res + (for/fold ([result null] + [count 12] + #:result result) ([p lst]) (define next (+ count (second p))) (define r (if (eq? (first p) 'function) 1 0)) - (values - (cons (list (first p) count next r) result) - next))) - (list* `(function 0 5 1) `(white-space 5 6 0) `(function 6 12 1) `(function 6 12 1) + (values (cons (list (first p) count next r) result) next))) + (list* `(function 0 5 1) + `(white-space 5 6 0) + `(function 6 12 1) + `(function 6 12 1) (reverse res))) (check-equal? diff --git a/scribble-lib/scribble/private/manual-mod.rkt b/scribble-lib/scribble/private/manual-mod.rkt index 9f680e93b6..d808e32911 100644 --- a/scribble-lib/scribble/private/manual-mod.rkt +++ b/scribble-lib/scribble/private/manual-mod.rkt @@ -299,12 +299,9 @@ pkg-spec)))) libs-specs)) (append (if link-target? - (map (lambda (modpath) - (make-part-tag-decl - (intern-taglet - `(mod-path ,(datum-intern-literal - (element->string modpath)))))) - modpaths) + (for/list ([modpath (in-list modpaths)]) + (make-part-tag-decl (intern-taglet `(mod-path ,(datum-intern-literal + (element->string modpath)))))) null) (flow-paragraphs (decode-flow content))))))) @@ -334,12 +331,12 @@ #'(list pkg ...) #'#f)]) (let ([libs (syntax->list #'(lib ... plib ...))]) - (for ([l libs]) - (unless (or (syntax-case l (unquote) - [(unquote _) #t] - [_ #f]) - (module-path? (syntax->datum l))) - (raise-syntax-error #f "not a module path" stx l))) + (for ([l libs] + #:unless (or (syntax-case l (unquote) + [(unquote _) #t] + [_ #f]) + (module-path? (syntax->datum l)))) + (raise-syntax-error #f "not a module path" stx l)) (when (null? libs) (raise-syntax-error #f "need at least one module path" stx)) #'(*declare-exporting `(lib ...) `(plib ...) packages)))])) diff --git a/scribble-lib/scribble/private/manual-proc.rkt b/scribble-lib/scribble/private/manual-proc.rkt index 89c3d59e3f..76f51b2598 100644 --- a/scribble-lib/scribble/private/manual-proc.rkt +++ b/scribble-lib/scribble/private/manual-proc.rkt @@ -857,42 +857,38 @@ (make-just-context (car name) (car (syntax-e stx-id))) stx-id)]) - (if link? - (let () - (define (gen defn?) - ((if defn? annote-exporting-library values) - (to-element #:defn? defn? name-id))) - (define content (gen #t)) - (define ref-content (gen #f)) - (make-target-element* - (lambda (s c t) - (make-toc-target2-element s c t ref-content)) - (if (pair? name) - (car (syntax-e stx-id)) - stx-id) - content - (let ([name (if (pair? name) (car name) name)]) - (list* (list 'info name) - (list 'type 'struct: name) - (list 'predicate name '?) - (append - (if cname-id - (list (list 'constructor (syntax-e cname-id))) - null) - (map (lambda (f) - (list 'accessor name '- - (field-name f))) - fields) - (filter-map - (lambda (f) - (and (or (not immutable?) - (and (pair? (car f)) - (memq '#:mutable - (car f)))) - (list 'mutator 'set- name '- - (field-name f) '!))) - fields)))))) - (to-element #:defn? #t name-id)))]) + (cond + [link? + (define (gen defn?) + ((if defn? annote-exporting-library values) (to-element #:defn? defn? + name-id))) + (define content (gen #t)) + (define ref-content (gen #f)) + (make-target-element* + (lambda (s c t) (make-toc-target2-element s c t ref-content)) + (if (pair? name) + (car (syntax-e stx-id)) + stx-id) + content + (let ([name (if (pair? name) + (car name) + name)]) + (list* (list 'info name) + (list 'type 'struct: name) + (list 'predicate name '?) + (append + (if cname-id + (list (list 'constructor (syntax-e cname-id))) + null) + (map (lambda (f) (list 'accessor name '- (field-name f))) + fields) + (filter-map + (lambda (f) + (and (or (not immutable?) + (and (pair? (car f)) (memq '#:mutable (car f)))) + (list 'mutator 'set- name '- (field-name f) '!))) + fields)))))] + [else (to-element #:defn? #t name-id)]))]) (if (pair? name) (make-element #f @@ -913,17 +909,17 @@ (map sym-length (append (if (pair? name) name (list name)) (map field-name fields))) - (map (lambda (f) - (match (car f) - [(? symbol?) 0] - [(list name) 2] ;; the extra [ ] - [(list* name field-opts) - ;; '[' ']' - (apply + 2 - (for/list ([field-opt (in-list field-opts)]) - ;; and " #:" - (+ 3 (string-length (keyword->string field-opt)))))])) - fields)))]) + (for/list ([f (in-list fields)]) + (match (car f) + [(? symbol?) 0] + [(list name) 2] ;; the extra [ ] + [(list* name field-opts) + ;; '[' ']' + (apply + + 2 + (for/list ([field-opt (in-list field-opts)]) + ;; and " #:" + (+ 3 (string-length (keyword->string field-opt)))))]))))]) (cond [(and (short-width . < . max-proto-width) (not keyword-modifiers?)) @@ -931,9 +927,7 @@ (make-omitable-paragraph (list (to-element - `(,(racket struct) - ,the-name - ,(map field-view fields)))))] + (list (racket struct) the-name (map field-view fields)))))] [else ;; Multi-line view (leaving out last paren if keywords follow): (define one-right-column? diff --git a/scribble-lib/scribble/private/manual-unit.rkt b/scribble-lib/scribble/private/manual-unit.rkt index 5af549ec24..e66c882e6a 100644 --- a/scribble-lib/scribble/private/manual-unit.rkt +++ b/scribble-lib/scribble/private/manual-unit.rkt @@ -35,8 +35,7 @@ (define (signature-desc . l) (make-sig-desc l)) -(provide/contract - [signature-desc (() () #:rest (listof pre-flow?) . ->* . sig-desc?)]) +(provide (contract-out [signature-desc (() () #:rest (listof pre-flow?) . ->* . sig-desc?)])) (define (*defsignature stx-id supers body-thunk indent?) (*defthing diff --git a/scribble-lib/scribble/private/manual-utils.rkt b/scribble-lib/scribble/private/manual-utils.rkt index a42e3fa2c8..8057f09afc 100644 --- a/scribble-lib/scribble/private/manual-utils.rkt +++ b/scribble-lib/scribble/private/manual-utils.rkt @@ -8,14 +8,15 @@ racket/list) (provide doc-prefix) -(provide/contract - [spacer element?] - [to-flow (content? . -> . flow?)] - [flow-spacer flow?] - [flow-spacer/n (-> exact-nonnegative-integer? flow?)] - [flow-empty-line flow?] - [make-table-if-necessary ((or/c style? string?) list? . -> . (list/c (or/c omitable-paragraph? table?)))] - [current-display-width (parameter/c exact-nonnegative-integer?)]) +(provide (contract-out + [spacer element?] + [to-flow (content? . -> . flow?)] + [flow-spacer flow?] + [flow-spacer/n (-> exact-nonnegative-integer? flow?)] + [flow-empty-line flow?] + [make-table-if-necessary + ((or/c style? string?) list? . -> . (list/c (or/c omitable-paragraph? table?)))] + [current-display-width (parameter/c exact-nonnegative-integer?)])) (define spacer (hspace 1)) diff --git a/scribble-lib/scribble/private/manual-vars.rkt b/scribble-lib/scribble/private/manual-vars.rkt index 3321674190..a707d8270e 100644 --- a/scribble-lib/scribble/private/manual-vars.rkt +++ b/scribble-lib/scribble/private/manual-vars.rkt @@ -17,8 +17,7 @@ (define-struct (box-splice splice) ()) -(provide/contract - [struct (box-splice splice) ([run list?])]) ; XXX ugly copying +(provide (contract-out (struct (box-splice splice) ([run list?])))) ; XXX ugly copying (provide deftogether *deftogether with-racket-variables with-togetherable-racket-variables @@ -172,47 +171,42 @@ (list (make-table boxed-style - (map - (lambda (box) - (unless (and (box-splice? box) - (= 1 (length (splice-run box))) - (nested-flow? (car (splice-run box))) - (eq? vertical-inset-style (nested-flow-style (car (splice-run box)))) - (let ([l (nested-flow-blocks (car (splice-run box)))]) - (= 1 (length l)) - (table? (car l)) - (eq? boxed-style (table-style (car l))))) - (error 'deftogether - "element is not a boxing splice containing a single nested-flow with a single table: ~e" - box)) - (list (make-flow (list (make-table - "together" - (table-flowss (car (nested-flow-blocks (car (splice-run box)))))))))) - boxes)))) + (for/list ([box (in-list boxes)]) + (unless (and (box-splice? box) + (= 1 (length (splice-run box))) + (nested-flow? (car (splice-run box))) + (eq? vertical-inset-style (nested-flow-style (car (splice-run box)))) + (let ([l (nested-flow-blocks (car (splice-run box)))]) + (= 1 (length l)) + (table? (car l)) + (eq? boxed-style (table-style (car l))))) + (error + 'deftogether + "element is not a boxing splice containing a single nested-flow with a single table: ~e" + box)) + (list (make-flow (list (make-table "together" + (table-flowss (car (nested-flow-blocks + (car (splice-run box))))))))))))) (body-thunk)))) (define-syntax (deftogether stx) (syntax-parse stx [(_ (def ...+) . body) (with-syntax ([((_ (lit ...) (var ...) decl) ...) - (map (lambda (def) - (define exp-def - (local-expand - def - (list (make-deftogether-tag)) - (cons - #'with-togetherable-racket-variables* - (kernel-form-identifier-list)))) - (syntax-case exp-def (with-togetherable-racket-variables*) - [(with-togetherable-racket-variables* lits vars decl) - exp-def] - [_ - (raise-syntax-error - #f - "sub-form is not a documentation form that can be combined" - stx - def)])) - (syntax->list #'(def ...)))]) + (for/list ([def (in-list (syntax->list #'(def ...)))]) + (define exp-def + (local-expand def + (list (make-deftogether-tag)) + (cons #'with-togetherable-racket-variables* + (kernel-form-identifier-list)))) + (syntax-case exp-def (with-togetherable-racket-variables*) + [(with-togetherable-racket-variables* lits vars decl) exp-def] + [_ + (raise-syntax-error + #f + "sub-form is not a documentation form that can be combined" + stx + def)]))]) #'(with-togetherable-racket-variables (lit ... ...) (var ... ...)