scribble/bnf: add `BNF-seq-lines'

original commit: 563909c3285cd30f076b37619b5623c24888f2c0
This commit is contained in:
Matthew Flatt 2012-04-26 16:24:33 -06:00
parent 497a6e15cb
commit 6a773e5078
2 changed files with 25 additions and 5 deletions

View File

@ -1,11 +1,14 @@
(module bnf mzscheme (module bnf racket
(require "struct.rkt" (require "struct.rkt"
"decode.rkt" "decode.rkt"
(only-in "core.rkt"
make-style
make-table-columns)
mzlib/kw) mzlib/kw)
(provide BNF (provide BNF
nonterm nonterm
BNF-seq BNF-seq BNF-seq-lines
BNF-alt BNF-alt/close ; single-line alternatives BNF-alt BNF-alt/close ; single-line alternatives
BNF-etc BNF-etc
BNF-group BNF-group
@ -15,11 +18,19 @@
(define equals (make-element 'tt (list spacer "::=" spacer))) (define equals (make-element 'tt (list spacer "::=" spacer)))
(define alt (make-element 'tt (list spacer spacer "|" spacer spacer))) (define alt (make-element 'tt (list spacer spacer "|" spacer spacer)))
(define (as-flow i) (make-flow (list (make-paragraph (list i))))) (define (as-flow i) (make-flow (list (if (block? i)
i
(make-paragraph (list i))))))
(define baseline (make-style #f '(baseline)))
(define (BNF . defns) (define (BNF . defns)
(make-table (make-table
#f (make-style #f
(list
(make-table-columns
(list baseline baseline baseline baseline))))
(apply (apply
append append
(map (lambda (defn) (map (lambda (defn)
@ -42,6 +53,10 @@
"" ""
(interleave l spacer))) (interleave l spacer)))
(define (BNF-seq-lines . l)
(make-table #f (map (lambda (row) (list (as-flow (apply BNF-seq row))))
l)))
(define (BNF-alt . l) (define (BNF-alt . l)
(interleave l alt)) (interleave l alt))

View File

@ -43,7 +43,7 @@ produces the output
See also @racket[racketgrammar]. See also @racket[racketgrammar].
@defproc[(BNF [prod (cons element? (listof element?))] ...) table?]{ @defproc[(BNF [prod (cons element? (listof (or/c block? element?)))] ...) table?]{
Typesets a grammar table. Each production starts with an element Typesets a grammar table. Each production starts with an element
(typically constructed with @racket[nonterm]) for the non-terminal (typically constructed with @racket[nonterm]) for the non-terminal
@ -58,6 +58,11 @@ Typesets a non-terminal: italic in angle brackets.}
Typesets a sequence.} Typesets a sequence.}
@defproc[(BNF-seq-lines [elems (listof element?)] ...) block?]{
Typesets a sequence that is broken into multiple lines, where each
@racket[elems] is one line.}
@defproc[(BNF-group [pre-content any/c] ...) element?]{ @defproc[(BNF-group [pre-content any/c] ...) element?]{
Typesets a group surrounded by curly braces (so the entire group can Typesets a group surrounded by curly braces (so the entire group can