Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated Resyntax fixes #476

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions scribble-lib/scribble/private/indirect-renderer.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@
(define/override (get-suffix) target-suffix)
(define/override (render srcs dests ri)
(define tmp-dir
(make-temporary-file
(format "scribble-~a-to-~a-~~a"
(dotless base-suffix) (dotless target-suffix))
'directory))
(make-temporary-directory
(format "scribble-~a-to-~a-~~a" (dotless base-suffix) (dotless target-suffix))))
(define (cleanup)
(when (directory-exists? tmp-dir) (delete-directory/files tmp-dir)))
(with-handlers ([void (lambda (e) (cleanup) (raise e))])
(define tmp-dests
(map (lambda (dest)
(build-path tmp-dir
(path-replace-suffix (file-name-from-path dest)
base-suffix)))
dests))
(for/list ([dest (in-list dests)])
(build-path tmp-dir (path-replace-suffix (file-name-from-path dest) base-suffix))))
(set! tmp-dest-dir tmp-dir)
;; it would be better if it's ok to change current-directory for this
(super render srcs tmp-dests ri)
Expand Down
4 changes: 3 additions & 1 deletion scribble-lib/scribble/private/manual-bib.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
`(" " ,@(decode-content (list location)) ,(if date "," "."))
null)
(if date `(" " ,@(decode-content (list date)) ".") null)
(if url `(" " ,(link url (tt url))) null)
(if url (list " "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bad...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jackfirth I think this occurs because Resyntax invokes range formatting on only the subexpression, so it doesn't format the entire if expression...

(Actually fmt ideally should collapse (list " " (link url (tt url))) into one line, circumventing this issue, but without shadowing, link is a special form that should be formatted vertically, so that's why fmt introduces a newline)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's definitely the cause. I'm not sure how to fix it from the Resyntax side.

(link url
(tt url))) null)
(if note (decode-content (list note)) null)))))

(define-on-demand bib-style (make-style "RBibliography" scheme-properties))
Expand Down
189 changes: 85 additions & 104 deletions scribble-lib/scribble/private/manual-bind.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)))))
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 8 additions & 13 deletions scribble-lib/scribble/private/manual-class.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?)
Expand Down
57 changes: 27 additions & 30 deletions scribble-lib/scribble/private/manual-style.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
itemize
aux-elem
code-inset)
(provide/contract [filebox (((or/c core:element? string?)) () #:rest (listof pre-flow?) . ->* . block?)])
(provide (contract-out
[filebox (((or/c core:element? string?)) () #:rest (listof pre-flow?) . ->* . block?)]))

(define styling-f/c
(() () #:rest (listof pre-content?) . ->* . element?))
(-> pre-content? ... element?))
(define-syntax-rule (provide-styling id ...)
(provide/contract [id styling-f/c] ...))
(provide-styling racketmodfont racketoutput
Expand Down Expand Up @@ -53,35 +54,32 @@

(provide void-const
undefined-const)
(provide/contract
[PLaneT element?]
[hash-lang (-> element?)]
[etc element?]
[inset-flow (() () #:rest (listof pre-content?) . ->* . nested-flow?)]
[litchar (() () #:rest (listof string?) . ->* . element?)]
[t (() () #:rest (listof pre-content?) . ->* . paragraph?)]
[exec (() () #:rest (listof content?) . ->* . element?)]
[commandline (() () #:rest (listof content?) . ->* . paragraph?)]
[menuitem (string? string? . -> . element?)])
(provide (contract-out [PLaneT element?]
[hash-lang (-> element?)]
[etc element?]
[inset-flow (() () #:rest (listof pre-content?) . ->* . nested-flow?)]
[litchar (() () #:rest (listof string?) . ->* . element?)]
[t (() () #:rest (listof pre-content?) . ->* . paragraph?)]
[exec (() () #:rest (listof content?) . ->* . element?)]
[commandline (() () #:rest (listof content?) . ->* . paragraph?)]
[menuitem (string? string? . -> . element?)]))

(define PLaneT (make-element "planetName" '("PLaneT")))

(define etc (make-element #f (list "etc" ._)))

(define (litchar . strs)
(let ([s (string-append* (map (lambda (s) (regexp-replace* "\n" s " "))
strs))])
(cond
[(regexp-match? #rx"^ *$" s) (make-element input-background-color (list (hspace (string-length s))))]
[else
(define ^spaces (car (regexp-match-positions #rx"^ *" s)))
(define $spaces (car (regexp-match-positions #rx" *$" s)))
(make-element
input-background-color
(list (hspace (cdr ^spaces))
(make-element input-color
(list (substring s (cdr ^spaces) (car $spaces))))
(hspace (- (cdr $spaces) (car $spaces)))))])))
(define s (string-append* (map (lambda (s) (regexp-replace* "\n" s " ")) strs)))
(cond
[(regexp-match? #rx"^ *$" s)
(make-element input-background-color (list (hspace (string-length s))))]
[else
(define ^spaces (car (regexp-match-positions #rx"^ *" s)))
(define $spaces (car (regexp-match-positions #rx" *$" s)))
(make-element input-background-color
(list (hspace (cdr ^spaces))
(make-element input-color (list (substring s (cdr ^spaces) (car $spaces))))
(hspace (- (cdr $spaces) (car $spaces)))))]))

(define (onscreen . str)
(make-element 'sf (decode-content str)))
Expand Down Expand Up @@ -173,11 +171,10 @@
(make-blockquote code-inset-style (list b)))

(define (commandline . s)
(make-paragraph (cons (hspace 2) (map (lambda (s)
(if (string? s)
(make-element 'tt (list s))
s))
s))))
(make-paragraph (cons (hspace 2) (for/list ([s (in-list s)])
(if (string? s)
(make-element 'tt (list s))
s)))))

(define (pidefterm . s)
(define c (apply defterm s))
Expand Down
Loading
Loading