scribble/bnf: add `BNF-seq-lines'
original commit: 563909c3285cd30f076b37619b5623c24888f2c0
This commit is contained in:
parent
497a6e15cb
commit
6a773e5078
|
@ -1,11 +1,14 @@
|
|||
(module bnf mzscheme
|
||||
(module bnf racket
|
||||
(require "struct.rkt"
|
||||
"decode.rkt"
|
||||
(only-in "core.rkt"
|
||||
make-style
|
||||
make-table-columns)
|
||||
mzlib/kw)
|
||||
|
||||
(provide BNF
|
||||
nonterm
|
||||
BNF-seq
|
||||
BNF-seq BNF-seq-lines
|
||||
BNF-alt BNF-alt/close ; single-line alternatives
|
||||
BNF-etc
|
||||
BNF-group
|
||||
|
@ -15,11 +18,19 @@
|
|||
(define equals (make-element 'tt (list 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)
|
||||
(make-table
|
||||
#f
|
||||
(make-style #f
|
||||
(list
|
||||
(make-table-columns
|
||||
(list baseline baseline baseline baseline))))
|
||||
(apply
|
||||
append
|
||||
(map (lambda (defn)
|
||||
|
@ -42,6 +53,10 @@
|
|||
""
|
||||
(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)
|
||||
(interleave l alt))
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ produces the output
|
|||
|
||||
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
|
||||
(typically constructed with @racket[nonterm]) for the non-terminal
|
||||
|
@ -58,6 +58,11 @@ Typesets a non-terminal: italic in angle brackets.}
|
|||
|
||||
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?]{
|
||||
|
||||
Typesets a group surrounded by curly braces (so the entire group can
|
||||
|
|
Loading…
Reference in New Issue
Block a user