Redex rendering adjustments, including new metafunction styles

svn: r15322
This commit is contained in:
Matthew Flatt 2009-06-28 16:15:23 +00:00
parent 7f2aac10e6
commit 52acc7cbfb
4 changed files with 91 additions and 63 deletions

View File

@ -73,8 +73,10 @@
[metafunction-pict-style [metafunction-pict-style
(parameter/c (symbols 'left-right (parameter/c (symbols 'left-right
'left-right/vertical-side-conditions 'left-right/vertical-side-conditions
'left-right/compact-side-conditions
'up-down 'up-down
'up-down/vertical-side-conditions))]) 'up-down/vertical-side-conditions
'up-down/compact-side-conditions))])
(provide/contract (provide/contract
[label-font-size (parameter/c (and/c (between/c 1 255) integer?))] [label-font-size (parameter/c (and/c (between/c 1 255) integer?))]

View File

@ -3,6 +3,7 @@
(lib "utils.ss" "texpict") (lib "utils.ss" "texpict")
scheme/gui/base scheme/gui/base
scheme/class scheme/class
(only-in scheme/list drop-right last)
"reduction-semantics.ss" "reduction-semantics.ss"
"struct.ss" "struct.ss"
"loc-wrapper.ss" "loc-wrapper.ss"
@ -219,16 +220,15 @@
(make-vertical-style rbl-superimpose)) (make-vertical-style rbl-superimpose))
(define (rule-picts->pict/compact-vertical rps) (define (rule-picts->pict/compact-vertical rps)
(let ([max-w (apply max (let* ([max-w (apply max
(compact-vertical-min-width) (compact-vertical-min-width)
(map pict-width (map pict-width
(append (append
(map rule-pict-lhs rps) (map rule-pict-lhs rps)
(map rule-pict-rhs rps))))]) (map rule-pict-rhs rps))))]
(table 3 [one-line
(apply (lambda (sep?)
append (lambda (rp)
(map (lambda (rp)
(let ([arrow (hbl-append (arrow->pict (rule-pict-arrow rp)) (blank (arrow-space) 0))] (let ([arrow (hbl-append (arrow->pict (rule-pict-arrow rp)) (blank (arrow-space) 0))]
[lhs (rule-pict-lhs rp)] [lhs (rule-pict-lhs rp)]
[rhs (rule-pict-rhs rp)] [rhs (rule-pict-rhs rp)]
@ -236,20 +236,27 @@
[label (hbl-append (blank (label-space) 0) (rp->pict-label rp))] [label (hbl-append (blank (label-space) 0) (rp->pict-label rp))]
[sep (blank (compact-vertical-min-width) [sep (blank (compact-vertical-min-width)
(reduction-relation-rule-separation))]) (reduction-relation-rule-separation))])
(append
(if ((apply + (map pict-width (list lhs spc arrow spc rhs))) (if ((apply + (map pict-width (list lhs spc arrow spc rhs)))
. < . . < .
max-w) max-w)
(list (list
(blank) (hbl-append lhs spc arrow spc rhs) label (blank) (hbl-append lhs spc arrow spc rhs) label
(blank) (rp->side-condition-pict rp max-w) (blank) (blank) (rp->side-condition-pict rp max-w) (blank))
(blank) sep (blank))
(list (blank) lhs label (list (blank) lhs label
arrow rhs (blank) arrow rhs (blank)
(blank) (rp->side-condition-pict rp max-w) (blank) (blank) (rp->side-condition-pict rp max-w) (blank)))
(blank) sep (blank))))) (if sep? (list (blank) sep (blank)) null)))))])
rps)) (if (null? rps)
(blank)
(table 3
(append
(apply
append
(map (one-line #t) (drop-right rps 1)))
((one-line #f) (last rps)))
ltl-superimpose ltl-superimpose ltl-superimpose ltl-superimpose
(list* 2 (+ 2 (current-label-extra-space))) 2))) (list* 2 (+ 2 (current-label-extra-space))) 2))))
;; side-condition-pict : (listof pict) (listof (or/c (cons/c pict pict) pict)) number -> pict ;; side-condition-pict : (listof pict) (listof (or/c (cons/c pict pict) pict)) number -> pict
;; the elements of pattern-binds/sc that are pairs are bindings (ie "x = <something>") ;; the elements of pattern-binds/sc that are pairs are bindings (ie "x = <something>")
@ -485,14 +492,17 @@
info)))) info))))
(define (sequence-of-non-terminals nts) (define (sequence-of-non-terminals nts)
(let ([draw-nt (lambda (nt)
(lw->pict nts (build-lw nt 0 0 0 0)))])
(let loop ([nts (cdr nts)] (let loop ([nts (cdr nts)]
[pict (non-terminal (format "~a" (car nts)))]) [pict (draw-nt (car nts))])
(cond (cond
[(null? nts) pict] [(null? nts) pict]
[else [else
(loop (cdr nts) (loop (cdr nts)
(hbl-append pict (hbl-append pict
(non-terminal (format ", ~a" (car nts)))))]))) (non-terminal ", ")
(draw-nt (car nts))))]))))
(define extend-language-show-union (make-parameter #f)) (define extend-language-show-union (make-parameter #f))
@ -740,6 +750,21 @@
mfs))] mfs))]
[eqns (select-cases all-eqns)] [eqns (select-cases all-eqns)]
[lhss (select-cases all-lhss)] [lhss (select-cases all-lhss)]
[rhss (map (lambda (eqn) (wrapper->pict (list-ref eqn 2))) eqns)]
[linebreak-list (or current-linebreaks
(map (lambda (x) #f) eqns))]
[=-pict (make-=)]
[max-lhs-w (apply max (map pict-width lhss))]
[max-line-w/pre-sc (apply
max
(map (lambda (lhs rhs linebreak?)
(max
(if linebreak?
(max (pict-width lhs)
(+ (pict-width rhs) (pict-width =-pict)))
(+ (pict-width lhs) (pict-width rhs) (pict-width =-pict)
(* 2 sep)))))
lhss rhss linebreak-list))]
[scs (map (lambda (eqn) [scs (map (lambda (eqn)
(if (null? (list-ref eqn 1)) (if (null? (list-ref eqn 1))
#f #f
@ -753,26 +778,13 @@
(if (memq style '(up-down/vertical-side-conditions (if (memq style '(up-down/vertical-side-conditions
left-right/vertical-side-conditions)) left-right/vertical-side-conditions))
0 0
+inf.0)))) (if (memq style '(up-down/compact-side-conditions
eqns)] left-right/compact-side-conditions))
[rhss (map (lambda (eqn) (wrapper->pict (list-ref eqn 2))) eqns)] max-line-w/pre-sc
[linebreak-list (or current-linebreaks +inf.0)))))
(map (lambda (x) #f) eqns))] eqns)])
[=-pict (make-=)]
[max-lhs-w (apply max (map pict-width lhss))]
[max-line-w (apply
max
(map (lambda (lhs sc rhs linebreak?)
(max
(if sc (pict-width sc) 0)
(if linebreak?
(max (pict-width lhs)
(+ (pict-width rhs) (pict-width =-pict)))
(+ (pict-width lhs) (pict-width rhs) (pict-width =-pict)
(* 2 sep)))))
lhss scs rhss linebreak-list))])
(case style (case style
[(left-right left-right/vertical-side-conditions) [(left-right left-right/vertical-side-conditions left-right/compact-side-conditions)
(table 3 (table 3
(apply append (apply append
(map (lambda (lhs sc rhs linebreak?) (map (lambda (lhs sc rhs linebreak?)
@ -803,7 +815,7 @@
linebreak-list)) linebreak-list))
ltl-superimpose ltl-superimpose ltl-superimpose ltl-superimpose
sep sep)] sep sep)]
[(up-down up-down/vertical-side-conditions) [(up-down up-down/vertical-side-conditions up-down/compact-side-conditions)
(panorama (panorama
;; the side-conditions may hang outside the pict, so bring them back w/ panorama ;; the side-conditions may hang outside the pict, so bring them back w/ panorama
(apply vl-append (apply vl-append

View File

@ -1655,7 +1655,7 @@ other tools that combine picts together.
@defform/none[#:literals (render-metafunction) @defform/none[#:literals (render-metafunction)
(render-metafunction metafunction-name filename)]{} (render-metafunction metafunction-name filename)]{}
@defform[(render-metafunctions metafunction-name ...)]{} @defform[(render-metafunctions metafunction-name ...)]{}
@defform/none[#:literals (render-metafunction) @defform/none[#:literals (render-metafunctions)
(render-metafunctions metafunction-name ... #:file filename)]{}]]{ (render-metafunctions metafunction-name ... #:file filename)]{}]]{
If provided with one argument, @scheme[render-metafunction] If provided with one argument, @scheme[render-metafunction]
@ -1764,14 +1764,25 @@ label on each rule, but only in horizontal mode. Defaults to
(or/c 'left-right (or/c 'left-right
'up-down 'up-down
'left-right/vertical-side-conditions 'left-right/vertical-side-conditions
'up-down/vertical-side-conditions)]{ 'up-down/vertical-side-conditions
'left-right/compact-side-conditions
'up-down/compact-side-conditions)]{
This parameter controls the style used for typesetting This parameter controls the style used for typesetting
metafunctions. The @scheme['left-right] style means that the metafunctions. The @scheme['left-right] style means that the
results of calling the metafunction are displayed to the results of calling the metafunction are displayed to the
right of the arguments and the @scheme['up-down] style means that right of the arguments and the @scheme['up-down] style means that
the results are displayed below the arguments. the results are displayed below the arguments.
}
The @scheme['left-right/vertical-side-conditions] and
@scheme['up-down/vertical-side-conditions] variants format side
conditions each on a separate line, instead of all on the same line.
The @scheme['left-right/compact-side-conditions] and
@scheme['up-down/compact-side-conditions] variants move side
conditions to separate lines to avoid making the rendered form wider
than it would be otherwise.}
@defparam[metafunction-cases @defparam[metafunction-cases
cases cases

View File

@ -9,6 +9,9 @@ v4.2.1
pattern matches are allowed, as long as the right-hand side pattern matches are allowed, as long as the right-hand side
has the same value for each different pattern binding has the same value for each different pattern binding
* added metafunction styles 'up-down/compact-side-conditions and
'left-right/compact-side-conditions
v4.2 v4.2
* minor bug fixes * minor bug fixes