reference work, and also change ...0 and ...1 to ... and ...+

svn: r6498

original commit: 3856d9e6a4c64579a7149ec386e087bfba1ed907
This commit is contained in:
Matthew Flatt 2007-06-06 06:08:46 +00:00
parent 5a0cc3d55f
commit d15ac66494
5 changed files with 153 additions and 99 deletions

View File

@ -206,6 +206,7 @@
,@(case va
[(#f) null]
[(top) '((valign "top"))]
[(baseline) '((valign "baseline"))]
[(bottom) '((valign "bottom"))]))
,@(render-flow d part ht)))
flows

View File

@ -160,14 +160,47 @@
(define dots1
(make-element #f (list "..." (superscript "+"))))
(define-syntax (arg-contract stx)
(syntax-case stx (... ...+)
[(_ [id contract])
(identifier? #'id)
#'(schemeblock0 contract)]
[(_ [id contract val])
(identifier? #'id)
#'(schemeblock0 contract)]
[(_ [kw id contract])
(and (keyword? (syntax-e #'kw))
(identifier? #'id))
#'(schemeblock0 contract)]
[(_ [kw id contract val])
(and (keyword? (syntax-e #'kw))
(identifier? #'id))
#'(schemeblock0 contract)]
[(_ (... ...))
#'#f]
[(_ (... ...+))
#'#f]
[(_ arg)
(raise-syntax-error
'defproc
"bad argument form"
#'arg)]))
(define-syntax defproc
(syntax-rules ()
[(_ s-exp result desc ...)
(*defproc '[s-exp] '[result] (lambda () (list desc ...)))]))
[(_ (id arg ...) result desc ...)
(*defproc '[(id arg ...)]
(list (list (lambda () (arg-contract arg)) ...))
(list (lambda () (schemeblock0 result)))
(lambda () (list desc ...)))]))
(define-syntax defproc*
(syntax-rules ()
[(_ [[s-exp result] ...] desc ...)
(*defproc '[s-exp ...] '[result ...] (lambda () (list desc ...)))]))
[(_ [[(id arg ...) result] ...] desc ...)
(*defproc '[(id arg ...) ...]
(list (list (lambda () (arg-contract arg)) ...) ...)
(list (lambda () (schemeblock0 result)) ...)
(lambda () (list desc ...)))]))
(define-syntax defstruct
(syntax-rules ()
[(_ name fields desc ...)
@ -219,13 +252,15 @@
(syntax-rules ()
[(_ id) (*var 'id)]))
(define (*defproc prototypes results content-thunk)
(define (*defproc prototypes arg-contractss result-contracts content-thunk)
(let ([spacer (hspace 1)]
[has-optional? (lambda (arg)
(and (pair? arg)
((length arg) . > . (if (keyword? (car arg))
3
2))))]
[to-flow (lambda (e)
(make-flow (list (make-paragraph (list e)))))]
[arg->elem (lambda (v)
(cond
[(pair? v)
@ -234,9 +269,9 @@
(hspace 1)
(to-element (cadr v))))
(to-element (car v)))]
[(eq? v '...1)
[(eq? v '...+)
dots1]
[(eq? v '...0)
[(eq? v '...)
dots0]
[else v]))])
(parameterize ([current-variable-list
@ -253,75 +288,86 @@
(apply
append
(map
(lambda (prototype result first?)
(lambda (prototype arg-contracts result-contract first?)
(append
(list
(list (make-flow
(list
(make-paragraph
(make-table
'((valignment top top top top top))
(list
(let-values ([(required optional more-required)
(let loop ([a (cdr prototype)][r-accum null])
(if (or (null? a)
(and (has-optional? (car a))))
(let ([req (reverse r-accum)])
(let loop ([a a][o-accum null])
(if (or (null? a)
(not (has-optional? (car a))))
(values req (reverse o-accum) a)
(loop (cdr a) (cons (car a) o-accum)))))
(loop (cdr a) (cons (car a) r-accum))))])
(to-element (append
(list (if first?
(make-target-element
#f
(list (to-element (car prototype)))
(register-scheme-definition (car prototype)))
(to-element (car prototype))))
(map arg->elem required)
(if (null? optional)
null
(list
(to-element
(syntax-property
(syntax-ize (map arg->elem optional) 0)
'paren-shape
#\?))))
(map arg->elem more-required))))
(hspace 2)
'rarr
(hspace 2)
(to-element result)))))))
(list
(to-flow
(let-values ([(required optional more-required)
(let loop ([a (cdr prototype)][r-accum null])
(if (or (null? a)
(and (has-optional? (car a))))
(let ([req (reverse r-accum)])
(let loop ([a a][o-accum null])
(if (or (null? a)
(not (has-optional? (car a))))
(values req (reverse o-accum) a)
(loop (cdr a) (cons (car a) o-accum)))))
(loop (cdr a) (cons (car a) r-accum))))])
(to-element (append
(list (if first?
(make-target-element
#f
(list (to-element (car prototype)))
(register-scheme-definition (car prototype)))
(to-element (car prototype))))
(map arg->elem required)
(if (null? optional)
null
(list
(to-element
(syntax-property
(syntax-ize (map arg->elem optional) 0)
'paren-shape
#\?))))
(map arg->elem more-required)))))
(to-flow spacer)
(to-flow 'rarr)
(to-flow spacer)
(make-flow (list (result-contract))))))))))
(apply append
(map (lambda (v)
(map (lambda (v arg-contract)
(cond
[(pair? v)
(list
(list
(make-flow
(list
(let ([v (if (keyword? (car v))
(cdr v)
v)])
(make-paragraph (append
(list
(hspace 2)
(arg->elem v))
(list
spacer
":"
spacer
(to-element (cadr v)))
(if (has-optional? v)
(list spacer
"="
spacer
(to-element (caddr v)))
null))))))))]
(make-table
`((valignment baseline baseline baseline baseline
baseline baseline
,@(if (has-optional? v)
'(baseline baseline baseline baseline)
null)))
(list
(let ([v (if (keyword? (car v))
(cdr v)
v)])
(append
(list
(to-flow (hspace 2))
(to-flow (arg->elem v))
(to-flow spacer)
(to-flow ":")
(to-flow spacer)
(make-flow (list (arg-contract))))
(if (has-optional? v)
(list (to-flow spacer)
(to-flow "=")
(to-flow spacer)
(to-flow (to-element (caddr v))))
null)))))))))]
[else null]))
(cdr prototype)))))
(cdr prototype)
arg-contracts))))
prototypes
results
arg-contractss
result-contracts
(cons #t (map (lambda (x) #f) (cdr prototypes))))))
(content-thunk))))))

View File

@ -64,10 +64,14 @@
(define out
(case-lambda
[(v cls)
(out v cls (cond
[(string? v) (string-length v)]
[(sized-element? v) (sized-element-length v)]
[else 1]))]
(out v cls (let sz-loop ([v v])
(cond
[(string? v) (string-length v)]
[(sized-element? v) (sized-element-length v)]
[(and (element? v)
(= 1 (length (element-content v))))
(sz-loop (car (element-content v)))]
[else 1])))]
[(v cls len)
(unless (equal? v "")
(if (equal? v "\n")
@ -378,7 +382,7 @@
(finish-line!))
(if multi-line?
(make-table #f (map list (reverse docs)))
(make-element #f (reverse content)))))
(make-sized-element #f (reverse content) dest-col))))
(define (to-element c)
(typeset c #f "" "" #t))

View File

@ -6,13 +6,13 @@
@define-syntax[def-title-like
(syntax-rules ()
[(_ id result/c x ...) (defproc (id [#:tag tag (or/c false/c string?) #f]
[pre-content any/c] ...0)
[pre-content any/c] (... ...+))
result/c
x ...)])]
@define-syntax[def-elem-proc
(syntax-rules ()
[(_ id x ...) (defproc (id [pre-content any/c] ...0)
[(_ id x ...) (defproc (id [pre-content any/c] (... ...))
element?
x ...)])]
@define-syntax[def-style-proc
@ -66,7 +66,7 @@ have Scribble's @file{scheme.ss} and @file{manual.ss}).
unnumbered section heading (for when the nesting gets too deep to
include in a table of contents).}
@defproc[(itemize [itm (or/c whitespace? an-item?)] ...0) itemization?]{
@defproc[(itemize [itm (or/c whitespace? an-item?)] ...) itemization?]{
Constructs an itemization given a sequence of items constructed by
@scheme[item]. Whitespace strings among the @scheme[itm]s are
@ -74,7 +74,7 @@ have Scribble's @file{scheme.ss} and @file{manual.ss}).
}
@defproc[(item pre-flow ...0) item?]{
@defproc[(item [pre-flow any/c] ...) item?]{
Creates an item for use with @scheme[itemize]. The
@scheme[pre-flow] list is parsed with @scheme[decode-flow].
}
@ -100,7 +100,7 @@ style @scheme[#f].}
Produces an element containing @scheme[n] spaces and style @scheme['hspace].
}
@defproc[(span-class [style-name string?] [pre-content any/c] ...0)
@defproc[(span-class [style-name string?] [pre-content any/c] ...)
element?]{
Parses the @scheme[pre-content] list using @scheme[decode-content],
@ -111,7 +111,7 @@ and produces an element with style @scheme[style-name].
@section{Indexing}
@defproc[(index [words (or/c string? (listof string?))]
[pre-content any/c] ...0)
[pre-content any/c] ...)
index-element?] {
Creates an index element given a plain-text string---or list of
@ -126,14 +126,14 @@ refers.
@defproc[(index* [words (listof string?)]
[word-contents (listof list?)]
[pre-content any/c] ...0)
[pre-content any/c] ...)
index-element?] {
Like @scheme[index], except that @scheme[words] must be a list, and
the list of contents render in the index (in parallel to
@scheme[words]) is supplied as @scheme[word-contents].
}
@defproc[(as-index [pre-content any/c] ...0)
@defproc[(as-index [pre-content any/c] ...)
index-element?] {
Like @scheme[index], but the word to index is determined by applying

View File

@ -107,10 +107,10 @@ a single line and wrapped with its enclosing paragraph, independent of
the formatting of @scheme[datum].}
@defform[(schemeresult datum ...)]{Like @scheme[scheme], but typeset
as a REPL value (i.e., a single color with no hperlinks).}
as a REPL value (i.e., a single color with no hyperlinks).}
@defform[(schemeid datum ...)]{Like @scheme[scheme], but typeset
as an unbound identifier (i.e., no coloring or hyperlink).}
as an unbound identifier (i.e., no coloring or hyperlinks).}
@defform[(schememodname datum ...)]{Like @scheme[scheme], but typeset
as a @schemefont{#module} language name.}
@ -125,24 +125,24 @@ as a table/paragraph in typewriter font with the linebreaks specified
by newline characters in @scheme[str]. ``Here strings'' are often
useful with @scheme[verbatim].}
@defproc[(schemefont [pre-content any/c] ...0) element?]{Typesets the given
@defproc[(schemefont [pre-content any/c] ...) element?]{Typesets the given
content as uncolored, unhyperlinked Scheme. This procedure is useful
for typesetting thngs like @scheme{#module}, which are not
@scheme[read]able by themselves.}
@defproc[(schemevalfont [pre-content any/c] ...0) element?]{Like
@defproc[(schemevalfont [pre-content any/c] ...) element?]{Like
@scheme[schemefont], but colored as a value.}
@defproc[(schemeresultfont [pre-content any/c] ...0) element?]{Like
@defproc[(schemeresultfont [pre-content any/c] ...) element?]{Like
@scheme[schemefont], but colored as a REPL result.}
@defproc[(schemeidfont [pre-content any/c] ...0) element?]{Like
@defproc[(schemeidfont [pre-content any/c] ...) element?]{Like
@scheme[schemefont], but colored as an identifier.}
@defproc[(schemekeywordfont [pre-content any/c] ...0) element?]{Like
@defproc[(schemekeywordfont [pre-content any/c] ...) element?]{Like
@scheme[schemefont], but colored as a syntactic form name.}
@defproc[(procedure [pre-content any/c] ...0) element?]{Typesets the given
@defproc[(procedure [pre-content any/c] ...) element?]{Typesets the given
content as a procedure name in a REPL result (e.g., in typewrite font
with a @schemefont{#<procedure:} prefix and @schemefont{>} suffix.).}
@ -173,7 +173,7 @@ Each @scheme[arg-spec] must have one of the following forms:
@specsubform[(arg-id contract-expr-datum)]{
An argument whose contract is specified by
@scheme[contract-expr-datum] which is typeset via
@scheme[scheme].}
@scheme[schemeblock0].}
@specsubform[(arg-id contract-expr-datum default-expr)]{
Like the previous case, but with a default value. All arguments
@ -187,14 +187,14 @@ Each @scheme[arg-spec] must have one of the following forms:
Like the previous case, but with a default
value.}
@specsubform[#, @schemeidfont{...0}]{ Any number of the preceding argument
@specsubform[#, @schemeidfont{...}]{ Any number of the preceding argument
(normally at the end).}
@specsubform[#, @schemeidfont{...1}]{One or more of the preceding argument
@specsubform[#, @schemeidfont{...+}]{One or more of the preceding argument
(normally at the end).}
The @scheme[result-contract-expr-datum] is typeset via
@scheme[scheme], and it represents a contract on the procedure's
@scheme[schemeblock0], and it represents a contract on the procedure's
result.
The @scheme[pre-flow]s list is parsed as a flow that documents the
@ -205,7 +205,7 @@ The typesetting of all data before the @scheme[pre-flow]s ignores the
source layout.}
@defform[(defproc* ([(id arg-spec ...)
@defform[(defproc* ([(id arg-spec ...)
result-contract-expr-datum] ...)
pre-flow ...)]{
@ -224,8 +224,11 @@ procedure. In this description, a reference to any identifier in
@scheme[datum] is typeset as a sub-form non-terminal.
The typesetting of @scheme[(id . datum)] preserves the source
layout, like @scheme[scheme], and unlike @scheme[defproc].}
layout, like @scheme[schemeblock], and unlike @scheme[defproc].}
@defform[(specform (id . datum) pre-flow ...)]{Like @scheme[defform],
with without registering a definition, and with indenting on the left
for both the specification and the @scheme[pre-flow]s.}
@defform[(specsubform datum pre-flow ...)]{Similar to
@scheme[defform], but without any specific identifier being defined,
@ -260,20 +263,20 @@ The @scheme[struct-name] can be either of the following:
@; ------------------------------------------------------------------------
@section{Various String Forms}
@defproc[(defterm [pre-content any/c] ...0) element?]{Typesets the given
@defproc[(defterm [pre-content any/c] ...) element?]{Typesets the given
content as a defined term (e.g., in italic).}
@defproc[(onscreen [pre-content any/c] ...0) element?]{ Typesets the given
@defproc[(onscreen [pre-content any/c] ...) element?]{ Typesets the given
content as a string that appears in a GUI, such as the name of a
button.}
@defproc[(menuitem [menu-name string?] [item-name string?]) element?]{
Typesets the given combination of a GUI's menu and item name.}
@defproc[(file [pre-content any/c] ...0) element?]{Typesets the given content
@defproc[(file [pre-content any/c] ...) element?]{Typesets the given content
as a file name (e.g., in typewriter font and in in quotes).}
@defproc[(exec [pre-content any/c] ...0) element?]{Typesets the given content
@defproc[(exec [pre-content any/c] ...) element?]{Typesets the given content
as a command line (e.g., in typewriter font).}
@; ------------------------------------------------------------------------
@ -282,10 +285,10 @@ as a command line (e.g., in typewriter font).}
@defproc[(secref [tag string?]) element?]{Inserts the hyperlinked
title of the section tagged @scheme[tag].}
@defproc[(seclink [tag string?] [pre-content any/c] ...0) element?]{The content from
@defproc[(seclink [tag string?] [pre-content any/c] ...) element?]{The content from
@scheme[pre-content] is hyperlinked to the section tagged @scheme[tag].}
@defproc[(schemelink [id symbol?] [pre-content any/c] ...0) element?]{The content from
@defproc[(schemelink [id symbol?] [pre-content any/c] ...) element?]{The content from
@scheme[pre-content] is hyperlinked to the definition of @scheme[id].}
@ -293,11 +296,11 @@ title of the section tagged @scheme[tag].}
@; ------------------------------------------------------------------------
@section{Indexing}
@defproc[(idefterm [pre-content any/c] ...0) element?]{Combines
@defproc[(idefterm [pre-content any/c] ...) element?]{Combines
@scheme[as-index] and @scheme[defterm]. The content normally should be
plurarl, rather than singular.}
@defproc[(pidefterm [pre-content any/c] ...0) element?]{Like
@defproc[(pidefterm [pre-content any/c] ...) element?]{Like
@scheme[idefterm], but plural: adds an ``s'' on the end of the content
for the index entry.}
@ -311,9 +314,9 @@ the letters in the right case).}
@defthing[undefined-const element?]{Returns an element for @|undefined-const|.}
@defproc[(centerline [pre-flow any/c] ...0) table?]{Produces a
@defproc[(centerline [pre-flow any/c] ...) table?]{Produces a
centered table with the @scheme[pre-flow] parsed by
@scheme[decode-flow].}
@defproc[(commandline [pre-content any/c] ...0) paragraph?]{Produces a
@defproc[(commandline [pre-content any/c] ...) paragraph?]{Produces
an inset command-line example (e.g., in typewriter font).}