add defidform/inline and use it to document on-draw

original commit: b61a99c4336006890709f312764604e0fd21ce41
This commit is contained in:
Matthew Flatt 2010-04-28 06:41:43 -06:00
94 changed files with 90 additions and 53 deletions

View File

@ -20,7 +20,7 @@
(provide defform defform* defform/subs defform*/subs defform/none
defidform
defidform defidform/inline
specform specform/subs
specsubform specsubform/subs specspecsubform specspecsubform/subs
specsubform/inline
@ -173,6 +173,12 @@
(syntax/loc stx
(fm #:literals () spec desc ...))]))
(define-syntax (defidform/inline stx)
(syntax-case stx ()
[(_ id)
(identifier? #'id)
#'(defform-site (quote-syntax id))]))
(define-syntax (defidform stx)
(syntax-case stx ()
[(_ spec-id desc ...)
@ -307,6 +313,29 @@
(define (meta-symbol? s) (memq s '(... ...+ ?)))
(define (defform-site kw-id)
(let ([target-maker (id-to-form-target-maker kw-id #t)]
[content (list (definition-site (syntax-e kw-id)
kw-id #t))])
(if target-maker
(target-maker
content
(lambda (tag)
(make-toc-target-element
#f
(if kw-id
(list (make-index-element
#f content tag
(list (symbol->string (syntax-e kw-id)))
content
(with-exporting-libraries
(lambda (libs)
(make-form-index-desc (syntax-e kw-id)
libs)))))
content)
tag)))
(car content))))
(define (*defforms kw-id forms form-procs subs sub-procs contract-procs content-thunk)
(parameterize ([current-meta-list '(... ...+)])
(make-box-splice
@ -325,27 +354,7 @@
(list (to-element `(,x . ,(cdr form)))))))
(and kw-id
(eq? form (car forms))
(let ([target-maker (id-to-form-target-maker kw-id #t)]
[content (list (definition-site (syntax-e kw-id)
kw-id #t))])
(if target-maker
(target-maker
content
(lambda (tag)
(make-toc-target-element
#f
(if kw-id
(list (make-index-element
#f content tag
(list (symbol->string (syntax-e kw-id)))
content
(with-exporting-libraries
(lambda (libs)
(make-form-index-desc (syntax-e kw-id)
libs)))))
content)
tag)))
(car content)))))))))
(defform-site kw-id)))))))
forms form-procs)
(if (null? sub-procs)
null

View File

@ -611,43 +611,64 @@
((loop init-line! (if qq? quote-depth +inf.0) qq?) (unbox (syntax-e c))))]
[(hash? (syntax-e c))
(advance c init-line!)
(let ([equal-table? (not (hash-eq? (syntax-e c)))]
(let ([equal-table? (hash-equal? (syntax-e c))]
[eqv-table? (hash-eq? (syntax-e c))]
[quote-depth (to-quoted "`" qq? quote-depth out color? inc-src-col)])
(out (if equal-table?
"#hash"
"#hasheq")
(if eqv-table?
"#hasheqv"
"#hasheq"))
value-color)
(let ([delta (+ 5 (if equal-table? 2 0))]
(let ([delta (+ 5 (if equal-table? 0 (if eqv-table? 3 2)))]
[orig-col src-col])
(set! src-col (+ src-col delta))
(hash-set! next-col-map src-col dest-col)
((loop init-line! (if qq? quote-depth +inf.0) qq?)
(let* ([l (sort (hash-map (syntax-e c) cons)
(lambda (a b)
(< (or (syntax-position (cdr a)) -inf.0)
(or (syntax-position (cdr b)) -inf.0))))]
[l2 (for/list ([p (in-list l)])
(let* ([tentative (syntax-ize (car p) 0)]
[width (syntax-span tentative)])
(datum->syntax
#f
(make-forced-pair
(syntax-ize (car p)
(max 0 (- (syntax-column (cdr p))
width
3))
(syntax-line (cdr p)))
(cdr p))
(vector 'here
(syntax-line (cdr p))
(max 0 (- (syntax-column (cdr p)) width 4))
(max 1 (- (syntax-position (cdr p)) width 4))
(+ (syntax-span (cdr p)) width 5)))))])
(datum->syntax #f l2 (vector (syntax-source c)
(syntax-line c)
(+ (syntax-column c) delta)
(+ (syntax-position c) delta)
(max 1 (- (syntax-span c) delta))))))
(let*-values ([(l) (sort (hash-map (syntax-e c) cons)
(lambda (a b)
(< (or (syntax-position (cdr a)) -inf.0)
(or (syntax-position (cdr b)) -inf.0))))]
[(col0) (+ (syntax-column c) delta 2)]
[(l2 pos line) (for/fold ([l2 null][col col0][line (syntax-line c)])
([p (in-list l)])
(let* ([tentative (syntax-ize (car p) 0)]
[width (syntax-span tentative)]
[col (if (= line (syntax-line (cdr p)))
col
col0)])
(let ([key
(let ([e (syntax-ize (car p)
(max 0 (- (syntax-column (cdr p))
width
3))
(syntax-line (cdr p)))])
(if ((syntax-column e) . <= . col)
e
(datum->syntax #f
(syntax-e e)
(vector (syntax-source e)
(syntax-line e)
col
(syntax-position e)
(+ (syntax-span e) (- (syntax-column e) col))))))])
(let ([elem
(datum->syntax
#f
(make-forced-pair key (cdr p))
(vector 'here
(syntax-line (cdr p))
(max 0 (- (syntax-column key) 1))
(max 1 (- (syntax-position key) 1))
(+ (syntax-span (cdr p)) (syntax-span key) 5)))])
(values (cons elem l2)
(+ (syntax-column elem) (syntax-span elem) 2)
(syntax-line elem))))))])
(datum->syntax #f (reverse l2) (vector (syntax-source c)
(syntax-line c)
(+ (syntax-column c) delta)
(+ (syntax-position c) delta)
(max 1 (- (syntax-span c) delta))))))
(set! src-col (+ orig-col (syntax-span c)))))]
[(graph-reference? (syntax-e c))
(advance c init-line!)

View File

@ -1,4 +1,4 @@
#lang scribble/doc
@(require scribble/lp-include)
@lp-include["lp-ex.ss"]
@lp-include["lp-ex.rkt"]

View File

@ -26,7 +26,7 @@ program, and the rest of the module is discarded. When using
and are treated like an ordinary Scribble document, where
@scheme[chunk]s are typeset in a manner similar to @scheme[codeblock].
@(define-runtime-path lp-ex "lp-ex.ss")
@(define-runtime-path lp-ex "lp-ex.rkt")
For example, consider this program:

View File

@ -549,6 +549,13 @@ Like @scheme[defform], but without registering a definition.}
Like @scheme[defform], but with a plain @scheme[id] as the form.}
@defform[(defidform/inline id)]{
Like @scheme[defidform], but @racket[id] is typeset as an inline
element. Use this form sparingly, because the typeset form does not
stand out to the reader as a specification of @racket[id].}
@defform[(specform maybe-literals datum maybe-contracts
pre-flow ...)]{